
var _DEBUD_MODE_AJAX_L = false;

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function IncludeJS(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></script>'); 
}

///drag code
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

/// product validation

function goTo(URL){
	window.location = URL;
}

function val(bi,oh,obj) {
	if (oh < 0) { oh = 0; }
	thisForm = eval('document.Form_' + bi);
	thisQty = thisForm.Quantity.value;
	if(thisQty > oh){
		if(confirm('Please note we have a quantity of ' + oh + ' in stock at present.\n\nIf you want to add this item to your cart press OK.\n\nOtherwise, press Cancel to change the quantity or to remove the item from your order.')){
			//obj.value = oh;
			thisForm.submit();
		}
		else{
			obj.value = obj.title;
			clearInterval('flashingButton');
		}
	}
	else{
		thisForm.submit();
	}
}

var myButtonFirstRun = 0;
function validateNumber(obj,basId){
	if(isNaN(obj.value)){
		obj.value = '';
	}
	/*else{
		if(myButtonFirstRun == 0){
			myButtonFirstRun = 1;
			flashButton(basId,obj)
		}
		obj.id = obj.value;
	}*/
}

//myButton.focus();

var myButtonState = 0;
function highLightUpdate(basId){
	myButton = eval('document.Form_' + basId + '.update' + basId);
	currentColor = myButton.style.backgroundColor;
	if(myButtonState == 0){
		myButton.style.backgroundColor = '#bdff41';
		myButtonState = 1;
	}
	else{
		myButton.style.backgroundColor = '#ffffff';
		myButtonState = 0;
	}
}

var flashingButton;
var alertCheckout = 0;
function flashButton(basId,obj){
	newValue = obj.value;
	oldValue = obj.id;
	if(newValue != oldValue){
		flashingButton = window.setInterval('highLightUpdate(' + basId + ')', 500);
		alertCheckout = 1;
	}
}

///////////////////////////////////////////////////////

if(window.Event && document.captureEvents)
	document.captureEvents(Event.MOUSEMOVE);
	
document.onmousemove = getMousePos;

var mouseX, mouseY;

function getMousePos(e)
{
if (!e)
var e = window.event||window.Event;

if('undefined'!=typeof e.pageX)
{
mouseX = e.pageX;
mouseY = e.pageY;
}
else
{


	if (document.documentElement.scrollLeft == null)
	{
		mouseX = e.clientX + document.documentElement.scrollLeft;
		mouseY = e.clientY + document.documentElement.scrollTop;
	}
	else
	{
		if (document.body != null)
		{
			mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
		}
		
	}



 
}

}

function getPosition(e) {
    e = e || window.event || window.Event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	
    return cursor;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

///////////////////////////////////////////////////////

function cs_val(){
	var cs_msg = 'Please provide the following information:\n\n';
	if(document.csForm.cs_fname.value == ''){
		cs_msg = cs_msg + '- Your First Name\n';
		cs_stop = 1;
	}
	if(document.csForm.cs_lname.value == ''){
		cs_msg = cs_msg + '- Your Last Name\n';
		cs_stop = 1;
	}
	if(document.csForm.cs_cemail.value == ''){
		cs_msg = cs_msg + '- Your Email Address\n';
		cs_stop = 1;
	}
	var cs_stop = 0;
	if(((document.csForm.cs_subjectList.selectedIndex == 0) || (document.csForm.cs_subjectList[document.csForm.cs_subjectList.selectedIndex].value == 'Other')) && (document.csForm.cs_other.value == '')){
		cs_msg = cs_msg + '- Subject\n';
		cs_stop = 1;
	}
	if(document.csForm.cs_details.value == ''){
		cs_msg = cs_msg + '- Details\n';
		cs_stop = 1;
	}

	if(cs_stop == 1){
		alert(cs_msg);
		return;
	}
	document.csForm.cs_subject.value = document.csForm.cs_subjectList[document.csForm.cs_subjectList.selectedIndex].value + ' ' + document.csForm.cs_other.value;
	document.csForm.cs_button.disabled = true;
	document.csForm.cs_button.value = '- Sending Your Message -';
	document.csForm.submit();
}

function postMailToFriend(){
	tEmail = document.sendToFriend.tEmail.value;
	yEmail = document.sendToFriend.yEmail.value;
	yName = document.sendToFriend.yName.value;
	friendMessage = document.sendToFriend.friendMessage.value;
	proid = document.sendToFriend.proid.value;
	if((tEmail!='') && (yEmail!='')){
		//mailToFriend = new Image();
		//mailToFriend.src= globalFilePath + 'tellAFriend.taf?tEmail=' + tEmail + '&yEmail=' + yEmail + '&yName=' + yName + '&friendMessage=' + friendMessage + '&proid=' + proid + '&' + globalUserKey;
		var url = globalFilePath + 'tellAFriend.taf?tEmail=' + tEmail + '&yEmail=' + yEmail + '&yName=' + yName + '&friendMessage=' + encodeURI(friendMessage) + '&proid=' + proid + '&' + globalUserKey;
		tellafriendAjax(url);
	}
}

function tellafriendAjax(url){
    document.sendToFriend.bttnSendAFriend.value = "Sending...";
	document.sendToFriend.bttnSendAFriend.disabled = true;

	var xmlhttp = null;
	//var moment = new Date();
	//ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	if (window.XMLHttpRequest){ 
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	try {
		xmlhttp.open('POST',url,true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					ShowDebugAjaxL(xmlhttp,url,'');
      				document.sendToFriend.bttnSendAFriend.value = "Send Message";
 					document.sendToFriend.bttnSendAFriend.disabled = false;
					if(xmlhttp.responseText=='OK'){
						alert('Your message has been sent');
					}else{
						alert('Sorry, failed to send email');
					}
				}
			}
		}
		xmlhttp.send('');
	}
	catch(e) {
		//alert(e)
		alert('Sorry, failed to send email.');
	}
}


function swapTdBgColor(obj,color){
	obj.style.backgroundColor = color;
}

function goToURL(cmd,sec){
	//globalSecureFileName
	var gukey;
	if (globalUserKey == '')
		gukey = '';
	else
		gukey = '&' + globalUserKey;

	if((cmd == 'myAccount') || (cmd == 'checkout')){
		document.location.href = globalSecureFileName + '?cmd=' + cmd + '&sec=' + sec + gukey;
	}
	else{
		document.location.href = globalFileName + '?cmd=' + cmd + '&sec=' + sec + gukey;
		/*
		var str = globalWSFile + '/cmd/' + cmd;
		if (sec != '')
			str += '/sec/' + sec + '/' + sec + '.htm';
		else
			str += '/' + cmd + '.htm';
		document.location.href = str;
		*/
	}
}

function launchComponent(cmd)
{
	var comp = '';
	//if(cmd == 'companyManager')
		//comp = 'Components/companyManager/companyManager.taf';
	comp = 'Components/' + cmd + '/' + cmd + '.taf';

	if (comp != '')
	{
		if(navigator.appName == "Netscape")
		{
			window.open(comp, 'companyManager','chrome,centerscreen,dependent=YES,dialog=YES,modal=YES,resizable=NO,scrollbars=NO,location=0,status=0,menubar=0,toolbar=0,width=835,height=570');
		}
		else if(navigator.appName == "Microsoft Internet Explorer")
		{
			window.showModalDialog(comp,"name","dialogWidth:835px;dialogHeight:580px");
		}
	}
}

