
function PopUp(theURL,winName,features) {
	window.open(theURL,winName,features);
}


function isNumber (InString)  {
     if(InString.length==0) return (false);
     var RefString="1234567890";
     for (Count=0; Count < InString.length; Count++)  {
         TempChar= InString.substring (Count, Count+1);
         if (RefString.indexOf (TempChar, 0)==-1)  
             return (false);
     }
     return (true);
}

function StringIsEmpty(st) {
   if ((st.length==0) || (st==null)) {
      return true;
   }
   else { return false; }
}


function addtocart(v_id) {
	addtocartwindow=dhtmlmodal.open('addtocart', 'iframe', '/addtocart.asp?s='+sessioncode+'&V_ID='+v_id, 'Add Product To Cart', 'width=500px,height=400px,center=1,resize=0,scrolling=0','recal');
	return false;
}

function hideapplicationwarning() {
	var x = document.getElementById('applicationwarning')
	x.style.visibility = 'hidden';
	x.style.display = 'none';
}

function ajaxaddtocart(url,v_id) {
	if (window.XMLHttpRequest) {ajaxRequest=new XMLHttpRequest();} else {ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");}
	ajaxRequest.open("GET",url,true);
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState==4){
			var acontent=ajaxRequest.responseText;
			if (!(acontent=='OK')) {
				alert('An error occured while adding this product to your shopping cart!<br />Please try adding it again.');
			} else {
				var addons=document.getElementById('tladdons');
				if (!(addons==null)) { myTabs.expandit('tladdons'); }
				//var x=document.getElementById('cartbutton_'+v_id);
				//if (!(x==null)) { x.src='/skin_rallitek/buttons/button_addedtocart.jpg';}
			}
			ajaxupdatecartdisplay();
			ajaxRequest=null;
		}
	}
	ajaxRequest.send(null);
}

function validateaddtocartform(v_id) {
	var x = document.getElementById('atcquantity');
	var v_qty=x.value;
	var v_ok=1;
	if (v_qty==null) {v_ok=0;}
	if (!(isNumber(v_qty))) {v_ok=0;}
	if (v_qty<1) {v_ok=0;}
	if (v_ok==0) {
		alert('Please enter a valid numerical quantity.');
		x.focus();
		x.select();
	} else {
		var url='/ajaxaddtobasket.asp?s='+sessioncode+'&v1='+v_id+'&q1='+v_qty;
		parent.ajaxaddtocart(url,v_id);
		parent.addtocartwindow.hide();
		parent.addtocartwindow.close();
	}
}


function ajaxupdatecartdisplay() {
	if (window.XMLHttpRequest) {ajaxd=new XMLHttpRequest();} else {ajaxd=new ActiveXObject("Microsoft.XMLHTTP");}
	ajaxd.open("GET",'/ajaxdisplaybasket.asp?s='+sessioncode,true);
	ajaxd.onreadystatechange = function(){
		if(ajaxd.readyState==4){
			cc=ajaxd.responseText;
			if (cc.length>0) { 
				eval(cc); 
				//cd=document.getElementById('cartsummary');
				//cd.style.display='block';
				//cd.innerHTML=URLDecode(cc);
				//cd.innerHTML=cc;
				//flashcart(1);
			}
		}
	}
	ajaxd.send(null);
}

function tooltipworddefinition(id) {
	if (window.XMLHttpRequest) {ajaxd=new XMLHttpRequest();} else {ajaxd=new ActiveXObject("Microsoft.XMLHTTP");}
	ajaxd.open("GET",'/ajaxworddefinition.asp?id='+id,false);
	ajaxd.send(null);
	return ajaxd.responseText;
}

function tooltipworddefinition2(id) {
	if (window.XMLHttpRequest) {ajaxd=new XMLHttpRequest();} else {ajaxd=new ActiveXObject("Microsoft.XMLHTTP");}
	ajaxd.open("GET",'/ajaxworddefinition.asp?id='+id,true);
	ajaxd.onreadystatechange = function(){
		if(ajaxd.readyState==4){
			cc=ajaxd.responseText;
			if (cc.length>0) {
				cd=document.getElementById('tooltipdiv');
				cd.style.display='block';
				cd.innerHTML=cc;
			}
		}

	}
	ajaxd.send(null);
	return '<div id="tooltipdiv">Loading...</div>'
}

function flashcart(e) {
	if (e==0) {c="#ffffff";e=1;i=3000;} else { c="#ffff70";e=0;i=1000; }
	document.getElementById("cartsummary").style.backgroundColor=c;
        window.setTimeout("flashcart('"+e+"')", i);
}



function ToggleItem(ItemID) {
	var myBox = document.getElementById('box_'+ItemID)
	if (myBox.style.visibility != 'hidden') {
		myBox.style.visibility = 'hidden';
		myBox.style.display = 'none';
	} else {
		myBox.style.visibility = 'visible';
		myBox.style.display = 'block';
	}
	return false;
}

function ToggleShippingInfo() {
	var chkBox = document.getElementById('strSameShippingAsBilling');

	var myBox = document.getElementById('shippingdetails')
	if (chkBox.checked) {
		myBox.style.visibility = 'hidden';
		myBox.style.display = 'none';
	} else {
		myBox.style.visibility = 'visible';
		myBox.style.display = 'block';
	}
	return false;
}

