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];}
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresize'
	win = window.open(mypage,myname,settings)
}

function ProspectiveSuppliersValidate(form){

	var str_coname = form.fm_coname.value;
		if(str_coname.length == 0){
	alert("Company name is required.");
		form.fm_coname.focus();
	return false;
		}

	var str_cotype = form.fm_cotype.value;
		if(str_cotype.length == 0) {
		alert("Type of business must be selected.");
		form.fm_cotype.focus();
		return false;
		}

	var str_cap = form.fm_capabilities.value;
		if(str_cap.length == 0) {
		alert("Capabilities field is required.");
		form.fm_capabilities.focus();
		return false;
		}

	var str_add1 = form.fm_add1.value;
		if(str_add1.length == 0) {
		alert("Address field is required.");
		form.fm_add1.focus();
		return false;
		}

	var str_city = form.fm_city.value;
		if(str_city.length == 0) {
		alert("City is required.");
		form.fm_city.focus();
		return false;
		}

	var str_zip = form.fm_zip.value;
		if(str_zip.length == 0) {
		alert("Zip or Postal Code is required.");
		form.fm_zip.focus();
		return false;
		}

	var str_country = form.fm_country.value;
		if(str_country.length == 0) {
		alert("Country is required.");
		form.fm_country.focus();
		return false;
		}

	var str_fname = form.fm_fname.value;
		if(str_fname.length == 0) {
		alert("First name is required.");
		form.fm_fname.focus();
		return false;
		}

	var str_lname = form.fm_lname.value;
		if(str_lname.length == 0) {
		alert("Last name is required.");
		form.fm_lname.focus();
		return false;
		}

	var str_title = form.fm_title.value;
		if(str_title.length == 0) {
		alert("Title is required.");
		form.fm_title.focus();
		return false;
		}

	var str_email = form.fm_email.value;
		if(str_email.length == 0) {
		alert("Email is required.");
		form.fm_email.focus();
		return false;
		}

	var str_emailc = form.fm_emailconf.value;
		if(str_emailc.length == 0) {
		alert("Email confirmation is required.");
		form.fm_emailconf.focus();
		return false;
		}


	var str_email1 = form.fm_email.value;
	var str_email2 = form.fm_emailconf.value;
		if (str_email1 != str_email2) {
		alert("Email addresses do not match. Please try again.");
		form.fm_email.value = "";
		form.fm_emailconf.value = "";
		form.fm_email.focus();
		return false;
		}


	var str_phone = form.fm_phone.value;
		if(str_phone.length == 0) {
		alert("Please enter a phone number.");
		form.fm_phone.focus();
		return false;
		}
}

function SearchValidator(theForm) {
	// check if first drop down is selected, if so, invalid selection
	var listCheck = theForm.region_id.selectedIndex;
	if (theForm.region_id.options[listCheck].value=="none") {
	alert("Please select a territory.");
	theForm.region_id.focus();
	return false;
	}
}

function SearchValidator2(theForm2) {
	// check if first drop down is selected, if so, invalid selection
	var listCheck = theForm2.fm_distributor_id.selectedIndex;
	if (theForm2.fm_distributor_id.options[listCheck].value=="none") {
	alert("Please select a territory.");
	theForm2.fm_distributor_id.focus();
	return false;
	}
}

function SearchValidator3(theForm3) {
	// check if first drop down is selected, if so, invalid selection
	var listCheck = theForm3.servicecenter.selectedIndex;
	if (theForm3.servicecenter.options[listCheck].value=="none") {
	alert("Please select a country.");
	theForm3.servicecenter.focus();
	return false;
	}
}

