var ob,selectedObj,GlobalX,GlobalY,ScrX,ScrY,PageX,PageY;
var over = false;
var checkoutFlag = true;


function checkNull(FORM) {
	if (FORM.search.value.length < 1) {
		alert("Please Enter Search Term.");
		FORM.search.focus(); 
		return false;
	 }
}

function loadState(state) {
	var stateForm=document.getElementById("state");
	if (state == "OutsideUS")
		setOutsideUS('state','outside1');
	for (i=0;i<stateForm.options.length;i++)
	{	//find state and select it
		if (stateForm.options[i].value==state)
			stateForm.options[i].selected=true;
	}
}

function populateDropDowns(title,labType,discipline,state,country,sState,sCountry,faxOption,emailOption,same) {

	var stateForm=document.getElementById("stateDropDown");
	var sStateForm=document.getElementById("sStateDropDown");
	var titleForm=document.getElementById("title");
	var labTypeForm=document.getElementById("labType");
	var disciplineForm=document.getElementById("discipline");
	var countryForm=document.getElementById("country");	
	var sCountryForm=document.getElementById("sCountry");	
	var emailOptionForm=document.getElementById("emailOption");	
	var faxOptionForm=document.getElementById("faxOption");	
	var sameForm=document.getElementById("same");	
	
	// billing state loader
	if (state == "OutsideUS")
		setOutsideUS('state','outside1');
	for (i=0;i<stateForm.options.length;i++)
	{	//find state and select it
		if (stateForm.options[i].value==state)
			stateForm.options[i].selected=true;
	}

	// shipping state loader
	if (sState == "OutsideUS")
		setOutsideUS('sState','outside1');
	for (i=0;i<sStateForm.options.length;i++)
	{	//find state and select it
		if (sStateForm.options[i].value==sState)
			sStateForm.options[i].selected=true;
	}

	// title
	for (i=0;i<titleForm.options.length;i++)
	{	//find state and select it
		if (titleForm.options[i].value==title)
			titleForm.options[i].selected=true;
	}

	// labType
	for (i=0;i<labTypeForm.options.length;i++)
	{	//find state and select it
		if (labTypeForm.options[i].value==labType)
			labTypeForm.options[i].selected=true;
	}

	// discipline
	for (i=0;i<disciplineForm.options.length;i++)
	{	//find state and select it
		if (disciplineForm.options[i].value==discipline)
			disciplineForm.options[i].selected=true;
	}

	// billing country
	for (i=0;i<countryForm.options.length;i++)
	{	//find state and select it
		if (countryForm.options[i].value==country) {
			countryForm.options[i].selected=true;
			internationalForm(country,'state','province','bdisplay')
		}
	}

	// shipping country
	for (i=0;i<sCountryForm.options.length;i++)
	{	//find state and select it
		if (sCountryForm.options[i].value==sCountry) {
			sCountryForm.options[i].selected=true;
			internationalForm(sCountry,'sState','sProvince','sdisplay')
		}
	}

	if ( faxOption == "on" )
		faxOptionForm.checked=true;
	else
		faxOptionForm.checked=false;

	if ( emailOption == "on" )	
		emailOptionForm.checked=true;
	else
		emailOptionForm.checked=false;

	if ( same == "on" )	
		sameForm.checked=true;
	else
		sameForm.checked=false;
}

function loadOtherShipping(page,id,checkout) {
	if (checkout)
		self.location=page+"?loadVal="+id+"&checkout=true";
	else
		self.location=page+"?loadVal="+id;
}

