URL = window.location.href;

var pagename_array = URL.split("/");

if (!pagename_array[3]) {
result = "Home";

} else {

var barefile_array = pagename_array[3].split(".");
var result = barefile_array[0];

if	(result == "index" || result == "" || !result)	{
	result = "Home";
}
else if	(result == "about")	{
	result = "About Us";
}
else if	(result == "testimonial")	{
	result = "Testimonials";
}
else if	(result == "contact" || result == "_vti_bin")	{
	result = "Contact Us";
}
else if	(result == "type-1a")	{
	result = "Type 1A";
}
else if	(result == "type-1")	{
	result = "Type 1";
}
else if	(result == "mxz")	{
	result = "MXZ";
}
else if	(result == "fibreglass")	{
	result = "Fibreglass";
}
else if	(result == "safety-step")	{
	result = "Safety Step";
}
else if	(result == "accessories")	{
	result = "Accessories";
}
else if	(result == "planks")	{
	result = "Telescoping Planks";
}
else if	(result == "skyscraper")	{
	result = "Skyscraper";
}

}

function mouseOver(src,colorOver)	{
   if (!src.contains(event.fromElement))	{
   src.style.cursor = 'hand'; src.bgColor = colorOver;
   }
}
function mouseOut(src,colorIn)	{
   if (!src.contains(event.toElement))	{
   src.style.cursor = 'default';
   src.bgColor = colorIn;
   }
}
function mouseClk(src)	{
   if(event.srcElement.tagName=='TD')	{
   src.children.tags('A')[0].click();
   }
}


function PreLoad() {

if (document.images != null) {

clickme1 = new Image();
clickme1.src = "/images/popups/popup-close.gif";
clickme2 = new Image();
clickme2.src = "/images/popups/popup-close-over.gif";
clickme3 = new Image();
clickme3.src = "/images/popups/popup-back.gif";
clickme4 = new Image();
clickme4.src = "/images/popups/popup-back-over.gif";
clickme5 = new Image();
clickme5.src = "/images/popups/popup-next.gif";
clickme6 = new Image();
clickme6.src = "/images/popups/popup-next-over.gif";

buyme1 = new Image();
buyme1.src = "/images/buynow.gif";
buyme2 = new Image();
buyme2.src = "/images/buynow-over.gif";

}
	loaded = 1;
}

function hiLite(imgDocID,imgObjName) {
if (document.images !=null) {
  if (loaded)
   document.images[imgDocID].src = eval(imgObjName + ".src")
  }
}

function showLayer() {
  if (navigator.appName.indexOf("Netscape")>-1) {
    document.profile.visibility = "visible";
  } else {
    document.all.profile.style.visibility = "visible";
  }
}

function hideLayer() {
  if (navigator.appName.indexOf("Netscape")>-1) {
    document.profile.visibility = "hidden";
  } else {
    document.all.profile.style.visibility = "hidden";
  }
}



function popup(winName,URL,width,height,scroll) {

 var baseURL = "http://www.canadaladder.com/";
 if(URL.substring(0,7) != "http://") {
  var URL = baseURL + URL;
 }

 if(!window.NewWindow || NewWindow.closed || NewWindow == null) {
  var popup = window.open(URL,winName,"height=" + height + ",width=" + width + ",left=55,top=55,status=0,scrollbars=" + scroll + ",toolbar=0,directories=0,menubar=0,location=0,resizable=1");
  NewWindow = popup;

 }else{

 if (NewWindow.name != winName) {
  var popup = window.open(URL,winName,"height=" + height + ",width=" + width + ",left=55,top=55,status=0,scrollbars=" + scroll + ",toolbar=0,directories=0,menubar=0,location=0,resizable=1");
  NewWindow = popup;
 }else{
  NewWindow.location.href = URL;
  NewWindow.focus();
 }

}
}

function AddwFreeAccessory(frm)
{


if(frm.ladderModel.selectedIndex < 1){
	alert("Please select your ladder.");
	frm.ladderModel.focus();
	return(false);
}


if(frm.FreeAcc1.selectedIndex < 1){
	alert("Please choose your first free accessory.");
	frm.FreeAcc1.focus();
	return(false);
}

if(frm.FreeAcc2.selectedIndex < 1){
	alert("Please choose your second free accessory.");
	frm.FreeAcc2.focus();
	return(false);
}

if(frm.FreeAcc3.selectedIndex < 1){
	alert("Please choose your third free accessory.");
	frm.FreeAcc3.focus();
	return(false);
}

ladderModel = frm.ladderModel.options[frm.ladderModel.selectedIndex].value;
ladderArray = ladderModel.split("!!");
ladderSKU = ladderArray[0]
ladderPrice = ladderArray[1]
ladderDesc = ladderArray[2]

newDesc = ladderDesc + "<BR>With Free Accessories:<BR>" + frm.FreeAcc1.options[frm.FreeAcc1.selectedIndex].value + "<BR>" + frm.FreeAcc2.options[frm.FreeAcc2.selectedIndex].value + "<BR>" + frm.FreeAcc3.options[frm.FreeAcc3.selectedIndex].value

Add(frm.jac_quantity_input.value,ladderSKU,newDesc);
}