function default_goTo(gid1,gid2){
	document.location.href = globalFileName + '?gid=' + gid1 + '&gid=' + gid2 + '&' + globalUserKey;
}

function goToPidPage(gid){
		document.location.href = globalFileName + '?gid=' + gid + '&' + globalUserKey;
}

function viewOtherFilters(sDiv){
	var ie5=document.all && !window.opera
	var ns6=document.getElementById
	try
	{
		sourceDiv=ie5? eval('document.all.' + sDiv) : eval('document.getElementById("' + sDiv + '")')
		destinationDiv=ie5? document.all.FilterBox : document.getElementById("FilterBox");
		destinationDiv.innerHTML = sourceDiv.innerHTML;
	}
	catch (ex)
	{
	}
}

function postSignup(){
	formEmail = document.signupForm.signupEmail.value;
	if(formEmail!='' && formEmail!='your email address'){
		tricky = new Image();
		tricky.src= globalFilePath + 'signupForm.taf?pid=' + globalPID + '&psid=' + globalPSID + '&email=' + formEmail;
		alert('Thank you, we have received your email address.');
	}
}

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=3000;
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";
	}
}

function Blink(layerName){
	if (NS4 || IE4){ 
		if(i%2==0){
			eval(layerRef+'["'+layerName+'"]'+
			styleSwitch+'.visibility="visible"');
			blink_speed=1000;
		}
		else{
			eval(layerRef+'["'+layerName+'"]'+
			styleSwitch+'.visibility="hidden"');
			blink_speed=200;
		}
	}
	if(i<1){
		i++;
	} 
	else{
		i--
	}
	setTimeout("Blink('"+layerName+"')",blink_speed);
}

function valLogin() {
	if ((document.login.username.value != '') && (document.login.password.value != '')) {
		document.login.submit();
		document.login.login.disabled = true;
	}
	else{
		alert("Please complete the required information to login.");
	}
}

function valForgot() {
	if (document.forgot.email.value != '') {
		document.forgot.submit();
		document.forgot.emailpassword.disabled = true;
	}
	else{
		alert("Please enter your email address to proceed.");
	}
}

function valRegistration(){
	if(	(document.registerForm.nfn.value == '') ||
			(document.registerForm.nln.value == '') ||
			(document.registerForm.nem.value == '') ||
			(document.registerForm.npw.value == '') //||
			//(document.registerForm.Reff.selectedIndex == 0)
		){
		alert('You must complete all required information.');
		return false;
	}
	
	
	//document.registerForm.submit();
	//document.registerForm.button.disabled = true;
	return true;
}
function fCheck(n,p) {
	n= new String(n);
	t=new String();
	k=new String();
   phn = '';   
	if(p == 0){
		phn = 'billing';
	}else{
		phn = 'shipping';
	}
	for (i=0;i<n.length;i++)
		{
			k=String("1234567890").indexOf(n.substring(i,i+1));
			if (k!=-1){		
				t=t+n.substring(i,i+1);
			}
	}
	if(t.length<10){
		alert("The "+phn+" phone number must be at least 10 digits.");
		return false;
	}else{
		return true;
	}
}