function checkUserRegistration(f) {


	if (f.email.value.indexOf("@") + "" == "-1" || f.email.value.indexOf(".") + "" == "-1" || f.email.value == "" )
	 { 
		alert("Please enter email address in correct format.");
		f.email.focus();
		return false;
	 }
         
	if (f.pwd.value.length < 4 ) 
	 {
		alert("Password has to be at least 4 characters long.");
		f.pwd.focus(); 
		return false;
	 }


//	return false;

         if (f.rpwd.value.length < 4) {
                alert("Please retype password for verification.");
				f.rpwd.focus(); 
                return false;
         }
         
         if (f.pwd.value != f.rpwd.value) {
                alert("Password verification failed.");
                f.pwd.value="";
                f.rpwd.value="";
				f.pwd.focus(); 
                return false;
         }

         if (f.fname.value.length < 1) {
                alert("Please enter first name.");
				f.fname.focus(); 
                return false;
         }

         if (f.lname.value.length < 1) {
                alert("Please enter last name.");
				f.lname.focus(); 
                return false;
         }

         if (f.organization.value.length < 1) {
                alert("Please enter organization or agency information.");
				f.organization.focus(); 
                return false;
         }
		/*
         if (f.agency.value.length < 1) {
                alert("Please enter agency information.");
				f.agency.focus(); 
                return false;
         }        
		*/
  
         if (f.title.value == "null" ) {
				 if (f.title_manual.value.length < 1) {
						alert("Please enter title.");
						f.title_manual.focus(); 
						return false;
			 }
         }
  
         if (f.labType.value == "null" ) {
			 if (f.labType_manual.value.length < 1) {
					alert("Please enter Lab Type Information.");
					f.labType_manual.focus(); 
					return false;
			 }
         }
  
         if (f.discipline.value == "null" ) {
			 if (f.discipline_manual.value.length < 1) {
					alert("Please enter Discipline Information.");
					f.discipline_manual.focus(); 
					return false;
			 }
         }

         if (f.address.value.length < 1) {
                alert("Please enter street address.");
				f.address.focus(); 
                return false;
         }
         if (f.city.value.length < 1) {
                alert("Please enter city.");
				f.city.focus(); 
                return false;
         }
        
 		 if (f.zip.value.length < 1 )
		 {
                alert("Please enter zipcode in correct format.");
				f.zip.focus(); 
                return false;             
         }
            
         if (f.phone.value.length < 1) {
                alert("Please enter contact phone number.");
				f.phone.focus(); 
                return false;
         }

         if (f.sAddress.value.length < 1) {
               alert("Please provide shipping address.");
				f.sAddress.focus(); 
                return false;
		  }

		  if (f.sCity.value.length < 1) {
			alert("Please provide shipping city.");
			f.sCity.focus(); 
			return false;
		  }

		 if (f.sZip.value.length < 1 )
		  {
			alert("Please provide shipping zipcode in correct format.");
			f.sZip.focus(); 
			return false;             
		  }
   }


function internationalForm (id,state,province,display) {
	if ( id != 1 )
	{	
		var stateForm=document.getElementById(state);
		var provinceForm=document.getElementById(province);
		var displayZip=document.getElementById(display);
		stateForm.style.display="none";	
		provinceForm.style.display="";
		displayZip.innerHTML="Postalcode";
	}
	else
	{	
		var stateForm=document.getElementById(state);
		var provinceForm=document.getElementById(province);
		var displayZip=document.getElementById(display);
		provinceForm.style.display="none";
		stateForm.style.display="";	
		displayZip.innerHTML="Zipcode";
	}
}


function copyAddressInfo (name) {

	if ( document.getElementById("same").checked)
	{
		var f=document.getElementById(name);

		if ( f.country.value != 1 ) {
			var stateForm=document.getElementById("sState");
			var provinceForm=document.getElementById("sProvince");
			var displayZip=document.getElementById("sdisplay");
			stateForm.style.display="none";	
			provinceForm.style.display="";
			displayZip.innerHTML="Postalcode";

			f.sProvince.value=f.province.value;
		}


		f.sAddress.value=f.address.value;
		f.sAddress2.value=f.address2.value;
		f.sCity.value=f.city.value;
		f.sState.selectedIndex=f.state.selectedIndex;
		f.sZip.value=f.zip.value;
		f.sCountry.value=f.country.value;
	}
	else
	{
		var f=document.getElementById(name);
		f.sAddress.value="";
		f.sAddress2.value="";
		f.sCity.value="";
		f.sState.selectedIndex=0;
		f.sZip.value="";
		f.sCountry.value=1;		// set to default display country USA

		var stateForm=document.getElementById("sState");
		var provinceForm=document.getElementById("sProvince");
		var displayZip=document.getElementById("sdisplay");
		f.sProvince.value="";
		stateForm.style.display="";	
		provinceForm.style.display="none";
		displayZip.innerHTML="Zipcode";
	}
}

function checkShippingForm(f) {
         
         if (f.profilename.value.length < 1) {
                alert("Please enter shipping profile name.");
				f.profilename.focus(); 
                return false;
         }

         if (f.address1.value.length < 1) {
                alert("Please enter street address.");
				f.address1.focus(); 
                return false;
         }

         if (f.city.value.length < 1) {
                alert("Please enter city.");
				f.city.focus(); 
                return false;
         }
        

 		 if (f.zip.value.length < 1 )
		 {
                alert("Please enter zipcode in correct format.");
				f.zip.focus(); 
                return false;             
         }
            
}