function submitphoto(p_id,c_id) {
	mc='<table align="center" style="margin:5px;border:0;border-spacing:0;"><tr>';
	mc+='<tr><td>';
	mc+='<iframe frameborder="0" style="height:250px;width:380px;border:0;" src="/submitproductphotoiframe.asp?s='+sessioncode+'&P_ID='+p_id+'&C_ID='+c_id+'">';
	mc+='<center><img src="/images/loading.gif"></center>';
	mc+='</iframe>';
	mc+='</td></tr>';
	mc+='<tr><td align="center" style="padding-top:10px;"><input class="submit" type="button" value="Close this Window" onClick="submitphotowindow.hide(); submitphotowindow.close();" /></td></tr>';
	mc+='</table>';
	document.getElementById('popupdiv').innerHTML=mc;
	submitphotowindow=dhtmlmodal.open('submitphoto', 'div', 'popupdiv', 'Submit Your Own Product Photo', 'width=400px,height=300px,center=1,resize=0,scrolling=0');
	return false;
}

function showdefinition(id) {
	mc='<table align="center" style="border:0;border-spacing:0;width:100%;"><tr>';
	mc+='<tr><td>';
	mc+='<iframe frameborder="0" style="height:410px;width:100%;border:0;" src="/worddefinition.asp?WD_ID='+id+'&s='+sessioncode+'">';
	mc+='<center><img src="/images/loading.gif"></center>';
	mc+='</iframe>';
	mc+='</td></tr>';
	mc+='<tr><td align="center" style="padding-top:10px;"><input class="submit" type="button" value="Close this Window" onClick="worddefwindow.hide(); worddefwindow.close();" /></td></tr>';
	mc+='</table>';
	document.getElementById('popupdiv').innerHTML=mc;
	worddefwindow=dhtmlmodal.open('worddef', 'div', 'popupdiv', 'Word Definition', 'width=600px,height=450px,center=1,resize=0,scrolling=0');
	return false;
}

function submitreview(p_id) {
	mc='<table align="center" style="border:0;border-spacing:0;width:100%;"><tr>';
	mc+='<tr><td>';
	mc+='<iframe frameborder="0" style="height:310px;width:100%;border:0;" src="/customerreview.asp?s='+sessioncode+'&P_ID='+p_id+'">';
	mc+='<center><img src="/images/loading.gif"></center>';
	mc+='</iframe>';
	mc+='</td></tr>';
	mc+='<tr><td align="center" style="padding-top:10px;">';
	mc+='<input class="submit" type="button" value="Close this Window" onClick="reviewwindow.hide(); reviewwindow.close();" />';
	mc+='</td></tr>';
	mc+='</table>';
	document.getElementById('popupdiv').innerHTML=mc;
	reviewwindow=dhtmlmodal.open('submitreview', 'div', 'popupdiv', 'Product Review', 'width=500px,height=350px,center=1,resize=0,scrolling=0');
	return false;
}


function showvehicledialog() {
	mc='<table align="center" style="border:0;border-spacing:0;width:100%;"><tr>';
	mc+='<tr><td>';
	mc+='<iframe style="height:310px;width:100%;border:0;" frameborder="0" src="/choosevehicle.asp?s='+sessioncode+'"><center><img src="" & strTemplateShopURL & "images/loading.gif"></center></iframe>';
	mc+='</td></tr>';
	mc+='<tr><td align="center" style="padding-top:10px;"><input class="submit" type="button" value="Close this Window" onClick="vehicledialog.hide(); vehicledialog.close();" /></td></tr>';
	mc+='</table>';
	mc+='</form>';
	document.getElementById('popupdiv').innerHTML=mc;
	vehicledialog=dhtmlmodal.open('vehicledialogwindow', 'div', 'popupdiv', 'Choose Your Vehicle', 'width=500px,height=350px,center=1,resize=0,scrolling=0');
	return false;
}
function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};



//	function addversion(v_name,v_id,v_quantity,v_question,v_uom,v_price,v_image) {
//		mc='<div id="atcproductname">'+v_name+'</div>';
//		mc+='<div id="atcimage"><center>'+v_image+'</center></div>';
//		if (v_question.length>0) {mc+='<span id="atcwarning">'+v_question+'</span>';}
//		mc+='<div id="atcuom">'+v_price+' per '+v_uom+'</div>';
//		mc+='<form id="atc" method="get" action="#" onSubmit="return false;">';
//		mc+='<table align="center" style="margin:5px;border:0;border-spacing:0;"><tr><td nowrap>Quantity to add:</td>';
//		mc+='<td><input type="text" name="qty" value="'+v_quantity+'" size="4"/></td>';
//		mc+='<td><input class="submit" type="submit" value="Add to Cart" onClick="validateaddtocartform('+v_id+');" /></td>';
//		mc+='<td><input class="submit" type="button" value="Cancel" onClick="addtocartwindow.hide(); addtocartwindow.close();" /></td>';
//		mc+='</tr></table></form>';
//		document.getElementById('popupdiv').innerHTML=mc;
//		var wh='275';
//		if (v_question.length>0) {wh='385';}
//		var winparams='width=400px,height='+wh+'px,center=1,resize=0,scrolling=0';
//		addtocartwindow=dhtmlmodal.open('addtocart', 'div', 'popupdiv', 'Add Product to Cart', winparams);
//		document.forms.atc.qty.focus();
//		document.forms.atc.qty.select();
//		return false;
//	}