function loadDefaults(){
	var states = document.addressForm.bstateId.length;
	var bcntry = document.addressForm.bCountryId.length;
	var country; var stateId;
	if(document.addressForm.bAddList.selectedIndex != 0){
		var bPos = document.addressForm.bAddList.selectedIndex;
		document.addressForm.bcompany.value = document.addressForm.hbCompany[bPos].value;
		document.addressForm.badd1.value = document.addressForm.hbAdd1[bPos].value;
		document.addressForm.badd2.value = document.addressForm.hbAdd2[bPos].value;
		document.addressForm.bcity.value = document.addressForm.hbCity[bPos].value;
		document.addressForm.bzip.value = document.addressForm.hbZip[bPos].value;
		document.addressForm.btel.value = document.addressForm.hbTel[bPos].value;		
		document.addressForm.btele.value = document.addressForm.hbTele[bPos].value;
		document.addressForm.bfax.value = document.addressForm.hbFax[bPos].value;
		document.addressForm.bfname.value = document.addressForm.hbContactFName[bPos].value;
		document.addressForm.blname.value = document.addressForm.hbContactLName[bPos].value;
		document.addressForm.bemail.value = document.addressForm.hbContactEmail[bPos].value;

		country = document.addressForm.hbcntry[bPos].value;
		stateId = document.addressForm.hbStateID[bPos].value;
		document.addressForm.bCountryId.value = country;
		Checkout_PopulateStatesList(country,stateId,'Billing');

	}
	if(document.addressForm.sAddList.selectedIndex != 0){
		var sPos = document.addressForm.sAddList.selectedIndex;
		document.addressForm.scompany.value = document.addressForm.hCompany[sPos].value;
		document.addressForm.sadd1.value = document.addressForm.hAdd1[sPos].value;
		document.addressForm.sadd2.value = document.addressForm.hAdd2[sPos].value;
		document.addressForm.scity.value = document.addressForm.hCity[sPos].value;
		document.addressForm.szip.value = document.addressForm.hZip[sPos].value;
		document.addressForm.stel.value = document.addressForm.hTel[sPos].value;
		document.addressForm.stele.value = document.addressForm.hTele[sPos].value;
		document.addressForm.sfax.value = document.addressForm.hFax[sPos].value;
		document.addressForm.sfname.value = document.addressForm.hContactFName[sPos].value;
		document.addressForm.slname.value = document.addressForm.hContactLName[sPos].value;
		document.addressForm.semail.value = document.addressForm.hContactEmail[sPos].value;
		/*if(document.addressForm.hIsAPO[sPos].value == 1){
			document.addressForm.sAPO.checked = true;
		}
		else{
			document.addressForm.sAPO.checked = false;		
		}
		if(document.addressForm.hBusiness[sPos].value == 1){
			document.addressForm.sBusiness.checked = true;
		}
		else{
			document.addressForm.sBusiness.checked = false;		
		}

		if(document.addressForm.hPOBox[sPos].value == 1){
			document.addressForm.sPOBox.checked = true;
		}
		else{
			document.addressForm.sPOBox.checked = false;		
		}*/

		country =  document.addressForm.hcntry[sPos].value;
		stateId = document.addressForm.hStateID[sPos].value;
		document.addressForm.sCountryId.value = country;
		Checkout_PopulateStatesList(country,stateId,'Shipping');
	}
}
function swapValues(v,n){
	var states = document.addressForm.bstateId.length;
	var bcntry = document.addressForm.bCountryId.length;
	var country; var stateId;
	if((n == 1) && (v == 1)){
		document.addressForm.bAddList.selectedIndex = 0;
	}
	if((n == 1) && (v == 0)){
		document.addressForm.sAddList.selectedIndex = 0;
	}
	if(v == 1){
		if(document.addressForm.bAddList.selectedIndex != 0){
			var bPos = document.addressForm.bAddList.selectedIndex;
			document.addressForm.bcompany.value = document.addressForm.hbCompany[bPos].value;
			document.addressForm.badd1.value = document.addressForm.hbAdd1[bPos].value;
			document.addressForm.badd2.value = document.addressForm.hbAdd2[bPos].value;
			document.addressForm.bcity.value = document.addressForm.hbCity[bPos].value;
			document.addressForm.bzip.value = document.addressForm.hbZip[bPos].value;
			document.addressForm.btel.value = document.addressForm.hbTel[bPos].value;
			document.addressForm.btele.value = document.addressForm.hbTele[bPos].value;
			document.addressForm.bfax.value = document.addressForm.hbFax[bPos].value;
			document.addressForm.bfname.value = document.addressForm.hbContactFName[bPos].value;
			document.addressForm.blname.value = document.addressForm.hbContactLName[bPos].value;
			document.addressForm.bemail.value = document.addressForm.hbContactEmail[bPos].value;
			
			country = document.addressForm.hbcntry[bPos].value;
			stateId = document.addressForm.hbStateID[bPos].value;
			document.addressForm.bCountryId.value = country;
			Checkout_PopulateStatesList(country,stateId,'Billing');
		}
		else{
			document.addressForm.bcompany.value = '';
			document.addressForm.badd1.value = '';
			document.addressForm.badd2.value = '';
			document.addressForm.bcity.value = '';
			document.addressForm.bzip.value = '';
			document.addressForm.btel.value = '';
			document.addressForm.btele.value = '';
			document.addressForm.bfax.value = '';
			document.addressForm.bfname.value = '';
			document.addressForm.blname.value = '';
			document.addressForm.bemail.value = '';
			document.addressForm.bCountryId.value = '';
			Checkout_PopulateStatesList('','','Billing');
			//document.addressForm.bAPO.checked = false;	
		}
	}
	else{
		if(document.addressForm.sAddList.selectedIndex != 0){
			var sPos = document.addressForm.sAddList.selectedIndex;
			document.addressForm.scompany.value = document.addressForm.hCompany[sPos].value;
			document.addressForm.sadd1.value = document.addressForm.hAdd1[sPos].value;
			document.addressForm.sadd2.value = document.addressForm.hAdd2[sPos].value;
			document.addressForm.scity.value = document.addressForm.hCity[sPos].value;
			document.addressForm.szip.value = document.addressForm.hZip[sPos].value;
			document.addressForm.stel.value = document.addressForm.hTel[sPos].value;
			document.addressForm.stele.value = document.addressForm.hTele[sPos].value;
			document.addressForm.sfax.value = document.addressForm.hFax[sPos].value;
			document.addressForm.sfname.value = document.addressForm.hContactFName[sPos].value;
			document.addressForm.slname.value = document.addressForm.hContactLName[sPos].value;
			document.addressForm.semail.value = document.addressForm.hContactEmail[sPos].value;
			document.addressForm.sameAsBilling.checked = false;	

			/*if(document.addressForm.hIsAPO[sPos].value == 1){
				document.addressForm.sAPO.checked = true;
			}
			else{
				document.addressForm.sAPO.checked = false;		
			}
		if(document.addressForm.hBusiness[sPos].value == 1){
			document.addressForm.sBusiness.checked = true;
		}
		else{
			document.addressForm.sBusiness.checked = false;		
		}

		if(document.addressForm.hPOBox[sPos].value == 1){
			document.addressForm.sPOBox.checked = true;
		}
		else{
			document.addressForm.sPOBox.checked = false;		
		}*/
			
			country =  document.addressForm.hcntry[sPos].value;
			stateId = document.addressForm.hStateID[sPos].value;
			document.addressForm.sCountryId.value = country;
			Checkout_PopulateStatesList(country,stateId,'Shipping');
			
		}
		else{
			document.addressForm.scompany.value = '';
			document.addressForm.sadd1.value = '';
			document.addressForm.sadd2.value = '';
			document.addressForm.scity.value = '';
			document.addressForm.szip.value = '';
			document.addressForm.stel.value = '';
			document.addressForm.stele.value = '';
			document.addressForm.sfax.value = '';
			document.addressForm.sfname.value = '';
			document.addressForm.slname.value = '';
			document.addressForm.semail.value = '';
			document.addressForm.sameAsBilling.checked = false;
			document.addressForm.sCountryId.value = '';
			Checkout_PopulateStatesList('','','Shipping');
			//document.addressForm.sAPO.checked = false;	
		}	
	}
}

function swapBillingInfoTypes(billType){
	if(billType=='spending'){
		document.addressForm.bAddList.selectedIndex = 0;
		document.addressForm.bAddList.disabled = true;
		document.addressForm.spendAccountId.disabled = false;
		document.getElementById("trCopyBillingInfo").style.display = 'none';
		EnableDisableAddressFileds('billing',false);
	}
	if(billType=='private'){
		document.addressForm.spendAccountId.selectedIndex = 0;
		document.addressForm.bAddList.disabled = false;
		document.addressForm.spendAccountId.disabled = true;
		document.getElementById("trCopyBillingInfo").style.display = '';
		EnableDisableAddressFileds('billing',true);
	}
	resetAddressFileds('billing');
}

function swapValuesSpending(){
	var states = document.addressForm.bstateId.length;
	var bcntry = document.addressForm.bCountryId.length;
	var country; var stateId;
	if(document.addressForm.spendAccountId.selectedIndex != 0){
		var bPos = document.addressForm.spendAccountId.selectedIndex;
		document.addressForm.bcompany.value = document.addressForm.hspCompany[bPos].value;
		document.addressForm.badd1.value = document.addressForm.hspAdd1[bPos].value;
		document.addressForm.badd2.value = document.addressForm.hspAdd2[bPos].value;
		document.addressForm.bcity.value = document.addressForm.hspCity[bPos].value;
		document.addressForm.bzip.value = document.addressForm.hspZip[bPos].value;
		document.addressForm.btel.value = document.addressForm.hspTel[bPos].value;
		document.addressForm.btele.value = document.addressForm.hspTele[bPos].value;
		document.addressForm.bfax.value = document.addressForm.hspFax[bPos].value;
		document.addressForm.bfname.value = document.addressForm.hspContactFName[bPos].value;
		document.addressForm.blname.value = document.addressForm.hspContactLName[bPos].value;
		document.addressForm.bemail.value = document.addressForm.hspContactEmail[bPos].value;
		
		country =  document.addressForm.hspcntry[bPos].value;
		stateId = document.addressForm.hspStateID[bPos].value;
		document.addressForm.bCountryId.value = country;
		Checkout_PopulateStatesList(country,stateId,'Billing');
	}
	else{
		resetAddressFileds('billing');	
	}
}

function isSpendAcc(){
	var retVal = false;
    if(document.addressForm.billingType!=null){
		if(document.addressForm.billingType[0].checked){
			retVal = true;
		}
	}
	return retVal;
}

