// safedecisions.js

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function checkRegForm(objForm){
	if (objForm.userid.value == ''){
		alert('Please enter a value in the User Name field')
		objForm.userid.focus();
		return false
	} 
	if (objForm.userid.value.length < 6 || objForm.userid.value.length > 20){
		alert('Your User Name must be between 6 and 20 characters')
		objForm.userid.focus();
		return false
	} 
	if (objForm.password.value == ''){
		alert('Please enter a value in the password field')
		objForm.password.focus();
		return false
	}
	if (objForm.password.value.length < 6 || objForm.password.value.length > 20){
		alert('Your password must be between 6 and 20 characters')
		objForm.password.focus();
		return false
	}  
	if (objForm.password_confirm.value == ''){
		alert('Please confirm your password')
		objForm.password_confirm.focus();
		return false
	} 
	if (objForm.password.value != objForm.password_confirm.value){
		alert('Your passwords do not match, please reenter')
		objForm.password.focus();
		return false
	} 
	if (objForm.HomePostalCode.value == ''){
		alert('Please enter a value in the zipcode field')
		objForm.HomePostalCode.focus();
		return false
	} 
	if (objForm.CustEmail.value == ''){
		alert('Please enter a value in the email field')
		objForm.CustEmail.focus();
		return false
	}
	if (objForm.Company.value == ''){
		alert('Please enter a value in the Broker name field')
		objForm.Company.focus();
		return false
	}  
	if (objForm.SupplierID.value == ''){
		alert('Please enter a value in the Supplier ID field')
		objForm.SupplierID.focus();
		return false
	}  
	if (objForm.SupplierID.value.length!=7)
	{
		alert('Supplier ID must be 7 numbers in length')
		objForm.SupplierID.focus();
		return false
	}
	if (IsNumeric(objForm.SupplierID.value)==false)
	{
		alert('Supplier ID must be 7 numbers in length')
		objForm.SupplierID.focus();
		return false
	}

	if (objForm.HomeAddress1.value == ''){
		alert('Please enter a Home Address')
		objForm.HomeAddress1.focus();
		return false
	}  
	if (objForm.HomeCity.value == ''){
		alert('Please enter a City')
		objForm.HomeCity.focus();
		return false
	}   
	

		
	return true
}


function checkRegForm2(objForm){
	if (objForm.userid.value == ''){
		alert('Please enter a value in the User Name field')
		objForm.userid.focus();
		return false
	} 
	if (objForm.userid.value.length < 6 || objForm.userid.value.length > 20){
		alert('Your User Name must be between 6 and 20 characters')
		objForm.userid.focus();
		return false
	} 
	if (objForm.password.value == ''){
		alert('Please enter a value in the password field')
		objForm.password.focus();
		return false
	}
	if (objForm.password.value.length < 6 || objForm.password.value.length > 20){
		alert('Your password must be between 6 and 20 characters')
		objForm.password.focus();
		return false
	}  
	if (objForm.password_confirm.value == ''){
		alert('Please confirm your password')
		objForm.password_confirm.focus();
		return false
	} 
	if (objForm.password.value != objForm.password_confirm.value){
		alert('Your passwords do not match, please reenter')
		objForm.password.focus();
		return false
	}
	

		
	return true
}

function checkEmpForm(objForm){
	if (objForm.EmpUserID.value == ''){
		alert('Please enter a value in the User Name field')
		objForm.EmpUserID.focus();
		return false
	} 
	if (objForm.EmpUserID.value.length < 6 || objForm.EmpUserID.value.length > 20){
		alert('Your User Name must be between 6 and 20 characters')
		objForm.EmpUserID.focus();
		return false
	} 
	if (objForm.EmpPassword.value == ''){
		alert('Please enter a value in the password field')
		objForm.EmpPassword.focus();
		return false
	}
	if (objForm.EmpPassword.value.length < 6 || objForm.EmpPassword.value.length > 20){
		alert('Your password must be between 6 and 20 characters')
		objForm.EmpPassword.focus();
		return false
	}  
	if (objForm.EmpPassword_Confirm.value == ''){
		alert('Please confirm your password')
		objForm.EmpPassword_Confirm.focus();
		return false
	} 
	if (objForm.EmpPassword.value != objForm.EmpPassword_Confirm.value){
		alert('Your passwords do not match, please reenter')
		objForm.EmpPassword.focus();
		return false
	} 
	
	return true
}


// populates form elements default values
function defaultValue(frmElement,val)
{
	if(frmElement)
	{
		// alert(frmElement.type)
		if(frmElement.type=="text"||frmElement.type=="hidden"){
			frmElement.value = val;
		}else{
			for(i=0;i<frmElement.length;i++)
			{
				optionValue = String(frmElement[i].value)
				optionValue = optionValue.toLowerCase()
			
				targetValue = String(val)
				targetValue = targetValue.toLowerCase()
				
				if (optionValue == targetValue){
					
					
					if(frmElement.type=="select-one"){
						frmElement.selectedIndex = i;
					}else if (frmElement.type=="select-multiple"){
						frmElement[i].selected = true;
					}else if (frmElement[i].type=="radio"){
						frmElement[i].checked = true;
					}else if (frmElement[i].type=="checkbox"){
					frmElement[i].checked = true;	
					}
				}
			}
		
		}
	} else {
	alert('form element not found')
	}
}
/*-------------------------
/ For nav and image swaping - CDavis
---------------------------*/
function MM_findObj(n, d) { //v4.1
	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_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_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_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];}
}

menuArray = new Array("aboutMenu","supportMenu","productsMenu","contactMenu")

function changeMenu (divname) {
	clearMenus();
	obj = MM_findObj(divname);
	if (obj) {
		obj.style.display = 'block';
	} 
}

function clearMenus(){
	for(i=0;i<menuArray.length; i++){
		obj = MM_findObj(menuArray[i]);
		if (obj){
			obj.style.display = 'none';
		}
	}
}