///////////////////////////////////////////////////////////////////////////////////////
function validate_cr()
{

var txt_cn = document.getElementById("cn"),
    txt_cadd = document.getElementById("cadd"),
    txt_ct = document.getElementById("ct"),
    txt_region = document.getElementById("region"),
    txt_country = document.getElementById("country"),
    txt_zip = document.getElementById("zip"),
    txt_con = document.getElementById("con"),
	txt_ccl = document.getElementById("ccl"),
    txt_ph = document.getElementById("ph"),
	txt_ext = document.getElementById("ext"),
	txt_email = document.getElementById("em"),
	txt_fax = document.getElementById("fax");

		
	if(txt_cn.value == ""){
		alert("Please specify company name !")
		txt_cn.focus();
		return false;
	}
	if(txt_cadd.value == ""){
		alert("Please specify company address !")
		txt_cadd.focus();
		return false;
	}
	if(txt_ct.value == ""){
		alert("Please specify city !")
		txt_ct.focus();
		return false;
	}
	if(txt_region.value == ""){
		alert("Please select region !")
		txt_region.focus();
		return false;
	}
	if(txt_country.value == ""){
		alert("Please select state !")
		txt_country.focus();
		return false;
	}
	if(txt_zip.value == "" ){
		alert("Please specify zip code !")
		txt_zip.focus();
		return false;
	}
	if (!validateZIP(txt_zip.value)){
		txt_zip.focus();
		return false;
	}
	if(txt_con.value == ""){
		alert("Please specify contact name!")
		txt_con.focus();
		return false;
	}
	if(txt_ccl.value == ""){
		alert("Please specify contact cell!")
		txt_ccl.focus();
		return false;
	}
	if(txt_ph.value == ""){
		alert("Please specify company phone!")
		txt_ph.focus();
		return false;
	}
	if(txt_ext.value == ""){
		alert("Please specify extension!")
		txt_ext.focus();
		return false;
	}
	if(!IsNumeric(txt_ext.value)){
		alert("Please enter correct extension!")
		txt_ext.focus();
		return false;
	} 
	if(txt_email.value==""){
		alert("Your email address does not seems to be valid!")
		txt_email.focus();
		return false;
	}
	
	var at=txt_email.value.indexOf("@");
	var dot=txt_email.value.lastIndexOf(".");	
	if(dot<=at){
		alert("Your email address does not seems to be valid!")
		txt_email.focus();
		return false;
	}
	if(txt_fax.value == ""){
		alert("Please specify fax!")
		txt_fax.focus();
		return false;
	}


return true	
}
///////////////////////////////////////////////////////////////////
function validate_pr()
{

var txt_an = document.getElementById("an"),
    txt_aad = document.getElementById("aad"),
    txt_ct = document.getElementById("ct"),
    txt_region = document.getElementById("region"),
    txt_country = document.getElementById("country"),
    txt_zip = document.getElementById("zip"),
    txt_con = document.getElementById("con"),
    txt_ph = document.getElementById("ph"),
	txt_ext = document.getElementById("ext"),
	txt_email = document.getElementById("em"),
	txt_fax = document.getElementById("fax");

		
	if(txt_an.value == ""){
		alert("Please specify agency name !")
		txt_an.focus();
		return false;
	}
	if(txt_aad.value == ""){
		alert("Please specify agency address !")
		txt_aad.focus();
		return false;
	}
	if(txt_ct.value == ""){
		alert("Please specify city !")
		txt_ct.focus();
		return false;
	}
	if(txt_region.value == ""){
		alert("Please select region !")
		txt_region.focus();
		return false;
	}
	if(txt_country.value == ""){
		alert("Please select state !")
		txt_country.focus();
		return false;
	}
	if(txt_zip.value == "" ){
		alert("Please specify zip code !")
		txt_zip.focus();
		return false;
	}
	if (!validateZIP(txt_zip.value)){
		txt_zip.focus();
		return false;
	}
	if(txt_con.value == ""){
		alert("Please specify contact name!")
		txt_con.focus();
		return false;
	}
	if(txt_ph.value == ""){
		alert("Please specify agency phone!")
		txt_ph.focus();
		return false;
	}
	if(txt_ext.value == ""){
		alert("Please specify extension!")
		txt_ext.focus();
		return false;
	}
	if(!IsNumeric(txt_ext.value)){
		alert("Please enter correct extension!")
		txt_ext.focus();
		return false;
	} 
	if(txt_email.value==""){
		alert("Your email address does not seems to be valid!")
		txt_email.focus();
		return false;
	}
	
	var at=txt_email.value.indexOf("@");
	var dot=txt_email.value.lastIndexOf(".");	
	if(dot<=at){
		alert("Your email address does not seems to be valid!")
		txt_email.focus();
		return false;
	}
	if(txt_fax.value == ""){
		alert("Please specify fax!")
		txt_fax.focus();
		return false;
	}


return true	
}
////////////////////////////////////////////////////////////////////////

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 validate0()
{

var txt_ph = document.getElementById("ph"),
	txt_nm = document.getElementById("nm"),
	txt_email = document.getElementById("em");

		
	if(txt_nm.value == ""){
		alert("Please specify your name!")
		txt_nm.focus();
		return false;
	}
	if(txt_email.value==""){
		alert("Your email address does not seems to be valid!")
		txt_email.focus();
		return false;
	}
	
	var at=txt_email.value.indexOf("@");
	var dot=txt_email.value.lastIndexOf(".");	
	if(dot<=at){
		alert("Your email address does not seems to be valid!")
		txt_email.focus();
		return false;
	}
	if(txt_ph.value == ""){
		alert("Please specify your phone number!")
		txt_ph.focus();
		return false;
	}

return true	
}
///////
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code.  Please try again.");
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return false;
   }
}
return true;
}
/////////////////////////////////////////////////////////////////
////////////////////////////////////////onchage procedure////////////////////////////////////////////
var AfricaArray =  new Array("('Select country','',true,true)",
"('Ethiopia','Ethiopia')",
"('Somalia','Somalia')",
"('South Africa','South Africa')",
"('Other')");
var Middle_EastArray =  new Array("('Select country','',true,true)",
"('Egypt','Egypt')",
"('Iran','Iran')",
"('Israel','Israel')",
"('Kuwait','Kuwait')",
"('Lebanon','Lebanon')",
"('Morocco','Morocco')",
"('Saudi Arabia','Saudi Arabia')",
"('Syria','Syria')",
"('Turkey','Turkey')",
"('U. A. Emirates','U. A. Emirates')",
"('Other')");
var AsiaArray =  new Array("('Select country','',true,true)",
"('Armenia','Armenia')",
"('Bangladesh','Bangladesh')",
"('Cambodia','Cambodia')",
"('China','China')",
"('India','India')",
"('Indonesia','Indonesia')",
"('Japan','Japan')",
"('Malaysia','Malaysia')",
"('Myanmar','Myanmar')",
"('Nepal','Nepal')",
"('Pakistan','Pakistan')",
"('Philippines','Philippines')",
"('Singapore','Singapore')",
"('South Korea','South Korea')",
"('Sri Lanka','Sri Lanka')",
"('Taiwan','Taiwan')",
"('Thailand','Thailand')",
"('Uzbekistan','Uzbekistan')",
"('Vietnam','Vietnam')",
"('Other')");
var EuropeArray =  new Array("('Select country','',true,true)",
"('Albania','Albania')",
"('Austria','Austria')",
"('Belarus','Belarus')",
"('Belgium','Belgium')",
"('Bosnia','Bosnia')",
"('Bulgaria','Bulgaria')",
"('Croatia','Croatia')",
"('Cyprus','Cyprus')",
"('Czech Rep.','Czech Rep.')",
"('Denmark','Denmark')",
"('Estonia','Estonia')",
"('Finland','Finland')",
"('France','France')",
"('Germany','Germany')",
"('Greece','Greece')",
"('Hungary','Hungary')",
"('Iceland','Iceland')",
"('Ireland','Ireland')",
"('Italy','Italy')",
"('Latvia','Latvia')",
"('Liechtenstein','Liechtenstein')",
"('Lithuania','Lithuania')",
"('Luxembourg','Luxembourg')",
"('Macedonia','Macedonia')",
"('Malta','Malta')",
"('Monaco','Monaco')",
"('Netherlands','Netherlands')",
"('Norway','Norway')",
"('Poland','Poland')",
"('Portugal','Portugal')",
"('Romania','Romania')",
"('Russia','Russia')",
"('Slovakia','Slovakia')",
"('Slovenia','Slovenia')",
"('Spain','Spain')",
"('Sweden','Sweden')",
"('Switzerland','Switzerland')",
"('Ukraine','Ukraine')",
"('United Kingdom','United Kingdom')",
"('Other')");
var AustraliaArray =  new Array("('Select country','',true,true)",
"('Australia','Australia')",
"('New Zealand','New Zealand')",
"('Other')");
var Latin_AmericaArray =  new Array("('Select country','',true,true)",
"('Costa Rica','Costa Rica')",
"('Cuba','Cuba')",
"('El Salvador','El Salvador')",
"('Guatemala','Guatemala')",
"('Haiti','Haiti')",
"('Jamaica','Jamaica')",
"('Mexico','Mexico')",
"('Panama','Panama')",
"('Other')");
var North_AmericaArray =  new Array("('Select country','',true,true)",
"('Canada','Canada')",
"('USA','USA')",
"('Other')");
var South_AmericaArray =  new Array("('Select country','',true,true)",
"('Argentina','Argentina')",
"('Bolivia','Bolivia')",
"('Brazil','Brazil')",
"('Chile','Chile')",
"('Colombia','Colombia')",
"('Ecuador','Ecuador')",
"('Paraguay','Paraguay')",
"('Peru','Peru')",
"('Suriname','Suriname')",
"('Uruguay','Uruguay')",
"('Venezuela','Venezuela')",
"('Other')");
function populateCountry(selected) {

country = document.getElementById("country");
region = document.getElementById("region");

var selectedArray = eval(selected + "Array");
while (selectedArray.length < country.options.length) {
country.options[(country.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("country.options[i]=" + "new Option" + selectedArray[i]);
}
if (region.options[0].value == '') {
region.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {   	
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
            }
         }
      }
   }
}