function disableBox(obj){
	var retVal = false;
	if(isSpendAcc()){
		obj.blur();
	}else{
		retVal = true;
	}
	return retVal;
}

function ClearFileds(addressType){
	window.location.reload();
}

function resetAddressFileds(addressType){
	if(addressType=='billing'){
		document.addressForm.bAddList.selectedIndex = 0;
		document.addressForm.bcompany.value = '';
		document.addressForm.badd1.value = '';
		document.addressForm.badd2.value = '';
		document.addressForm.bcity.value = '';
		document.addressForm.bzip.value = '';
		document.addressForm.btel.value = '';
		document.addressForm.btele.value = '';
		document.addressForm.bfax.value = '';
		document.addressForm.bfname.value = '';
		document.addressForm.blname.value = '';
		document.addressForm.bemail.value = '';
		document.addressForm.bCountryId.value = '';
		Checkout_PopulateStatesList('','','Billing');
		//document.addressForm.bAPO.checked = false;
	}
}

function EnableDisableAddressFileds(addressType,blnEnable){
	var blnDisable = false;
	if (blnEnable == false) blnDisable = true;
	if(addressType=='billing'){
		document.addressForm.bAddList.disabled = blnDisable;
		document.addressForm.bcompany.disabled = blnDisable;
		document.addressForm.badd1.disabled = blnDisable;
		document.addressForm.badd2.disabled = blnDisable;
		document.addressForm.bcity.disabled = blnDisable;
		document.addressForm.bzip.disabled = blnDisable;
		document.addressForm.btel.disabled = blnDisable;
		document.addressForm.btele.disabled = blnDisable;
		document.addressForm.bfax.disabled = blnDisable;
		document.addressForm.bfname.disabled = blnDisable;
		document.addressForm.blname.disabled = blnDisable;
		document.addressForm.bemail.disabled = blnDisable;
		document.addressForm.bsave.disabled = blnDisable;
		document.addressForm.bCountryId.disabled = blnDisable;
		$('td_bCountryId').disabled = blnDisable;
		$('td_bstateId').disabled = blnDisable;
	}
}

function backupPost(uk,file){
	if(_DEBUD_MODE_AJAX_L) return;
	window.clearTimeout(formTimeout);
	xmlhttp = '';
	//alert('backupFired');
	//moment = new Date();
	//ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	document.ccForm.method = 'POST';
	document.ccForm.action = file + 'orderBackup.taf?' + uk;
	//+ '&ts=' + ts;
	document.ccForm.submit();
}

function testPost(uk,file){
	document.ccForm.method = 'POST';
	document.ccForm.action = file + 'orderProcess.taf?' + uk;
	document.ccForm.submit();
}

function ShowDebugAjaxL(http_request,requestUrl,strPostParams){
	 //return;
	if (!_DEBUD_MODE_AJAX_L) return;
	
	var wDebug = window.open("/scripts/ajaxDebugCC.html","fwDebug");
	wDebug.document.body.innerHTML = "";
	
	var now = new Date();
	var currentTime = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
	
	var strHTML = "<span style='font-family: Arial; font-size: 12px;'>";				
	strHTML+= currentTime + "<br>";	
	strHTML+="<b style='color:red'>Ajax Debug mode</b><br>";
	strHTML+="HTTP Status: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b style='color:red'>" + http_request.status + "</b><br>";
	strHTML+="Request URL: &nbsp;&nbsp;&nbsp;" +  requestUrl  + "<br>";
	//strHTML+="All Response Headers: " + _http_request.getAllResponseHeaders + "<br>";
	if(strPostParams.length>0){
	  strHTML+="Sended POST Parameters: &nbsp;&nbsp;" +  strPostParams  + "<br>";
	}
	strHTML+="<br>Response Text: <hr size=1>" +  http_request.responseText;
	strHTML+= "</span>";
	wDebug.document.body.innerHTML = strHTML;
	//wDebug.focus();
}	

var _strParams = '';
function submitForm(uk,file){
	//REMOVE HERE
	//testPost(uk,file);
	//return;
	//TO HERE

	var myForm = document.ccForm;
	var refString = '';
	var responseMessageDiv = document.getElementById("responseDIV");
	responseMessageDiv.innerHTML = '';
	moment = new Date();
	ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	myForm.orderButton.disabled = true;
	myForm.orderButton.value = 'processing order...';
	countDownClock = setInterval('countDown()',1000);
	formTimeout = window.setTimeout('backupPost(uk,file)',50000);

	if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else {
			//alert('error3');
			backupPost(uk,file);
			return;
	}
	try {
		postAddress = file + 'orderProcess.taf?ts=' + ts + '&' + uk;
		xmlhttp.open('POST',postAddress,true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					window.clearTimeout(formTimeout);
					ShowDebugAjaxL(xmlhttp,postAddress,_strParams);
					//alert(xmlhttp.responseText)
					var response = xmlhttp.responseText;
					var responsePart = response.substr(0,6);
					//alert('message="' + responsePart + '"')
					if(responsePart == 'FAILED'){
						clearInterval(countDownClock);
						currentSecond = 60;
						myForm.orderButton.disabled = false;
						myForm.orderButton.value = 'Click here to re-submit  your order';
						var responseArray = response.split('~');
						myForm.oNum.value = responseArray[1];
						responseMessageDiv.innerHTML = '<BR><span class="bigred">We were unable to process your card.<BR>The response given by the payment gateway is:<BR><BR>' + responseArray[2] + '</span>';
					}
					else{
						window.location = xmlhttp.responseText;
					}
				}
				else{
					//alert(xmlhttp.getAllResponseHeaders());
					//alert(postAddress);
					//alert('xmlhttp.readyState = ' + xmlhttp.readyState);
					//alert('xmlhttp.status = ' + xmlhttp.status);
					ShowDebugAjaxL(xmlhttp,postAddress,_strParams);
					backupPost(uk,file);
					return;
				}
			}
		}
			//xmlhttp.setRequestHeader("validKey","uk");
			for(i=1;i<=46;i++){
				thisElement = eval('document.getElementById("text' + i + '")')
				if(thisElement){
					thisElementName = thisElement.name;
					thisElementValue = thisElement.value;
					refString = refString + thisElementName + '=' + thisElementValue + '&';
				}
			}
			for(i=1;i<=5;i++){
				thisElement = eval('document.getElementById("select' + i + '")');
				if(thisElement){
					thisElementName = thisElement.name;
					thisElementValue = thisElement[thisElement.selectedIndex].value;
					refString = refString + thisElementName + '=' + thisElementValue + '&';
				}
			}
			thisElement = document.getElementById("checkbox1");
			if(thisElement){
				if(thisElement.checked == true){
					thisElementName = thisElement.name;
					thisElementValue = thisElement.value;
					refString = refString + thisElementName + '=' + thisElementValue;
				}
			}
		_strParams = refString;
		xmlhttp.send(refString);
	}
	catch (e) {
		backupPost(uk,file);
		return;
	}
	
}


var countDownClock;