function Add(qty,access,brand,shipping) {

  var checkOK = "0123456789";
  var checkStr = qty;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digits in the QTY fields.");
  } else {
document.location.href = "/cart/update-cart.asp?Access=" + access + "&qty=" + qty + "&Brand=" + brand + "&shipping=" + shipping;
}
}

function UpdateDel(AccNum,Checked,AString,qty,Brand,shipping) {

  var checkOK = "0123456789";
  var checkStr = qty;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length; i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length; j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    qty = parseInt(qty); //alert("Please enter only digits in the QTY fields.");

  } else {

if(qty == "") {
	qty = 0;
}
  
if(isNaN(qty) == true) {
	qty = 1;
}

if(Checked != true && qty > 0) {
	cartArray[AccNum] = AString + '-!' + parseInt(qty) + "-!" + Brand + "-!" + shipping;
} else {
	cartArray[AccNum] = 0;
}
}
}

function UpdateandCheckout() {
var i;
var cartString;
cartString = "";

for(i in cartArray)
	if(cartString == "") {
		if(cartArray[i] != 0) {
		cartString = cartArray[i];
		}
	} else {
		if(cartArray[i] != 0) {
		cartString = cartString + "," + cartArray[i];
		}
	}

	if(cartString == "") {
	cartString = "1"
	}
	document.location.href = "update-cart.asp?goto=checkout&Update=" + cartString;
}

function Update() {
var i;
var cartString;
cartString = "";

for(i in cartArray)
	if(cartString == "") {
		if(cartArray[i] != 0) {
		cartString = cartArray[i];
		}
	} else {
		if(cartArray[i] != 0) {
		cartString = cartString + "," + cartArray[i];
		}
	}

	if(cartString == "") {
	cartString = "1"
	}
	document.location.href = "update-cart.asp?Update=" + cartString;
}

function URLDecode(psEncodeString) {
	return unescape(psEncodeString); 
} // end URLDecode

function URLEncode(psEncodeString) {
	return escape(psEncodeString); 
} // end URLEncode

function Check(toCheck,unCheck1,unCheck2) {

if (document.images != null) {
Checkmark = new Image();
Checkmark.src = "http://www.canadaladder.com/cart/images/check.gif";
unCheckmark = new Image();
unCheckmark.src = "http://www.canadaladder.com/cart/images/spacer.gif";
}

	if(document.images != null)	{
	document.images[toCheck].src = Checkmark.src;
	document.images[unCheck1].src = unCheckmark.src;
	document.images[unCheck2].src = unCheckmark.src;
	}

}

function MakeSame() {
if(document.InfoForm.Req_Billing_Name != '')	{
	document.InfoForm.Req_Shipping_Name.value = document.InfoForm.Req_Billing_Name.value;
	}
if(document.InfoForm.Billing_Company != '')	{
	document.InfoForm.Shipping_Company.value = document.InfoForm.Billing_Company.value;
	}
if(document.InfoForm.Req_Billing_Address != '')	{
	document.InfoForm.Req_Shipping_Address.value = document.InfoForm.Req_Billing_Address.value;
	}
if(document.InfoForm.Req_Billing_City != '')	{
	document.InfoForm.Req_Shipping_City.value = document.InfoForm.Req_Billing_City.value;
	}
if(document.InfoForm.Billing_State.selectedIndex.value != 0)	{
	document.InfoForm.Shipping_State.selectedIndex = document.InfoForm.Billing_State.selectedIndex;
	}
if(document.InfoForm.Req_Billing_Zip != '')	{
	document.InfoForm.Req_Shipping_Zip.value = document.InfoForm.Req_Billing_Zip.value;
	}
if(document.InfoForm.Billing_Country.selectedIndex.value != 0)	{
	document.InfoForm.Shipping_Country.selectedIndex = document.InfoForm.Billing_Country.selectedIndex;
	}
if(document.InfoForm.Req_Billing_Phone != '')	{
	document.InfoForm.Req_Shipping_Phone.value = document.InfoForm.Req_Billing_Phone.value;
	}
if(document.InfoForm.Req_Billing_Email != '')	{
	document.InfoForm.Req_Shipping_Email.value = document.InfoForm.Req_Billing_Email.value;
	}
if(document.InfoForm.Billing_Fax != '')	{
	document.InfoForm.Shipping_Fax.value = document.InfoForm.Billing_Fax.value;
	}
}

