
	var SelectCounter=0;
	
	function onRowOver(thisObj, bg, cur){
		thisObj.style.backgroundColor= bg;
		if(cur != null){
			thisObj.style.cursor=cur;
		}
		else{
			thisObj.style.cursor='hand';
		}
		return true;
	}

	function onRowOut(thisObj){
		thisObj.style.backgroundColor='';
		return true;
	}

	function setCheck(Line){
		if(document.getElementById("isCheck" + Line).value=="no"){
			document.getElementById("isCheck" + Line).value="yes";
			SelectCounter++;
		}
		else{
			document.getElementById("isCheck" + Line).value="no";
			SelectCounter--;
		}
		document.getElementById("imgCheck" + Line).src="images/icon/check_" + document.getElementById("isCheck" + Line).value + ".gif";
		return true;
	}

	function HideShowSendDetail(Line,maxSendDetail) {
		for(i=1;i<=maxSendDetail;i++){
			if (document.getElementById("SendDetail" + Line + "_" + i).style.display == 'none' ){
				document.getElementById("SendDetail" + Line + "_" + i).style.display = '';
			}
			else{
				document.getElementById("SendDetail" + Line + "_" + i).style.display = 'none';	
			}		
		}
		return true;	
	}

	function Popup(pname, purl, w, h, s){
		LeftPosition = (screen.width) ? (screen.width-w-8)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h-50)/2 : 0;
		window.open(purl,pname,"width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",resizable=no,scrollbars="+s);
	}	

	function MM_swapImgRestore() { //v3.0
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
  		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function CheckAll(FName, CheckBoxname) {
  		for (var i=0; i<FName.elements.length; i++) {
    		var c = FName.elements[i];
			if(c.type == CheckBoxname.type){
	    		if (c.name != CheckBoxname.name) {
    	  			c.checked = CheckBoxname.checked;
    			}
			}
  		}
	}

	function CheckBoxAll(chkName, chkAll){
		if(chkName){
			if(!chkName.length){
				if(chkAll.checked == true){
					// check
					if(chkName.checked == false){
						chkName.checked = true;
					}
				}
				else{
					// uncheck
					if(chkName.checked == true){
						chkName.checked = false;
					}
				}
			}
			else{
				for(var cnt=0;cnt<chkName.length;cnt++){
					if(chkAll.checked == true){
						// check
						if(chkName[cnt].checked == false){
							chkName[cnt].checked = true;
						}
					}
					else{
						// uncheck
						if(chkName[cnt].checked == true){
							chkName[cnt].checked = false;
						}
					}
				}
			}
		}
	}

	function Popup_Open(pname, purl, w, h, s, m, r, t, cc){

		cc = (!cc)? 0 : 1;

		if(cc){
			LeftPosition = (screen.width) ? (screen.width-w-8)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-h-50)/2 : 0;
		}
		else{
			LeftPosition = 0;
			TopPosition = 0;
		}

		s = (!s)? 0 : 1;
		m = (!m)? 0 : 1;
		r = (!r)? 0 : 1;		
		t = (!t)? 0 : 1;		
		rr = (r == 0) ? "no" : "yes";
		opt = "width=" + w + ",height=" + h + ",top=" + TopPosition + ",left=" + LeftPosition + ",resizable=" + rr + ",scrollbars=" + s + ",menubar=" + m + ",status=" + t;
		window.open(purl, pname, opt);
	}	

	function Popup_Dialog(doc){
		opt = "resizable: yes; help: no; status: no; scroll: no;";
		showModalDialog(doc, window, opt);
	}

	function Check_Email(email, extension) {
		if(email.indexOf("@")<2){
			//alert(" This email address seems wrong. Please"
			//+" check the prefix and '@' sign.");
			return false;
		}
		if(extension){
			if((email.indexOf(".com")<5)&&(email.indexOf(".org")<5)
				&&(email.indexOf(".gov")<5)&&(email.indexOf(".net")<5)
				&&(email.indexOf(".co.uk")<7)&&(email.indexOf(".nl")<4)
				&&(email.indexOf(".mil")<5)&&(email.indexOf(".edu")<5)
				&&(email.indexOf(".co.th")<7)&&(email.indexOf(".in.th")<7)){
				//alert(" This email address seems wrong. Please"
				//+" check the suffix. (It should include a .com, .edu,"
				//+" .net, .org, .gov, .co.uk, .nl or .mil)");
				return false;
			}
		}
		return true;
	}

	var sname = "";
var slastname = "";
var saddress = "";
var scity = "";
var sprovince = "";
var szipcode = "";
var scountry = "";
var stelephone = "";
var sfax = "";
var semail = "";

function InitSaveVariables(form) {
ShipName = form.sname.value;
ShipLastname = form.slastname.value;
ShipAddress = form.saddress.value;
ShipCity = form.scity.value;
ShipProvince = form.sprovince.value;
ShipZipcode = form.szipcode.value;
ShipCountry = form.scountry.value;
ShipTelephone = form.stelephone.value;
ShipFax = form.sfax.value;
ShipEmail = form.semail.value;
}

function ShipToBillPerson(form) {
	if (form.copy.checked) {
		InitSaveVariables(form);
		form.sname.value = form.name.value;
		form.slastname.value = form.lastname.value;
		form.saddress.value = form.address.value;
		form.scity.value = form.city.value;
		form.sprovince.value = form.province.value;
		form.szipcode.value = form.zipcode.value;
		form.scountry.value = form.country.value;
		form.stelephone.value = form.telephone.value;
		form.sfax.value = form.fax.value;
		form.semail.value = form.email.value;
	}
	else {
	form.sname.value = sname;
		form.slastname.value = slastname;
		form.saddress.value = saddress;
		form.scity.value = scity;
		form.sprovince.value = sprovince;
		form.szipcode.value = szipcode;
		form.scountry.value = scountry;
		form.stelephone.value = stelephone;
		form.sfax.value = sfax;
		form.semail.value = semail;
   }
}



	function emailCheck(emailStr){
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);
		
		if(matchArray==null){
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}

		var user=matchArray[1];
		var domain=matchArray[2];
		if(user.match(userPat)==null){
			alert("The username doesn't seem to be valid.");
			return false;
		}
		
		var IPArray=domain.match(ipDomainPat);
		if(IPArray!=null){
			// this is an IP address
			for(var i=1;i<=4;i++){
				if(IPArray[i]>255){
					alert("Destination IP address is invalid!");
					return false;
				}
			}
			return true;
		}

		var domainArray=domain.match(domainPat);
		if(domainArray==null){
			alert("The domain name doesn't seem to be valid.");
			return false;
		}

		var atomPat=new RegExp(atom,"g");
		var domArr=domain.match(atomPat);
		var len=domArr.length;
		if(domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3){
			alert("The address must end in a three-letter domain, or two letter country.");
			return false;
		}

		if(len<2){
			var errStr="This address is missing a hostname!";
			alert(errStr);
			return false;
		}

		return true;
	}