var currentSecond = 60;
function countDown(){
	currentSecond--;
	if (currentSecond<0){
		clearInterval(countDownClock);
		currentSecond = 0;
	}
	if(currentSecond < 10){
		showZero = '0';
	}
	else{
		showZero = '';
	}
	myForm = document.ccForm;
	myForm.orderButton.value = 'processing order... 0:' + showZero + currentSecond; 
}

function clearValue(obj){
	if(obj.value == 'enter code') obj.value = '';
	else obj.select();
}
function setValue(obj){
	if(obj.value == '') obj.value = 'enter code';
}

function backupVerifyPost(){
	return;
}

function verifyItemReturn(myDiv,myButton,position,key,file){
	keycode = window.event.keyCode;
	if(keycode == 13){
		verifyItem(myDiv,myButton,position,key,file);
	}
}

function verifyItem(myDiv,myButton,position,key,file){
	
	var nextPosition = position * 1 + 1;
	var nextDIV = eval('document.getElementById("nav' + nextPosition + '")');
	var thisSKU = eval('document.getElementById("sku' + position + '")');
	var nextSKU = eval('document.getElementById("sku' + nextPosition + '")');
	var thisQTY = eval('document.getElementById("qty' + position + '")');
	var thisHint = eval('document.getElementById("hint' + position + '")');
	var myForm = document.quickForm;
	var refString = '';
	var location = file
	var responseMessageDiv = eval('document.getElementById("' + myDiv + '")');
	responseMessageDiv.innerHTML = '';
	moment = new Date();
	ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	//myButton.disabled = true;
	//myButton.value = 'verifying item ...';
	if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else {
		backupVerifyPost();
		return;
	}
	try {
		postAddress = location + 'itemVerify.taf?ts=' + ts + '&_UserReference=' + key;
		
		xmlhttp.open('POST',postAddress,true);
		xmlhttp.onreadystatechange = function(){
			
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					var response = xmlhttp.responseText;
					//myButton.disabled = false;
					//myButton.value = 'verify item';
					responseMessageDiv.innerHTML = response;
					if(response != 'item not found!'){
						nextDIV.className = 'visibleDIV';
						myButton.value = 'change';
						thisHint.src = 'images/ws_spacer.gif';
						nextSKU.focus();
					}
					else{
						myButton.value = 'try again';
					}
				}
				else{
					responseMessageDiv.innerHTML = 'unable to verify item' + xmlhttp.status;
					//backupVerifyPost();
					return;
				}
			}
		}
		thisSKUValue = thisSKU.value;
		thisQTYValue = thisQTY.value;
		if(thisSKUValue == '' || thisSKUValue == 'enter code'){
			//alert('invalid sku');
			//myButton.disabled = false;
			//myButton.value = 'verify item';
			return;
		}
		if(thisQTYValue == '' || isNaN(thisQTYValue) == true){
			alert('invalid quantity');
			thisQTY.value = 0;
			//myButton.disabled = false;
			//myButton.value = 'verify item';
			return;
		}
		else if(thisQTYValue == 0){
			//alert('invalid quantity');
			thisQTY.value = 0;
			thisSKU.value = '';
			//myButton.disabled = false;
			//myButton.value = 'verify item';
			return;
		}
		else{
			refString = 'itemSKU=' + thisSKUValue + '&itemQTY=' + thisQTYValue + '&pos=' + position;
		}
		xmlhttp.send(refString);
	}
	catch (e) {
		alert(e.message);
		return;
	}
	
}


function verifyItem2(myDiv,myButton,position,key,file){
	
	var nextPosition = position * 1 + 1;
	var nextDIV = eval('document.getElementById("nav' + nextPosition + '")');
	var thisSKU = eval('document.getElementById("OP")');
	var nextSKU = eval('document.getElementById("sku' + nextPosition + '")');
	var thisQTY = eval('document.getElementById("Quantity")');
	alert(thisQTY.value);
	var thisHint = eval('document.getElementById("hint' + position + '")');
	var myForm = document.quickForm;
	var refString = '';
	var location = file
	var responseMessageDiv = eval('document.getElementById("' + myDiv + '")');
	responseMessageDiv.innerHTML = '';
	moment = new Date();
	ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	//myButton.disabled = true;
	//myButton.value = 'verifying item ...';
	if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else {
		backupVerifyPost();
		return;
	}
	try {
		postAddress = location + 'itemVerify.taf?ts=' + ts + '&_UserReference=' + key;
		alert(postAddress);
		xmlhttp.open('POST',postAddress,true);
		xmlhttp.onreadystatechange = function(){
			
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					var response = xmlhttp.responseText;
					//myButton.disabled = false;
					//myButton.value = 'verify item';
					responseMessageDiv.innerHTML = response;
					if(response != 'item not found!'){
						nextDIV.className = 'visibleDIV';
						myButton.value = 'change';
						thisHint.src = 'images/ws_spacer.gif';
						nextSKU.focus();
					}
					else{
						myButton.value = 'try again';
					}
				}
				else{
					responseMessageDiv.innerHTML = 'unable to verify item' + xmlhttp.status;
					//backupVerifyPost();
					return;
				}
			}
		}
		thisSKUValue = thisSKU.value;
		thisQTYValue = thisQTY.value;
		if(thisSKUValue == '' || thisSKUValue == 'enter code'){
			//alert('invalid sku');
			//myButton.disabled = false;
			//myButton.value = 'verify item';
			return;
		}
		if(thisQTYValue == '' || isNaN(thisQTYValue) == true){
			alert('invalid quantity');
			thisQTY.value = 0;
			//myButton.disabled = false;
			//myButton.value = 'verify item';
			return;
		}
		else if(thisQTYValue == 0){
			//alert('invalid quantity');
			thisQTY.value = 0;
			thisSKU.value = '';
			//myButton.disabled = false;
			//myButton.value = 'verify item';
			return;
		}
		else{
			refString = 'itemSKU=' + thisSKUValue + '&itemQTY=' + thisQTYValue + '&pos=' + position;
		}
		xmlhttp.send(refString);
	}
	catch (e) {
		alert(e.message);
		return;
	}
	
}