function CheckForm2(theForm)
{
	if(theForm.SameInfo.checked == true)  {
	  MakeSame();
	  }

var BadField;
var Result;
var Result2;
var rExp = /\Req_/gi;
var rExp2 = /<%|%>|<|>|\;|\&|\{|\}/gi;
var rExp3 = /\_/gi;
var newString = new String ("");
var newString2 = new String (" ");

        if (theForm.Req_Billing_Name.value == '')	{
	alert("Please enter your billing name.");
	theForm.Req_Billing_Name.focus();
	return false;
	}
	
        if (theForm.Req_Billing_Address.value == '')	{
	alert("Please enter your billing address.");
	theForm.Req_Billing_Address.focus();
	return false;
	}	
	
        if (theForm.Req_Billing_City.value == '')	{
	alert("Please enter your billing city.");
	theForm.Req_Billing_City.focus();
	return false;
	}	
	
        if (theForm.Billing_State.selectedIndex <= 0)	{
	alert("Please select or enter your billing province.");
	theForm.Billing_State.focus();
	return false;
	}	
	
        if (theForm.Req_Billing_Zip.value == '')	{
	alert("Please enter your billing postal code.");
	theForm.Req_Billing_Zip.focus();
	return false;
	}	

        if (theForm.Billing_Country.selectedIndex <= 0)	{
	alert("Please select your billing country.");
	theForm.Billing_Country.focus();
	return false;
	}
	
        if (theForm.Req_Billing_Phone.value == '')	{
	alert("Please enter your billing phone number.");
	theForm.Req_Billing_Phone.focus();
	return false;
	}	

	var foundAt = theForm.Req_Billing_Email.value.indexOf("@",0);
  	var foundDot = theForm.Req_Billing_Email.value.indexOf(".",0);
  	if (foundAt == -1 || foundDot == -1)  	{
    	alert("Your email address is invalid please fix it.");
    	theForm.Req_Billing_Email.focus();
    	return false;
  	}

        if (theForm.Req_Shipping_Name.value == '')	{
	alert("Please enter your shipping name.");
	theForm.Req_Shipping_Name.focus();
	return false;
	}
	
        if (theForm.Req_Shipping_Address.value == '')	{
	alert("Please enter your shipping address.");
	theForm.Req_Shipping_Address.focus();
	return false;
	}	
	
        if (theForm.Req_Shipping_City.value == '')	{
	alert("Please enter your shipping city.");
	theForm.Req_Shipping_City.focus();
	return false;
	}	
	
        if (theForm.Shipping_State.selectedIndex <= 0)	{
	alert("Please select or enter your shipping province.");
	theForm.Shipping_State.focus();
	return false;
	}	
	
        if (theForm.Req_Shipping_Zip.value == '')	{
	alert("Please enter your shipping postal code.");
	theForm.Req_Shipping_Zip.focus();
	return false;
	}	

        if (theForm.Shipping_Country.selectedIndex <= 0)	{
	alert("Please select your shipping country.");
	theForm.Shipping_Country.focus();
	return false;
	}
	
        if (theForm.Req_Shipping_Phone.value == '')	{
	alert("Please enter your shipping phone number.");
	theForm.Req_Shipping_Phone.focus();
	return false;
	}	

	var foundAt = theForm.Req_Shipping_Email.value.indexOf("@",0);
  	var foundDot = theForm.Req_Shipping_Email.value.indexOf(".",0);
  	if (foundAt == -1 || foundDot == -1)  	{
    	alert("Your email address is invalid please fix it.");
    	theForm.Req_Shipping_Email.focus();
    	return false;
  	}
  	
  	return true;
  	}

clickme = new Image();
clickme.src = "https://www.iias.com/canadaladder/images/processing.gif";

function hiLite(imgDocID,imgObjName) {
 if (document.images !=null)	{
   document.images[imgDocID].src = eval(imgObjName + ".src")
  }
}

function submitForm() {
OK = CheckForm2(document.InfoForm);
	if(OK == true) {
		document.InfoForm.submit();
	}
}