function populateUSstate(inForm,selected) {  
var stateArray =  new Array("('Select State','',true,true)",
"('Alabama','Alabama')",
"('Alaska','Alaska')",
"('Arizona','Arizona')",
"('Arkansas','Arkansas')",
"('California','California')",
"('Colorado','Colorado')",
"('Connecticut','Connecticut')",
"('Delaware','Delaware')",
"('Columbia','Columbia')",
"('Florida','Florida')",
"('Georgia','Georgia')",
"('Hawaii','Hawaii')",
"('Idaho','Idaho')",
"('Illinois','Illinois')",
"('Indiana','Indiana')",
"('Iowa','Iowa')",
"('Kansas','Kansas')",
"('Kentucky','Kentucky')",
"('Louisiana','Louisiana')",
"('Maine','Maine')",
"('Maryland','Maryland')",
"('Massachusetts','Massachusetts')",
"('Michigan','Michigan')",
"('Minnesota','Minnesota')",
"('Mississippi','Mississippi')",
"('Missouri','Missouri')",
"('Montana','Montana')",
"('Nebraska','Nebraska')",
"('Nevada','Nevada')",
"('New Hampshire','New Hampshire')",
"('New Jersey','New Jersey')",
"('New Mexico','New Mexico')",
"('New York','New York')",
"('North Carolina','North Carolina')",
"('North Dakota','North Dakota')",
"('Ohio','Ohio')",
"('Oklahoma','Oklahoma')",
"('Oregon','Oregon')",
"('Pennsylvania','Pennsylvania')",
"('Rhode Island','Rhode Island')",
"('South Carolina','South Carolina')",
"('South Dakota','South Dakota')",
"('Tennessee','Tennessee')",
"('Texas','Texas')",
"('Utah','Utah')",
"('Vermont','Vermont')",
"('Virginia','Virginia')",
"('Washington','Washington')",
"('West Virginia','West Virginia')",
"('Wisconsin','Wisconsin')",
"('Wyoming','Wyoming')");
if (selected == 'USA') {
for (var i=0; i < stateArray.length; i++) {
eval("inForm.country.options[i]=" + "new Option" + stateArray[i]);
}
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0)
}
else {    	
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0)
         }
      }
   }
}
else {
}  
if (selected == 'Other') {
newCountry = "";
while (newCountry == ""){
newCountry=prompt ("Please enter the name of your country.", "");
}
if (newCountry != null) {
inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
inForm.country.options[inForm.country.options.length]=new Option('Other, not listed','Other');
   }
}
if(inForm.country.options[0].text == 'Select country') {
inForm.country.options[0]= null;
   }
}