function validateItems2(file,key){
	errorBlock = document.getElementById("errorMessage");
	errorBlock.innerHTML = "";
	var sendForm = 0;
	var stopForm = 0;
	myForm = document.quickForm;
	loopCount = myForm.selectId.length;
	if(loopCount == 'undefined'){
		loopCount = 0;
	}
	alert('select loop');
	for(i=0;i<loopCount-1;i++){
		var adjustedCount = i + 1;
		var selectedValue = eval("myForm.quantity" + adjustedCount + ".value");
		alert('selected value =' + selectedValue);
		if(selectedValue == 1){
			sendForm = 1;
			selectId = myForm.selectId[i].value;
			if(selectId != ''){
				alert('selectId = ' + selectId);
				thisSelect = document.getElementById(selectId);
				thisSelectSpan = document.getElementById("selectSpan_" + selectId);
				if(thisSelect.selectedIndex == 0){
					thisSelect.style.backgroundColor = "#FFFF00";
					thisSelectSpan.innerHTML = "&nbsp;&nbsp;<font color=red>* selection required</font>";
					stopForm = 1;
				}
				else{
					thisSelect.style.backgroundColor = "#FFFFFF";
					thisSelectSpan.innerHTML = "";
				}
			}
		}
	}
	loopCount = myForm.customId.length;
	if(loopCount == 'undefined'){
		loopCount = 0;
	}
	alert('custom loop');
	for(i=0;i<loopCount-1;i++){
		var adjustedCount = i + 1;
		var selectedValue = eval("myForm.quantity" + adjustedCount + ".value");
		alert('selected value =' + selectedValue);
		if(selectedValue == 1){
			customId = myForm.customId[i].value;
			if(customId != ''){
				alert('customId = ' + customId);
				thisCustom = document.getElementById("Custom" + customId);
				thisCustomLabel = document.getElementById("customLabel" + customId);
				thisCustomSpan = document.getElementById("customSpan" + customId);
				if((thisCustom.value == thisCustomLabel.value) || thisCustom.value == ''){
					thisCustom.style.backgroundColor = "#FFFF00";
					thisCustomSpan.innerHTML = "&nbsp;&nbsp;<font color=red>* entry required</font>";
					stopForm = 1;
				}
				else{
					thisCustom.style.backgroundColor = "#FFFFFF";
					thisCustomSpan.innerHTML = "";
				}
			}
		}
	}
	errorBlock = document.getElementById("errorMessage");
	sendForm = 1;
	if(stopForm == 1){
		errorBlock.innerHTML = "<BR><BR><font color=red><B>All required fields must be complete. Please review the error messages above.</b></font><BR><BR>"
	}
	else{
		if(sendForm == 1){
			errorBlock.innerHTML = "";
			myForm.method = 'POST';
			myForm.action = file + '?cmd=basket&fromPage=quickShop&_UserReference=' + key;
			myForm.submit();
		}
		else{
			errorBlock.innerHTML = "<BR><BR><font color=red><B>You must select one or more items to add to your shopping cart.</b></font><BR><BR>";
		}
	}
}

function stateKeep(key,file){
	myImage = document.getElementById("stateKeeper"); 
	moment = new Date();
	ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	myImage.src = file + '?_UserReference=' + key + '&ts=' + ts;
}

function showPage(which,where,key,file){
	swapImage = document.getElementById("bigPage");
	swapLink = 	document.getElementById("bigLink");
	newImage = 'images/catalogue/Page_' + which + '.jpg';
	swapImage.src = newImage;
	if(where > 0){
		newLink = file + '?gid=' + where + '&_UserReference=' + key;
	}
	else{
		newLink = '#';
	}
	swapLink.href = newLink;
}

function emailCheck (emailStr) {

var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)

if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    alert("The username doesn't seem to be valid.")
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

return true;
}

function checkCatalogFields() {        
	if ( (document.catalogForm.User_First_Name.value=="")  ||
		(document.catalogForm.User_Last_Name.value=="")  ||
		(document.catalogForm.Bill_Add1.value=="")  ||	
		(document.catalogForm.Bill_City.value=="")  ||			
		(document.catalogForm.Bill_Zip.value=="")   ||
		(document.catalogForm.email.value=="")   ||
		(document.catalogForm.Bill_Phone.value=="")   ||
		(document.catalogForm.Ref[document.catalogForm.Ref.selectedIndex].value == '')
		) 
	   {
	   alert("Please be sure to fill in all of the required fields.");
	   return false;
	   }
	
	else 
	   {
	      document.catalogForm.submit();
	   }
}

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_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];}
}

function processIt(){
	document.newsForm.button.disabled = true;
	document.newsForm.button.value = '- Processing -';
	document.newsForm.submit();
}
/* Already Exist
function valLogin() {
	if ((document.login.username.value != '') && (document.login.password.value != '')) {
		document.login.submit();
		document.login.button.disabled = true;
	}
	else{
		alert("Please complete the required information to login.");
	}
}*/
/* Already Exist
function valForgot() {
	if (document.forgot.email.value != '') {
		document.forgot.submit();
		document.forgot.button.disabled = true;
	}
	else{
		alert("Please enter your email address to proceed.");
	}
}*/
/* Already Exist
function valRegistration(){
	if(	(document.registerForm.nfn.value == '') ||
			(document.registerForm.nln.value == '') ||
			(document.registerForm.nem.value == '') ||
			(document.registerForm.npw.value == '') ||
			(document.registerForm.Reff.selectedIndex == 0)){
		alert('You must complete all required information.');
		return false;
	}
	
	
	//document.registerForm.submit();
	//document.registerForm.button.disabled = true;
	return true;
}*/
/*
function fCheck(n,p) {
	n= new String(n);
	t=new String();
	k=new String();
   phn = '';   
	if(p == 0){
		phn = 'billing';
	}else{
		phn = 'shipping';
	}
	for (i=0;i<n.length;i++)
		{
			k=String("1234567890").indexOf(n.substring(i,i+1));
			if (k!=-1){		
				t=t+n.substring(i,i+1);
			}
	}
	if(t.length<10){
		alert("The "+phn+" phone number must be at least 10 digits.");
		return false;
	}else{
		return true;
	}
}
*/

/*
function loadDefaults(){
	var states = document.addressForm.bstateId.length;
	var bcntry = document.addressForm.bCountryId.length;
	if(document.addressForm.bAddList.selectedIndex != 0){
		var bPos = document.addressForm.bAddList.selectedIndex;
		document.addressForm.bcompany.value = document.addressForm.hCompany[bPos].value;
		document.addressForm.badd1.value = document.addressForm.hAdd1[bPos].value;
		document.addressForm.badd2.value = document.addressForm.hAdd2[bPos].value;
		document.addressForm.bcity.value = document.addressForm.hCity[bPos].value;
		document.addressForm.bzip.value = document.addressForm.hZip[bPos].value;
		document.addressForm.btel.value = document.addressForm.hTel[bPos].value;		
		document.addressForm.btele.value = document.addressForm.hTele[bPos].value;
		document.addressForm.bfax.value = document.addressForm.hFax[bPos].value;
		document.addressForm.bfname.value = document.addressForm.hContactFName[bPos].value;
		document.addressForm.blname.value = document.addressForm.hContactLName[bPos].value;
		document.addressForm.bemail.value = document.addressForm.hContactEmail[bPos].value;
		for(i=0;i<states;i++){
			if(document.addressForm.bstateId[i].value == document.addressForm.hStateID[bPos].value){
				document.addressForm.bstateId.selectedIndex = i;
			}
		}
		for(b=0;b<bcntry;b++){
			if(document.addressForm.bCountryId[b].value == document.addressForm.hcntry[bPos].value){
				document.addressForm.bCountryId.selectedIndex = b;			
			}
		}
	}
	if(document.addressForm.sAddList.selectedIndex != 0){
		var sPos = document.addressForm.sAddList.selectedIndex;
		document.addressForm.scompany.value = document.addressForm.hCompany[sPos].value;
		document.addressForm.sadd1.value = document.addressForm.hAdd1[sPos].value;
		document.addressForm.sadd2.value = document.addressForm.hAdd2[sPos].value;
		document.addressForm.scity.value = document.addressForm.hCity[sPos].value;
		document.addressForm.szip.value = document.addressForm.hZip[sPos].value;
		document.addressForm.stel.value = document.addressForm.hTel[sPos].value;
		document.addressForm.stele.value = document.addressForm.hTele[sPos].value;
		document.addressForm.sfax.value = document.addressForm.hFax[sPos].value;
		document.addressForm.sfname.value = document.addressForm.hContactFName[sPos].value;
		document.addressForm.slname.value = document.addressForm.hContactLName[sPos].value;
		document.addressForm.semail.value = document.addressForm.hContactEmail[sPos].value;

		/*if(document.addressForm.hIsAPO[sPos].value == 1){
			document.addressForm.sAPO.checked = true;
		}
		else{
			document.addressForm.sAPO.checked = false;		
		}
		if(document.addressForm.hBusiness[sPos].value == 1){
			document.addressForm.sBusiness.checked = true;
		}
		else{
			document.addressForm.sBusiness.checked = false;		
		}

		if(document.addressForm.hPOBox[sPos].value == 1){
			document.addressForm.sPOBox.checked = true;
		}
		else{
			document.addressForm.sPOBox.checked = false;		
		}*/

	/*	for(i=0;i<states;i++){
			if(document.addressForm.sstateId[i].value == document.addressForm.hStateID[sPos].value){
				document.addressForm.sstateId.selectedIndex = i;
			}
		}
	}
}
*/