function PubsRegistrationValidate(form) {
	var str = form.fm_username.value;
	if(str.length == 0){
alert("Username is required.");
	form.fm_username.focus();
return false;
	}

	var str_uname = form.fm_username.value;
	if(str_uname.length > 16) {
	alert("Username must be less than 16 characters.");
	form.fm_username.focus();
	return false;
	}

	var str_pw = form.fm_pw.value;
	if(str_pw.length == 0 || str_pw.length < 6) {
	alert("Password is required, and must be at least 6 characters.");
	form.fm_pw.focus();
	return false;
	}

	var str_pwc = form.fm_pw_conf.value;
	if(str_pwc.length == 0) {
	alert("Password confirmation is required.");
	form.fm_pw_conf.focus();
	return false;
	}

	var str_pw1 = form.fm_pw.value;
	var str_pw2 = form.fm_pw_conf.value;
	if (str_pw1 != str_pw2) {
	alert("Passwords do not match. Please try again.");
	form.fm_pw.value = "";
	form.fm_pw_conf.value = "";
	form.fm_pw.focus();
	return false;
	}

	var str_fname = form.fm_fname.value;
	if(str_fname.length == 0) {
	alert("First name is required.");
	form.fm_fname.focus();
	return false;
	}

	var str_lname = form.fm_lname.value;
	if(str_lname.length == 0) {
	alert("Last name is required.");
	form.fm_lname.focus();
	return false;
	}

	var str_email = form.fm_email.value;
	if(str_email.length == 0) {
	alert("Email address is required.");
	form.fm_email.focus();
	return false;
	}

	var str_cname = form.fm_coname.value;
	if(str_cname.length == 0) {
	alert("Please enter company name or Self.");
	form.fm_coname.focus();
	return false;
	}

	var str_phone = form.fm_phone.value;
	if(str_phone.length == 0) {
	alert("Please enter a phone number.");
	form.fm_phone.focus();
	return false;
	}

	// phone number validation
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	function isInteger(s){   
	var i;
for (i = 0; i < s.length; i++)
{   
	// Check that current character is number.
	var c = s.charAt(i);
	if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
	}//end function

	function stripCharsInBag(s, bag){   
	var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{   
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
    return returnString;
	}//end function

	function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}//end function


	var phone = form.fm_phone.value;
	if (checkInternationalPhone(phone)==false){
	alert("Please enter a valid phone number.")
	form.fm_phone.focus()
	return false;
	}




	// fax number validation

	var str_fax = form.fm_fax.value;
	if (str_fax.length != 0){
	var fax = form.fm_fax.value;
	if (checkInternationalPhone(fax)==false){
	alert("Please enter a valid fax number.")
	form.fm_fax.focus()
	return false;
	}
	}

	var str_addr = form.fm_address.value;
	if(str_addr.length == 0) {
	alert("Please enter an address.");
	form.fm_address.focus();
	return false;
	}

	var str_city = form.fm_city.value;
	if(str_city.length == 0) {
	alert("Please enter a city.");
	form.fm_city.focus();
	return false;
	}

	var str_state = form.fm_state.value;
	if(str_state.length == 0) {
	alert("Please enter a state.");
	form.fm_state.focus();
	return false;
	}

	var str_zip = form.fm_zip.value;
	if(str_zip.length == 0) {
	alert("Please enter a zip code.");
	form.fm_zip.focus();
	return false;
	}

	//validate that country is selected		
	var str_country = form.fm_country.value;
	if(str_country.length == 0) {
	alert("Country must be selected.");
	form.fm_country.focus();
	return false;
	}

	//validate radio button for citizenship status
	myOption = -1;
	for (i=form.fm_citizen.length-1; i > -1; i--) {
	if (form.fm_citizen[i].checked) {
		myOption = i;
		}
	}
	if (myOption == -1) {
	alert("You must indicate citizenship status.");
	form.fm_citizen[0].focus();
	return false;
	}

	//validate terms and conditions
	if(!form.fm_terms.checked) {
	alert("You must read and agree to terms before registering.");
	form.fm_terms.focus();
	return false;
	}

} 

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300');");
}

