//-----------------------------------------------------------------------
//Created by David Chew on 9-Mar-2005
// Version 1.0.0
//-----------------------------------------------------------------------
// Last amended by david chew to remove validation of txtToPostal and txtFrom Postal
// Version 1.0.1
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
// Last amended by david chew 
// Version 1.0.2
//-----------------------------------------------------------------------

//Scrpts used by NewScreen1.asp
function checknumber()
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	var x=document.frmNewScreen1.txtWeight.value
	if (!(anum.test(x))){
		alert("Please input a valid weight!")
		document.frmNewScreen1.txtWeight.focus();
		return false
	}

	if (document.frmNewScreen1.cboZone.value == 'SIN')
	{
		/*
		var y=document.frmNewScreen1.txtToPostal.value
		var z=document.frmNewScreen1.txtIsSize.value
		*/
		/*
		if (!(anum.test(y))){
			alert("Please input a valid 6 digits postal code!")
			document.frmNewScreen1.txtToPostal.focus();
			return false
		}
		if (y.length < 6)
		{
			alert("Please input 6 digits postal code!")
			document.frmNewScreen1.txtToPostal.focus();
			return false
		}
		if (!(z == "Y" || z == "N")){
			alert("Please input Y/N !")
			document.frmNewScreen1.txtIsSize.focus();
			return false
		}
		*/
	}
	return true
}

function checkban()
{
   if (document.layers||document.all||document.getElementById)
      return checknumber()
   else
   return true
}

function RefreshSelect()
{
	var LocRef
	var FormTypeValue
	FormTypeValue = document.frmNewScreen1.cboZone.value;
	TextTypeValue = document.frmNewScreen1.txtWeight.value;
	//if (FormTypeValue == "MAS")
	//{
		LocRef = 'NewScreen1.asp?combovalue='+FormTypeValue+'&weightvalue='+TextTypeValue
		frmNewScreen1.action= LocRef ;
		frmNewScreen1.submit();
    //}
}

function Calculate()
{
	var LocRef
	LocRef = 'NewScreen1.asp'
	
	if (frmNewScreen1.txtWeight.value != "")
	{
		frmNewScreen1.action= LocRef ;
		frmNewScreen1.submit();
	}	
}
function txtIsSize_onkeyup()
{
	var temp = frmNewScreen1.txtIsSize.value;
	frmNewScreen1.txtIsSize.value = temp.toUpperCase();
}

//Functions used in NewScreen2.asp
function changeto(highlightcolor)
{
   source=event.srcElement
   if (source.tagName=="TR"||source.tagName=="TABLE")
      return
   while(source.tagName == "TD" || source.tagName !="TR")
      source=source.parentElement
   if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
      source.style.backgroundColor=highlightcolor
}

function changeback(originalcolor)
{
   if (event.fromElement.contains(event.toElement)|| source.contains(event.toElement) || source.id=="ignore")
      return
   if (event.toElement!=source)
      source.style.backgroundColor=originalcolor
}

//Scripts used by NewScreen3.asp
var totalcharge =0 ;

var finaltotal=0;
function ShowAmt(id,ctry)
{
   var RegCharge;
   
   if (ctry == "Singapore")   
   {
	RegCharge = 2.24;
   }
   else
   {
	RegCharge = 2.2;
   }

   totalcharge=parseFloat(document.frmShowAddCharges.txtTotCharge.value) 
   
   if(id == 1)
   {   
      if (ctry == "Singapore") 
      {
      	if(document.frmShowAddCharges.txtReg.value != "")
      	{
          document.frmShowAddCharges.chkReg.checked = false;
          document.frmShowAddCharges.txtReg.value = "" ;
          totalcharge = totalcharge - RegCharge;
      	}    
      	else
      	{
          document.frmShowAddCharges.chkReg.checked = true;
          document.frmShowAddCharges.txtReg.value = "2.24" ;
          totalcharge = totalcharge + RegCharge;
      	} 
      }
      else
      {
      	if(document.frmShowAddCharges.txtReg.value != "")
      	{
          document.frmShowAddCharges.chkReg.checked = false;
          document.frmShowAddCharges.txtReg.value = "" ;
          totalcharge = totalcharge - RegCharge;
      	}    
      	else
      	{
          document.frmShowAddCharges.chkReg.checked = true;
          document.frmShowAddCharges.txtReg.value = "2.20" ;
          totalcharge = totalcharge + RegCharge;
      	} 
      }
   }
   else if(id == 2)
   {   
      AODCharge = 1;
      if(document.frmShowAddCharges.txtAOD.value != "")
      {
          document.frmShowAddCharges.chkAOD.checked = false;
          document.frmShowAddCharges.txtAOD.value = "" ;
          totalcharge = totalcharge - AODCharge;
      }
      else
      {
          document.frmShowAddCharges.chkAOD.checked = true;
          document.frmShowAddCharges.txtAOD.value = "1.00" ;
          totalcharge = totalcharge + AODCharge;
      } 
   }
   else if(id == 3)
   {   
      var ExpressCharge = 2;
      if(document.frmShowAddCharges.txtExpress.value != "")
      {
          document.frmShowAddCharges.chkExpress.checked = false;
          document.frmShowAddCharges.txtExpress.value = "" ;      
          totalcharge = totalcharge - ExpressCharge;
      }
      else
      {
          document.frmShowAddCharges.chkExpress.checked = true;
          document.frmShowAddCharges.txtExpress.value = "2.00";          
          totalcharge = totalcharge + ExpressCharge;

      } 
   }
  document.frmShowAddCharges.txtTotCharge.value = formatCurrency(totalcharge);
}
function formatCurrency(num) 
{
   num = num.toString().replace(/\$|\,/g,'');
   
   if(isNaN(num))
   
      num = "0";
      sign = (num == (num = Math.abs(num)));
      num = Math.floor(num*100+0.50000000001);
      cents = num%100;
      num = Math.floor(num/100).toString();
      
   if(cents<10)
   
      cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+
      num.substring(num.length-(4*i+3));
      return (((sign)?'':'-') + num + '.' + cents);
}