/*

function swapValues(v,n){
	var states = document.addressForm.bstateId.length;
	var bcntry = document.addressForm.bCountryId.length;
	if((n == 1) && (v == 1)){
		document.addressForm.bAddList.selectedIndex = 0;
	}
	if((n == 1) && (v == 0)){
		document.addressForm.sAddList.selectedIndex = 0;
	}
	if(v == 1){
		if(document.addressForm.bAddList.selectedIndex != 0){
			var bPos = document.addressForm.bAddList.selectedIndex;
			document.addressForm.bcompany.value = document.addressForm.hCompany[bPos].value;
			document.addressForm.badd1.value = document.addressForm.hAdd1[bPos].value;
			document.addressForm.badd2.value = document.addressForm.hAdd2[bPos].value;
			document.addressForm.bcity.value = document.addressForm.hCity[bPos].value;
			document.addressForm.bzip.value = document.addressForm.hZip[bPos].value;
			document.addressForm.btel.value = document.addressForm.hTel[bPos].value;
			document.addressForm.btele.value = document.addressForm.hTele[bPos].value;
			document.addressForm.bfax.value = document.addressForm.hFax[bPos].value;
			document.addressForm.bfname.value = document.addressForm.hContactFName[bPos].value;
			document.addressForm.blname.value = document.addressForm.hContactLName[bPos].value;
			document.addressForm.bemail.value = document.addressForm.hContactEmail[bPos].value;
			
			for(b=0;b<bcntry;b++){
				if(document.addressForm.bCountryId[b].value == document.addressForm.hcntry[bPos].value){
				document.addressForm.bCountryId.selectedIndex = b;
				
				}
		
			}
	
			for(i=0;i<states;i++){
				if(document.addressForm.bstateId[i].value == document.addressForm.hStateID[bPos].value){
					document.addressForm.bstateId.selectedIndex = i;
				}
			}
		}
		else{
			document.addressForm.bcompany.value = '';
			document.addressForm.badd1.value = '';
			document.addressForm.badd2.value = '';
			document.addressForm.bcity.value = '';
			document.addressForm.bzip.value = '';
			document.addressForm.btel.value = '';
			document.addressForm.btele.value = '';
			document.addressForm.bfax.value = '';
			document.addressForm.bfname.value = '';
			document.addressForm.blname.value = '';
			document.addressForm.bemail.value = '';
			document.addressForm.bstateId.selectedIndex = 0;
			//document.addressForm.bAPO.checked = false;	
		}
	}
	else{
		if(document.addressForm.sAddList.selectedIndex != 0){
			var sPos = document.addressForm.sAddList.selectedIndex;

			document.addressForm.scompany.value = document.addressForm.hCompany[sPos].value;
			document.addressForm.sadd1.value = document.addressForm.hAdd1[sPos].value;
			document.addressForm.sadd2.value = document.addressForm.hAdd2[sPos].value;
			document.addressForm.scity.value = document.addressForm.hCity[sPos].value;
			document.addressForm.szip.value = document.addressForm.hZip[sPos].value;
			document.addressForm.stel.value = document.addressForm.hTel[sPos].value;
			document.addressForm.stele.value = document.addressForm.hTele[sPos].value;
			document.addressForm.sfax.value = document.addressForm.hFax[sPos].value;
			document.addressForm.sfname.value = document.addressForm.hContactFName[sPos].value;
			document.addressForm.slname.value = document.addressForm.hContactLName[sPos].value;
			document.addressForm.semail.value = document.addressForm.hContactEmail[sPos].value;
			document.addressForm.sameAsBilling.checked = false;	

			/*if(document.addressForm.hIsAPO[sPos].value == 1){
				document.addressForm.sAPO.checked = true;
			}
			else{
				document.addressForm.sAPO.checked = false;		
			}
		if(document.addressForm.hBusiness[sPos].value == 1){
			document.addressForm.sBusiness.checked = true;
		}
		else{
			document.addressForm.sBusiness.checked = false;		
		}

		if(document.addressForm.hPOBox[sPos].value == 1){
			document.addressForm.sPOBox.checked = true;
		}
		else{
			document.addressForm.sPOBox.checked = false;		
		}*/

	/*
			for(i=0;i<states;i++){
				if(document.addressForm.sstateId[i].value == document.addressForm.hStateID[sPos].value){
					document.addressForm.sstateId.selectedIndex = i;
				}
			}
		}
		else{
			document.addressForm.scompany.value = '';
			document.addressForm.sadd1.value = '';
			document.addressForm.sadd2.value = '';
			document.addressForm.scity.value = '';
			document.addressForm.szip.value = '';
			document.addressForm.stel.value = '';
			document.addressForm.stele.value = '';
			document.addressForm.sfax.value = '';
			document.addressForm.sfname.value = '';
			document.addressForm.slname.value = '';
			document.addressForm.semail.value = '';
			document.addressForm.sstateId.selectedIndex = 0;
			document.addressForm.sameAsBilling.checked = false;
			//document.addressForm.sAPO.checked = false;	
		}	
	}
}*/

function valAddressForm(){
	if ((document.account.fname.value == '') || (document.account.lname.value == '') || (document.account.emailaddress.value == '')){
		alert('Please complete all required fields.');
		return;
	}
	if (document.account.pw.value == ''){
		alert('You must enter your current password to update your account settings.');
		document.account.fname.focus();
		document.account.pw.focus();
		return;
	}
	if (document.account.pw2.value != document.account.pw3.value){
		alert('The new password does not match the confirmation password.');
		document.account.fname.focus();
		document.account.pw3.select();
		return;
	}
	document.account.process.disabled = true;
	document.account.process.value = '- Processing -';
	document.account.submit();
}

