//***********************************************************************************
//	WINDOW ONLOAD / DEFAULT KEY & WEB-SERVER CONTROL INTERNAL FUNCTIONS SECTION
//***********************************************************************************
//ONLOAD - Event:
if ( window.onload )   {
	var funWindowLoad = window.onload;
	window.onload = new Function( "funWindowLoad( ); jsOnLoad( );" );
}
else
	window.onload = jsOnLoad;
	
function jsOnLoad(){	
	
}
//------------------------------------------------------------------------------------
//DEFAULT KEY DOWN - Event:
function jsOnKeyDown(){	
	var llngKeyEvent = window.event.keyCode;
	
	//Handle the enter key:
	if (llngKeyEvent == 13){
		
	}
	
}
//------------------------------------------------------------------------------------
//COMBOBOX - Internal OnChange Event:
function ComboBox_OnChange(astrControlId){

	switch (astrControlId){
	
		case "COUNTRY":
			var strCountryCode = GetComboBoxById(astrControlId).GetValue();
			
			var objCmb = GetComboBoxById("State");
			var objTxt = GetTextBoxById("State");
			
			if (strCountryCode == "US"){
			
				objCmb.SetDisplay(true);
				objTxt.SetDisplay(false);		
			
			}
			else {
			
				objCmb.SetDisplay(false);
				objTxt.SetDisplay(true);
			
			}
			
			//Alternate between required and optional based on the country selected:
			switch (strCountryCode){
			
				case "US":
					objCmb.SetEnabled("required");
				
					break;
				case "CA":
					objTxt.SetEnabled("required");
					
					break;
				
				default:
					objTxt.SetEnabled("true");
				
					break;
			
			}
			
			break;			
	
	}

}
//------------------------------------------------------------------------------------
//BUTTON - Internal OnClick Event:
function Button_OnClick(astrControlId){

	switch (astrControlId){
	
		case "SUBMITCONTACT":
		case "SUBMITCONTACTBOTTOM":
			jsForm_BeforeSubmit();
			
			break;			
		
	}
	
}
//------------------------------------------------------------------------------------

//FORM FUNCTIONS:
//------------------------------------------------------------------------------------
function jsForm_BeforeSubmit(){

	//Check to make sure required fields are filled in:		
	if (jsTrim(GetTextBoxById("Email").GetText()) == ""){
		alert("Email Address is required.");
		GetTextBoxById("Email").Focus();
		return;
	}		
	if (jsIsEmail(jsTrim(GetTextBoxById("Email").GetText())) == false){		
		alert("Email Address is not formatted properly.");	
		GetTextBoxById("Email").Focus();		
		return;
	}
	if (jsTrim(GetTextBoxById("Email").GetText()).toLowerCase() != 
						jsTrim(GetTextBoxById("EmailCheck").GetText()).toLowerCase()){
		alert("The second entry of your email address is required " +
				"and must match the first entry.");
		GetTextBoxById("EmailCheck").Focus();
		return;
	}
	if (GetComboBoxById("Salutation").GetValue() == ""){
		alert("Please select a salutation.");
		GetComboBoxById("Salutation").Focus();
		return;
	}		
	if (jsTrim(GetTextBoxById("FirstName").GetText()) == ""){
		alert("First Name is required.");
		GetTextBoxById("FirstName").Focus();
		return;
	}	
	if (jsTrim(GetTextBoxById("LastName").GetText()) == ""){
		alert("Last Name is required.");
		GetTextBoxById("LastName").Focus();
		return;
	}		
	if (jsTrim(GetTextBoxById("Phone1").GetText()) == ""){
		alert("Phone is required.");
		GetTextBoxById("Phone1").Focus();
		return;
	}
		
	var lstrCountryCode = jsTrim(GetComboBoxById("Country").GetValue());
	if (lstrCountryCode == ""){
		alert("Country is required.");
		GetComboBoxById("Country").Focus();
		return;
	}	
	if (jsTrim(GetTextBoxById("Address1").GetText()) == ""){
		alert("Address is required.");
		GetTextBoxById("Address1").Focus();
		return;
	}
	if (jsTrim(GetTextBoxById("City").GetText()) == ""){
		alert("City is required.");
		GetTextBoxById("City").Focus();
		return;
	}
	
	switch (lstrCountryCode){
		
		case "CA":
			if (jsTrim(GetTextBoxById("State").GetText()) == ""){
				alert("State/Province is required.");
				GetTextBoxById("State").Focus();
				return;
			}		
		
			break;
			
		case "US":
			if (jsTrim(GetComboBoxById("State").GetUnboundText()) == ""){
				alert("State/Province is required.");
				GetComboBoxById("State").Focus();
				return;
			}	
			
			break;		
	
	}	
	
	if (jsTrim(GetTextBoxById("PostalCode").GetText()) == ""){
		alert("Postal Code is required.");
		GetTextBoxById("PostalCode").Focus();
		return;
	}		
	
	
	//HTML format the comments value:
	document.frmMain.hidComments.value =
		jsReplace(jsReplace(GetTextBoxById("Comments").GetText(), "\n", "<BR>"), "\r", "");
	
	//Initialize the pipeline:
	GetPipeLineById("").Initialize("jsForm_AfterSubmit", "Email_SendInquiry");	
}
//------------------------------------------------------------------------------------
function jsForm_AfterSubmit(){	
	
	var lstrResult = GetPipeLineById("").GetResult();	


	if (lstrResult == "0"){
	
		//Show the thank you table:
		document.getElementById("tblForm").style.display = "none";
		document.getElementById("tblThankYou").style.display = "block";	
		
	}
	else {
	
		//Alert the user of the error that occured:
		alert(lstrResult);		
		
	}
}
//------------------------------------------------------------------------------------
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_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];}
}

window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" 
 && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" 
 && bVer < 4);
 var blink_speed=500;
 var i=0;
 
if (NS4 || IE4) {
 if (navigator.appName == "Netscape") {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
}

//BLINKING
function Blink(layerName){
 if (NS4 || IE4) { 
 if(i%2==0)
 {
 eval(layerRef+'["'+layerName+'"]'+
 styleSwitch+'.visibility="visible"');
 }
 else
 {
 eval(layerRef+'["'+layerName+'"]'+
 styleSwitch+'.visibility="hidden"');
 }
 } 
 if(i<1)
 {
 i++;
 } 
 else
 {
 i--
 }
 setTimeout("Blink('"+layerName+"')",blink_speed);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function check(url)
{
	merchWindow =window.open(url,"Discount","height=350,width=500,innerHeight=0,innerWidth=0,outerHeight=0,outerWidth=0,screenX=150,left=150,screenY=125,top=125,channelmode=0,dependent=0,directories=0,fullscreen=no,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0")
}