function PubsUpdateValidate(form) {

	var str_pw = form.fm_pw.value;
	if(str_pw.length == 0) {
	alert("Password is required.");
	form.fm_pw.focus();
	return false;
	}

	var str_pwc = form.fm_pw_conf.value;
	if(str_pwc.length == 0) {
	alert("Password confirmation is required.");
	form.fm_pw_conf.focus();
	return false;
	}

	var str_pw1 = form.fm_pw.value;
	var str_pw2 = form.fm_pw_conf.value;
	if (str_pw1 != str_pw2) {
	alert("Passwords do not match. Please try again.");
	form.fm_pw.value = "";
	form.fm_pw_conf.value = "";
	form.fm_pw.focus();
	return false;
	}

	var str_fname = form.fm_fname.value;
	if(str_fname.length == 0) {
	alert("First name is required.");
	form.fm_fname.focus();
	return false;
	}

	var str_lname = form.fm_lname.value;
	if(str_fname.length == 0) {
	alert("Last name is required.");
	form.fm_lname.focus();
	return false;
	}

	var str_email = form.fm_email.value;
	if(str_email.length == 0) {
	alert("Email address is required.");
	form.fm_email.focus();
	return false;
	}

	var str_cname = form.fm_coname.value;
	if(str_cname.length == 0) {
	alert("Please enter company name or Self.");
	form.fm_coname.focus();
	return false;
	}

	var str_phone = form.fm_phone.value;
	if(str_phone.length == 0) {
	alert("Please enter a phone number.");
	form.fm_phone.focus();
	return false;
	}

	// phone number validation
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

	function isInteger(s){   
	var i;
for (i = 0; i < s.length; i++)
{   
	// Check that current character is number.
	var c = s.charAt(i);
	if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
	}//end function

	function stripCharsInBag(s, bag){   
	var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{   
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
    return returnString;
	}//end function

	function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}//end function


	var phone = form.fm_phone.value;
	if (checkInternationalPhone(phone)==false){
	alert("Please enter a valid phone number.")
	form.fm_phone.focus()
	return false;
	}




	// fax number validation

	var str_fax = form.fm_fax.value;
	if (str_fax.length != 0){
	var fax = form.fm_fax.value;
	if (checkInternationalPhone(fax)==false){
	alert("Please enter a valid fax number.")
	form.fm_fax.focus()
	return false;
	}
	}

	var str_addr = form.fm_address.value;
	if(str_addr.length == 0) {
	alert("Please enter an address.");
	form.fm_address.focus();
	return false;
	}

	var str_city = form.fm_city.value;
	if(str_city.length == 0) {
	alert("Please enter a city.");
	form.fm_city.focus();
	return false;
	}

	var str_state = form.fm_state.value;
	if(str_state.length == 0) {
	alert("Please enter a state.");
	form.fm_state.focus();
	return false;
	}

	var str_zip = form.fm_zip.value;
	if(str_zip.length == 0) {
	alert("Please enter a zip code.");
	form.fm_zip.focus();
	return false;
	}

	//validate that country is selected		
	var str_country = form.fm_country.value;
	if(str_country.length == 0) {
	alert("Country must be selected.");
	form.fm_country.focus();
	return false;
	}

	//validate radio button for citizenship status
	myOption = -1;
	for (i=form.fm_citizen.length-1; i > -1; i--) {
	if (form.fm_citizen[i].checked) {
		myOption = i;
		}
	}
	if (myOption == -1) {
	alert("You must indicate citizenship status.");
	form.fm_citizen[0].focus();
	return false;
	}

	//validate terms and conditions
	if(!form.fm_terms.checked) {
	alert("You must read and agree to terms before registering.");
	form.fm_terms.focus();
	return false;
	}

} 
function LoginValidate(form) {

	var str_user = form.un.value;
	if(str_user.length == 0) {
	alert("Please enter a username.");
	form.un.focus();
	return false;
	}

	var str_pass = form.pw.value;
	if(str_pass.length == 0) {
	alert("Please enter a password.");
	form.pw.focus();
	return false;
	}


} 