function enlarge(which,type,size){
var ie=document.all
var ns6=document.getElementById&&!document.all
if(type == 2){
	var newHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' +size+ '" height="' +size+ '" id="MMag" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' +which+ '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="' +which+ '" quality="high" bgcolor="#ffffff" width="' +size+ '" height="' +size+ '" name="MMag" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
}
else{
	var newHTML = '<img src="' +which+ '" width="' +size+ '" height="' +size+ '" border="0">'
}

	if (ie||ns6){
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		crossobj.innerHTML=newHTML;
		crossobj.style.visibility="visible"
	return false
	}
	else {
		return true;
	}
}

function closepreview()
{
	crossobj.style.visibility="hidden"
}

function checkLength(obj,maxLength){
	displayLength = maxLength;
	maxLength = maxLength - 1;
	curValue = obj.value;
	curLen = obj.value.length;
	if(curLen > maxLength){
		obj.value = curValue.substr(0,maxLength);
		alert('Unfortunately we can only accept a maximum of ' + displayLength + ' characters\n(including spaces) for gift messages.');
	}
}

function doIsReminder(userKey){
	//alert('go1');
	var responseMessageDiv = document.getElementById("inStockReminderDiv");
	moment = new Date();
	ts = moment.getHours() + '-' + moment.getMinutes() + '-' + moment.getSeconds() + '-' + moment.getMilliseconds();
	if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else {
		responseMessageDiv.innerHTML = 'Sorry, our reminder service is currently unavailable.';
		return;
	}
	//alert('ok');
	try {
		postAddress = globalFilePath + 'inStockReminder.taf?ts=' + ts + '&_UserReference=' + userKey;
		//alert(postAddress);
		xmlhttp.open('POST',postAddress,true);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				//alert(xmlhttp.status);
				if(xmlhttp.status == 200){
					//alert('success');
					var response = xmlhttp.responseText;
					responseMessageDiv.innerHTML = response;
				}
				else{
					//alert('fail');
					responseMessageDiv.innerHTML = 'Sorry, our reminder service is currently unavailable.';
					return;
				}
			}
		}
		//alert('gonna send');
		pid = document.productForm.inStockReminderPID.value;
		email = document.productForm.inStockReminderEmail.value;
		refString = 'inStockReminderPID=' + pid + '&inStockReminderEmail=' + email;
		//alert(refString);
		xmlhttp.send(refString);
	}
	catch(e) {
		//alert('error');
		responseMessageDiv.innerHTML = 'Sorry, our reminder service is currently unavailable.';
		return;
	}
	
}




//Added March 20, 2007, by Alec
//========================================================================================================
// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

/*
country => country abbreviation
the function returns boolean
*/
function isZip(inVal,country){
	var regExpZip = '';
	//if (country==null) country = "US";
	if (country==null || country=='') return false;
	inVal = inVal.toUpperCase();
	switch (country.toLowerCase())
	{
	  case "canada":  case "ca":
	        //M2R 1P1
			if (inVal.length == 6) inVal = inVal.substr(0,3) + " " + inVal.substr(3);
	        regExpZip = /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/
	        break;
	  case "us":
			// U.S. ZIP codes have 5 or 9 digits.
			// They are formatted as 12345 or 12345-6789.
	        regExpZip = /^\d{5}(-\d{4})?$/
	        break;
	}
	if (regExpZip=='') return false;
	if(inVal.match(regExpZip)){
		return true;
	}else{
		return false;
	}
}

function isZipFix(objInput,country){
	//fix the postal/zip code input e.g spaces, trim etc...
	var regExpZip = '';
	//if (country==null) country = "US";
	if (country==null || country=='') return false;
	var inVal = objInput.value;
	inVal = inVal.toUpperCase();
	switch (country.toLowerCase())
	{
	  case "canada":  case "ca":
	        //M2R 1P1
			if (inVal.length == 6){
					inVal = inVal.substr(0,3) + " " + inVal.substr(3);
					objInput.value = inVal;
			}
	        regExpZip = /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/
	        break;
	  case "us":
			// U.S. ZIP codes have 5 or 9 digits.
			// They are formatted as 12345 or 12345-6789.
	        regExpZip = /^\d{5}(-\d{4})?$/
	        break;
	}
	if (regExpZip=='') return false;
	if(inVal.match(regExpZip)){
		return true;
	}else{
		return false;
	}
}

function Checkout_PopulateStatesList(country, stateId, action){
	var inptStates = null;
	if(action=="Billing"){
		inptStates = document.addressForm.bstateId;
	}else{
		inptStates = document.addressForm.sstateId;
	}
	//states.js
	PopulateStates(country,inptStates,stateId);
}

function isEmailValid(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }
   else
	  return true;
}

//========================================================================================================

//var ol_width=300;
var ol_fgcolor='#ffffcc';
var ol_bgcolor='#666666';

IncludeJS('scripts/overlib.js');

function redimGiftCard(){
	$("GiftCardCodeResult").innerHTML = "";
	var GiftCardCode = $('GiftCardCode').value;
	if (GiftCardCode.trim()==""){
		//$('GiftCardCode').style.backgroundColor='yellow';
		$('GiftCardCode').focus();
		return;
	}
	new Ajax.Request('ajax/ajaxRedimGiftCard.taf?GiftCardCode=' + GiftCardCode,{
		onSuccess: function(transport) {
			isValidGiftCard  = ajaxResponse(transport,"isValidGiftCard");
			if(isValidGiftCard==0){
				sorryMessage = ajaxResponse(transport,"sorryMessage");
				htmlReslt = '<font color="#FF0000"><b>ALERT: Your Gift Card Did Not Work - ' + sorryMessage + '<br><br>Please re-enter your gift code.</b></font>';
				$("GiftCardCodeResult").innerHTML = htmlReslt + "<br><br>";
				//Blink('GiftCardCodeResult');
			}else{
				var GiftCardValue = ajaxResponse(transport,"GiftCardValue");
				var AcountBalance = ajaxResponse(transport,"AcountBalance");
				htmlReslt = '<font color="green"><b>$' + GiftCardValue + ' has been added to you account.<br><br>' +
							'Your current total Account Balance: $' + AcountBalance +
							' </b></font>';
				$("GiftCardCodeResult").innerHTML = htmlReslt + "<br><br>";
				$('GiftCardCode').value = "";
			}
		}
	});
}

function setDialogs()
{
	/*
	$('#btn2').click(function() {
        $('.dialog').fadeOut('medium');
        $('#dialog2').fadeIn('medium');
    });
	*/
}

function pop(img,pid) {
LeftPosition = (screen.width) ? (screen.width-650)/2 : 0;
TopPosition = (screen.height) ? (screen.height-500)/2 : 0;
	winWidth=550;

x = window.open('/images/products/imageviewer/'+pid+'/image/','x','left='+LeftPosition+',top='+TopPosition+',width='+winWidth+',height=500,resizable=0,scrollbars=0,status=0');

}

function roundNumber(num, dec) {
	if (dec==null) dec=2;
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