function checkBillingForm(f) {
          


         if (f.fname.value.length < 1) {
                alert("Please enter first name.");
				f.fname.focus(); 
                return false;
         }

         if (f.lname.value.length < 1) {
                alert("Please enter last name.");
				f.lname.focus(); 
                return false;
         }		 

         if (f.address1.value.length < 1) {
                alert("Please enter street address.");
				f.address1.focus(); 
                return false;
         }

         if (f.city.value.length < 1) {
                alert("Please enter city.");
				f.city.focus(); 
                return false;
         }
        

         if (f.organization.value.length < 1) {
                alert("Please enter organization or agency information.");
				f.organization.focus(); 
                return false;
         }
		/*
         if (f.agency.value.length < 1) {
                alert("Please enter agency information.");
				f.agency.focus(); 
                return false;
         }        
		*/
         if (f.title.value.length < 1) {
                alert("Please enter job title.");
				f.title.focus(); 
                return false;
         }   

         if (f.labType.value.length < 1) {
                alert("Please enter Lab Type Information.");
				f.labType.focus(); 
                return false;
         }   

         if (f.discipline.value.length < 1) {
                alert("Please enter Discipline Information.");
				f.discipline.focus(); 
                return false;
         }     
  
 		 if (f.zip.value.length < 1 )
		 {
                alert("Please enter zipcode in correct format.");
				f.zip.focus(); 
                return false;             
         }
            
         if (f.phone.value.length < 1) {
                alert("Please enter contact phone number.");
				f.phone.focus(); 
                return false;
         }
}

function contactForm (f) {
	return true;
}


function checkEmailForm(f) {
	if (f.newemail.value.indexOf("@") + "" == "-1" || f.newemail.value.indexOf(".") + "" == "-1" || f.newemail.value == "" )
	 { 
		alert("Please enter email address in correct format.");
		f.newemail.focus();
		return false;
	 }
}

function registerUserInfo(ff)
{ 
	var f=document.getElementById(ff);
	if ( !formCheck(f) ) return;		// check input from 
	var url="admin/user-register.php";

	var radiovalue=0;
	for (i=0;i<f.netPay.length ;i++ )
		if ( f.netPay[i].checked)
			radiovalue=f.netPay[i].value;

	if ( f.cc.checked )
		ccValue=1;
	else
		ccValue=0;

	if ( f.ur.checked )
		urValue=1;
	else
		urValue=0;

	if ( f.ck.checked )
		ckValue=1;
	else
		ckValue=0;

	if ( f.wt.checked )
		wtValue=1;
	else
		wtValue=0;

	if ( f.cod.checked )
		codValue=1;
	else
		codValue=0;	
	
	var params="email="+escape(f.email.value)+"&pwd="+escape(f.pwd.value)+"&status="+f.userType.value+"&company="+escape(f.company.value)+"&mailing="+f.mailing.value+"&discount="+f.discount.value+"&taxfree="+f.taxfree.value+"&cc="+ccValue+"&ur="+urValue+"&ck="+ckValue+"&wt="+wtValue+"&cod="+codValue+"&netPay="+radiovalue;
//	alert ( params );

	printProcessWindow("Registering User");				
	xmlHttp=GetXmlHttpObject(registerCleanUp);
	xmlHttp.open("POST", url ,true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlHttp.setRequestHeader("Content-length", params.length); 
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(params);

}


function checkForm() {

//	document.frmAddItem.btnAddtoCart(1).disabled = true;
//	document.frmAddItem.btnAddtoCart(0).disabled = true;
	
			 vQty = -1;
 //----------------------------------------------
 //-------- accomodate a single item on the page
 //----------------------------------------------
			varval = parseFloat(document.itemList.qty.length);


			if (varval =1){
				if (document.itemList.qty.value > 0)
				  vQty++;
			}

			if (document.itemList.qty.length > 1){	
				for (i=0; i< document.itemList.qty.length; i++) {
					if (document.itemList.qty[i].value > 0) {
					  vQty++;
					}
				}	
				
			}	
//--------	
		
			if (vQty == -1) {
	//		document.itemList.btnAddtoCart(1).disabled = false;
	//		document.itemList.btnAddtoCart(0).disabled = false;
			
			alert ("You have not entered any quantity.");
			
			return false;
			}

			if ( checkoutFlag )	
				;
			else
				document.itemList.action="/favorite/";

//			document.frmAddItem.btnAddtoCart(1).disabled = false;
//			document.frmAddItem.btnAddtoCart(0).disabled = false;
			return true;
		}

function changePath() {
	checkoutFlag=false;
}

function favoriteListConfirm(id) {
	if ( confirm("Deleting this list will permanently drop all record. Continue?") )
				self.location.href ='?DID='+id;	
}

function checkQuickForm() {

		var reg= /[^0-9]/;		// catches everything except numbers

		if (document.itemList.qty.length > 1){	
			for (i=0; i< document.itemList.qty.length; i++) {

				if ( reg.test(document.itemList.qty[i].value) || document.itemList.qty[i].value == ""   )
				{
					alert ("You have entered an invalid value for an item...\n please enter a quantity then submit.");
					document.itemList.qty[i].focus();
					return false;
				}
			}	
			
		}		

		return true;
	}