/**
 *  Most of the scripts below were found at
 *  www.alistapart.com and related sites.  They are used
 *  here because they are web standards compliant.  These
 *  scripts are all free to reuse and are not licensed as
 *  part of the Kryptronic Hybrid X Core (KHXC).
 *
 *  All onload() events go at the bottom of this file.
 */

/**
 *  Function DisableSubmit() used to disable submit buttons
 *  after then have been depressed.  This is implemented to
 *  stop multiple click submissions of forms.
 */

var submitted = false;

function DisableSubmit(formname) {
     if(submitted == true) { return; }
     document.forms[formname].submit();
     document.forms[formname].SUBMIT.value = 'Please Wait...';
     document.forms[formname].SUBMIT.disabled = true;
     submitted = true;

}

/**
 *  Function externalLinks() used to provide a standards
 *  compliant way of producing a pop-up link to another
 *  page.
 */

function externalLinks() {

     if (!document.getElementsByTagName) return;
     var anchors = document.getElementsByTagName("a");
     for (var i=0; i<anchors.length; i++) {
     var anchor = anchors[i];
     if (anchor.getAttribute("href") &&
     anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
     }

}

/**
 *  Function to add multiple onload() events to a page. 
 *  Authored by Scott Andrew.  Visit www.scottandrew.com
 *  for info.
 */

function addEvent(elm, evType, fn, useCapture) {

     if (elm.addEventListener) {
     elm.addEventListener(evType, fn, useCapture);
     return true;
     } else if (elm.attachEvent) {
     var r = elm.attachEvent('on' + evType, fn);
     return r;
     } else {
     elm['on' + evType] = fn;
     }

}

/**
 *	Whatever:hover - V1.42.060206 - hover & active
 *	------------------------------------------------------------
 *	(c) 2005 - Peter Nederlof
 *	Peterned - http://www.xs4all.nl/~peterned/
 *	License  - http://creativecommons.org/licenses/LGPL/2.1/
 *
 *	Whatever:hover is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	Whatever:hover is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *	Lesser General Public License for more details.
 *
 *	Credits and thanks to:
 *	Arnoud Berendsen, Martin Reurings, Robert Hanson
 *
 *	howto: body { behavior:url("csshover.htc"); }
 *	------------------------------------------------------------
 */

var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,

currentSheet, doc = window.document, hoverEvents = [], activators = {
onhover:{on:'onmouseover', off:'onmouseout'},
onactive:{on:'onmousedown', off:'onmouseup'}
}

function parseStylesheets() {

     if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
     window.attachEvent('onunload', unhookHoverEvents);
     var sheets = doc.styleSheets, l = sheets.length;
     for(var i=0; i<l; i++) 
     parseStylesheet(sheets[i]);

}

function parseStylesheet(sheet) {

     if(sheet.imports) {
     try {
     var imports = sheet.imports, l = imports.length;
     for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
     } catch(securityException){}
     }
     try {
     var rules = (currentSheet = sheet).rules, l = rules.length;
     for(var j=0; j<l; j++) parseCSSRule(rules[j]);
     } catch(securityException){}

}

function parseCSSRule(rule) {

     var select = rule.selectorText, style = rule.style.cssText;
     if(!csshoverReg.test(select) || !style) return;
     var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
     var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
     var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
     var affected = select.replace(/:(hover|active).*$/, '');
     var elements = getElementsBySelect(affected);
     if(elements.length == 0) return;
     currentSheet.addRule(newSelect, style);
     for(var i=0; i<elements.length; i++)
     new HoverElement(elements[i], className, activators[pseudo]);

}

function HoverElement(node, className, events) {

     if(!node.hovers) node.hovers = {};
     if(node.hovers[className]) return;
     node.hovers[className] = true;
     hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
     hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });

}

function hookHoverEvent(node, type, handler) {

     node.attachEvent(type, handler);
     hoverEvents[hoverEvents.length] = { 
     node:node, type:type, handler:handler 
     };

}

function unhookHoverEvents() {

     for(var e,i=0; i<hoverEvents.length; i++) {
     e = hoverEvents[i]; 
     e.node.detachEvent(e.type, e.handler);
     }
}

function getElementsBySelect(rule) {

     var parts, nodes = [doc];
     parts = rule.split(' ');
     for(var i=0; i<parts.length; i++) {
     nodes = getSelectedNodes(parts[i], nodes);
     }
     return nodes;

}

function getSelectedNodes(select, elements) {

     var result, node, nodes = [];
     var identify = (/\#([a-z0-9_-]+)/i).exec(select);
     if(identify) {
     var element = doc.getElementById(identify[1]);
     return element? [element]:nodes;
     }
     var classname = (/\.([a-z0-9_-]+)/i).exec(select);
     var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
     var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
     for(var i=0; i<elements.length; i++) {
     result = tagName? elements[i].all.tags(tagName):elements[i].all; 
     for(var j=0; j<result.length; j++) {
     node = result[j];
     if(classReg && !classReg.test(node.className)) continue;
     nodes[nodes.length] = node;
     }
     }	
     return nodes;

}

/**
 *  Function to show or hide an id within an XHTML page.
 */

function idShowHide(obj) {

     var el = document.getElementById(obj);
     if ( el.style.display != "none" ) {
     el.style.display = 'none';
     } else {
     el.style.display = 'block';
     }
}

/**
 *  All onload() events here.
 */

addEvent(window,'load',externalLinks,false);

var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
if (IE6) {addEvent(window,'load',parseStylesheets,false);}

/*Here code from garry*/
/* HTTP OBJECT to Call Server Script*/
function getHTTPObject() 
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try 
	{
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
	catch (e) 
	{
      try 
	  {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  catch (E) 
	  {
        xmlhttp = false;
	  }
    }
  @else
  	xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  {
    try
	{ 
      xmlhttp = new XMLHttpRequest();
	}
	catch (e) 
	{
      xmlhttp = false;
	}
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object

function shipvalue__1(str,qty,StCtryZ)
{
	var s_state='';
	var s_country='';
	var s_zip='';
	if(StCtryZ!="")
	{
		arrStCtryZ=StCtryZ.split("||");
		s_state=arrStCtryZ[0];
		s_country=arrStCtryZ[1];
		s_zip=arrStCtryZ[2];
		
	}
	
	document.getElementById("showresulthere").innerHTML="";
	document.getElementById("showrebutton").style.display="none";
	document.getElementById("showresulthere").style.display="block";
	splitval=str.split("||");
	var shiplength=splitval[0];
	var shipwidth=splitval[1];
	var shipheight=splitval[2];
	var shipweight=splitval[3];
	var shipnumbox=splitval[4];
	var shipclass=splitval[5];
	var is_free_ship=splitval[6];
// BEGIN
	var  pageID=document.getElementById("pageID").value;
	shipnumbox=document.getElementById("ccp0--prodaddtocart--"+pageID+"--quantity").value;
	var delevType=document.getElementById('delevType').value;
	TotalWeight=(shipweight*qty);
//alert("Weight="+shipweight+"\nTotalWeight="+TotalWeight+"\nClass="+shipclass);
document.getElementById("showresulthere").style.display="block";
	var zipcodesend=document.getElementById('sendzipcode').value;
	if(shipclass=="")	
	{
		var cubicIn=(shiplength*shipwidth*shipheight)*qty;
		//alert("(L x W x H) x qty = ("+shiplength+" x "+shipwidth+" x "+shipheight+") x "+qty+" = Cubic In = "+cubicIn);
		var cubicFoot=cubicIn/1728;
		//alert(cubicIn+" Divide by 1728 = Cubic Foot = "+cubicFoot);
		var new_wieight=(Math.round(TotalWeight*100)/100);
		var Freight_Density = parseInt(new_wieight/cubicFoot);
		Freight_Density=(Math.round(Freight_Density*100)/100);	
		//alert("Freight_Density="+Freight_Density);
		if(isNaN(Freight_Density))
		{
			alert("Unknown shipping class and undefined length, width, height etc.");
			document.getElementById("showrebutton").style.display="block";
			document.getElementById("showresulthere").style.display="none";			
		}
		shipclass=GetClassVal(Freight_Density);
	}
//alert("NOW\nWeight="+shipweight+"\nTotalWeight="+TotalWeight+"\nClass="+shipclass);	
	var url1="";
	if(TotalWeight<=70)
	{
		url1 += "testzipcode.php?shiplength=";
		url1 += shiplength + "&shipwidth=" + shipwidth + "&shipheight="+shipheight+ "&shipweight="+shipweight+"&shipnumbox="+shipnumbox+"&zipcodesend="+zipcodesend+(StCtryZ!=""?'&s_state='+s_state+'&s_country='+s_country+'&s_zip='+s_zip:'')+'&is_free_ship='+is_free_ship;			
	}
	else
	{
		url1 = "rater_php4.php?fullweight="+TotalWeight+"&weight="+shipweight+"&class="+shipclass+"&destination="+zipcodesend+'&delevType='+delevType+(StCtryZ!=""?'&s_state='+s_state+'&s_country='+s_country+'&s_zip='+s_zip:'')+'&is_free_ship='+is_free_ship;
	}
	var date = new Date();
	var timestamp = date.getTime();	
	url1 += "&time="+timestamp;
	//alert(url1);
//END

//alert("function=shipvalue__1 \n&\nURL="+url1);
	http.open("GET", url1, true);
  	http.onreadystatechange = handleHttpResponse;
  	http.send(null);
	
	
}
/*function shipvalue(str,qty)
{
	document.getElementById("showresulthere").innerHTML="";
	document.getElementById("showrebutton").style.display="none";
	document.getElementById("showresulthere").style.display="block";
	
	splitval=str.split("||");
	qty=parseFloat(qty);
	var shiplength=parseFloat(splitval[0]);
	var shipwidth=parseFloat(splitval[1]);
	var shipheight=parseFloat(splitval[2]);
	var shipweight=parseFloat(splitval[3]);
	var shipnumbox=parseFloat(splitval[4]);
	
	var  pageID=document.getElementById("pageID").value;
	shipnumbox=document.getElementById("ccp0--prodaddtocart--"+pageID+"--quantity").value;
	
	var delevType=document.getElementById('delevType').value;
	
	var cubicIn=(shiplength*shipwidth*shipheight)*qty;
	//alert("(L x W x H) x qty = ("+shiplength+" x "+shipwidth+" x "+shipheight+") x "+qty+" = Cubic In = "+cubicIn);
	var cubicFoot=cubicIn/1728;
	//alert(cubicIn+" Divide by 1728 = Cubic Foot = "+cubicFoot);
	TotalWeight=Math.abs(shipweight*qty);
	var new_wieight=(Math.round(TotalWeight*100)/100);
	var Freight_Density = parseInt(new_wieight/cubicFoot);
	 Freight_Density=(Math.round(Freight_Density*100)/100);
	
	//alert("Freight Density = wheight/"+cubicFoot+" = ("+shipweight+" x "+qty+")/"+cubicFoot+" = " + Freight_Density);
	//alert("Class = "+GetClassVal(Freight_Density)+" weight="+new_wieight);
	//alert("Qty = "+qty);
	document.getElementById("showresulthere").style.display="block";
	
	var zipcodesend=document.getElementById('sendzipcode').value;
	var url1 = "rater_php4.php?fullweight="+(shipweight*qty)+"&weight="+shipweight+"&class="+GetClassVal(Freight_Density)+"&destination="+zipcodesend+'&delevType='+delevType;
	//alert(url1);
	http.open("GET", url1, true);
  	http.onreadystatechange = handleHttpResponse;
  	http.send(null);
	
	
}
*/

function shipvalue(str,qty,StCtryZ)
{
	var s_state='';
	var s_country='';
	var s_zip='';
	if(StCtryZ!="")
	{
		arrStCtryZ=StCtryZ.split("||");
		s_state=arrStCtryZ[0];
		s_country=arrStCtryZ[1];
		s_zip=arrStCtryZ[2];
		
	}
	
	document.getElementById("showresulthere").innerHTML="";
	document.getElementById("showrebutton").style.display="none";
	document.getElementById("showresulthere").style.display="block";
	
	splitval=str.split("||");
	qty=parseFloat(qty);
	var shipweight=parseFloat(splitval[0]);
	var shipclass=parseFloat(splitval[1]);

	
	var  pageID=document.getElementById("pageID").value;
	shipnumbox=document.getElementById("ccp0--prodaddtocart--"+pageID+"--quantity").value;
	
	var delevType=document.getElementById('delevType').value;
	
	TotalWeight=Math.abs(shipweight*qty);

	document.getElementById("showresulthere").style.display="block";
	
	var zipcodesend=document.getElementById('sendzipcode').value;
	var url1 = "rater_php4.php?fullweight="+TotalWeight+"&weight="+shipweight+"&class="+shipclass+"&destination="+zipcodesend+'&delevType='+delevType+(StCtryZ!=""?'&s_state='+s_state+'&s_country='+s_country+'&s_zip='+s_zip:'');
	//alert("function=shipvalue \n&\nURL="+url1);
	http.open("GET", url1, true);
  	http.onreadystatechange = handleHttpResponse;
  	http.send(null);
	
	
}
function GetClassVal(TotalDensity){
	var ClassVal=0;
	var TD = TotalDensity;
	
	//Check to see if US Measure radio button is checked
	if (true) {
		//US Measure
		TD=TD;
	} else {
		//Metric Measure
		TD=TD/16.0184634; // 1 lb/cu.ft = 16.0184634 kg/cu.mtr
	}
	
	if(TD<1){
	ClassVal=500;
	}
	if((TD>=1) && (TD<2)){
	ClassVal=400;
	}
	if((TD>=2) && (TD<3)){
	ClassVal=300;
	}
	if((TD>=3) && (TD<4)){
	ClassVal=250;
	}
	if((TD>=4) && (TD<5)){
	ClassVal=200;
	}
	if((TD>=5) && (TD<6)){
	ClassVal=175;
	}
	if((TD>=6) && (TD<7)){
	ClassVal=150;
	}
	if((TD>=7) && (TD<8)){
	ClassVal=125;
	}
	if((TD>=8) && (TD<9)){
	ClassVal=110;
	}
	if((TD>=9) && (TD<10.5)){
	ClassVal=100;
	}
	if((TD>=10.5) && (TD<12)){
	ClassVal=92;
	}
	if((TD>=12) && (TD<13.5)){
	ClassVal=85;
	}	
	if((TD>=13.5) && (TD<15)){
	ClassVal=77;
	}	
	if((TD>=15) && (TD<22.5)){
	ClassVal=70;
	}	
	if((TD>=22.5) && (TD<30)){
	ClassVal=65;
	}	
	if((TD>=30) && (TD<35)){
	ClassVal=60;
	}	
	if((TD>=35) && (TD<50)){
	ClassVal=55;
	}
	if(TD>=50){
	ClassVal=50;
	}		
	return ClassVal;
}

function update_qty(val)
{
	var qty=parseFloat(val);
	var old_price=parseFloat(document.getElementById('myactual_price').value);
	var new_price=roundNumber((old_price*qty),2);
	document.getElementById('khxc_price').innerHTML="$"+new_price;
	document.getElementById('Basepriceshowval').value=new_price;
	document.getElementById('priceshowval').value=new_price;
	
	
}
function roundNumber(number,decimal_points) {
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}

function handleHttpResponse() 
{
  if (http.readyState == 4)
  {
	result="";  
	zipcodev="";
	var result1 = http.responseText;
	document.getElementById("showresulthere").innerHTML="<div class='totalShipformat'>"+result1+" <a href='javascript:void(0);' onclick='return aginship()' style='color:#ffffff;'>Back</a></div>";
		
  }
  else
  {
		document.getElementById("showresulthere").innerHTML="<img src='skins/OMGBudget/media/loading.gif'>";	  
  }
}

var http1 = getHTTPObject(); // We create the HTTP Object
var http2 = getHTTPObject(); // We create the HTTP Object

function shipvalue_new(str)
{
	document.getElementById("showresulthere").innerHTML="";
	document.getElementById("showrebutton").style.display="none";
	document.getElementById("showresulthere").style.display="block";
	var zipcodesend=document.getElementById('sendzipcode').value;
	var url1 = "http://budgetsupply.com/testzipcode_cart.php?totstr="; 	

	url1 = url1 + str+"&zipcodesend="+zipcodesend;
	//alert(url1);
	http1.open("GET", url1, true);
  	http1.onreadystatechange = handleHttpResponse1;
  	http1.send(null);
	
	
}
function handleHttpResponse1() 
{
  if (http1.readyState == 4)
  {
	result="";  
	zipcodev="";
	var result1 = http1.responseText;
	resultnew=result1.split("|||");
	result=resultnew[0];
	zipcodev=resultnew[1];
	document.getElementById("showresulthere").innerHTML="<div class='totalShipformat'><b>Total Shipping for "+zipcodev+":<br> $"+result+"</b><br><a href='javascript:void(0);' onclick='return aginship()' style='color:#ffffff;'>Back</a></div>";
		
  }
}

function aginship()
{
	document.getElementById("showrebutton").style.display="block";
	document.getElementById("showresulthere").style.display="none";
}


function colorimage(pid, xopid)
{
	document.getElementById("color_cont").innerHTML="";
	var dropidval=document.getElementById("ccp0--prodaddtocart--"+pid+"--"+xopid).value;
	document.getElementById("color_cont").style.display="block";
	var url1 = "http://budgetsupply.com/returncolourimage.php?id="+dropidval; 	
	http2.open("GET", url1, true);
  	http2.onreadystatechange = handleHttpResponse2;
  	http2.send(null);
	
	
}
function handleHttpResponse2() 
{
  if (http2.readyState == 4)
  {
	var result = http2.responseText;
	document.getElementById("color_cont").innerHTML=result;
		
  }
}
/**
 *  End.
 */

function sortOptions() {
	if(document.sortByForm.sortbyselect.value != '') {
		window.location.href = document.sortByForm.sortbyselect.value;
	} else {
		
	}
}
function addcolorval(id,value,counter,typevale)
{
	preval=document.getElementById("priceshowval").value;
	if(document.getElementById(id+"--"+counter).checked==true)
	{
		newpreval=parseInt(preval) + parseInt(value);
	}
	else
	{
		newpreval=parseInt(preval) - parseInt(value);
	}
	newpreval=newpreval.toFixed(2);

	document.getElementById("priceshowval").value=newpreval;
	document.getElementById("khxc_price").innerHTML='$'+newpreval;
}
function addcolorval_radio(id,value,counter,typevale)
{
	preval=document.getElementById("priceshowval").value;
	oldpreval=document.getElementById("priceshowval_check").value;
	document.getElementById("priceshowval_check").value=parseInt(value);
	newpreval=parseInt(preval) + parseInt(value);
	newpreval=newpreval - oldpreval;
	newpreval=newpreval.toFixed(2);

	document.getElementById("priceshowval").value=newpreval;
	document.getElementById("khxc_price").innerHTML='$'+newpreval;
}

function addcolorval_new(id)
{
	var startId=0;
	var sendedIDs='';
	for (var i = 0; i < document.forms[1].elements.length; i++)
	{ 
		if(document.forms[1].elements[i].type=="select-one")
		{
			if(document.forms[1].elements[i].value!=0)
			{
				if(startId==0)
				{
					var sendedIDs=document.forms[1].elements[i].value;
					startId++;
				}
				else
				{
					sendedIDs=sendedIDs+'|'+document.forms[1].elements[i].value;	
				}
			}
		}	
	}
	
	//if(id!=0)
//	{
		//document.getElementById("priceshowval_lastidval").value=lastid;
//		preval=document.getElementById("priceshowval").value;  
//		oldpreval=document.getElementById("priceshowval_select").value;
//		var url1 = "http://budgetsupply.com/returncolour_select.php?id="+sendedIDs+"&lastid="+lastid; 	
		var url1 = "http://budgetsupply.com/returncolour_select.php?id="+sendedIDs; 	
		http2.open("GET", url1, true);
		http2.onreadystatechange = handleHttpResponse2;
		http2.send(null);
	//}
//	else
//	{
//		preval=document.getElementById("priceshowval").value;  
//		document.getElementById("priceshowval_lastidval").value;  
//		oldpreval=document.getElementById("priceshowval_select").value; 
//		if(oldpreval!='')
//		{
//			newpreval=preval-oldpreval;
//		}
//		else
//		{
//			newpreval=document.getElementById("Basepriceshowval").value;  	
//		}
//		newpreval=newpreval.toFixed(2);
//		document.getElementById("priceshowval_select").value='';  	
//		document.getElementById("priceshowval_lastidval").value=lastid;
//		document.getElementById("priceshowval").value=newpreval;
//		document.getElementById("khxc_price").innerHTML='$'+newpreval;
//	}
	
}
function handleHttpResponse2() 
{
	//preval=document.getElementById("priceshowval").value;  
//	prevalLastid=document.getElementById("priceshowval_lastidval").value;  
//	oldpreval=document.getElementById("priceshowval_select").value; 
	
	basepriceValue=document.getElementById("Basepriceshowval").value;  
	if (http2.readyState == 4)
	  {
		var newpreval11 = http2.responseText;
		//newpreval22=newpreval11.split("##");
//		var newpreval = newpreval22[1];
//		var lastIDreturn=newpreval22[0];
//		document.getElementById("priceshowval_select").value=newpreval;
	//	newpreval=parseFloat(preval)+parseFloat(newpreval);
		newpreval=parseFloat(basepriceValue)+parseFloat(newpreval11);
		
		//if((prevalLastid=="") || (prevalLastid==lastIDreturn))
//		{					 
//			newpreval=newpreval-oldpreval;
//		}
		newpreval=newpreval.toFixed(2);
		//document.getElementById("priceshowval_lastidval").value=lastIDreturn;
		//document.getElementById("priceshowval").value=newpreval;
		document.getElementById("khxc_price").innerHTML='$'+newpreval;
			
	  }
}


var XMLHttpRequestObject = false;
if(window.XMLHttpRequest) {
	XMLHttpRequestObject = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function displayImageOMG(valueCheck,divDisplay) {
	if(XMLHttpRequestObject) {
			var valueSet = document.getElementById(valueCheck).value;
			XMLHttpRequestObject.open('GET','http://budgetsupply.com/returncolourimage.php?optionvalue=' + valueSet);
			XMLHttpRequestObject.onreadystatechange = function() {
				if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					var obj = document.getElementById(divDisplay);
					obj.innerHTML = XMLHttpRequestObject.responseText;
				}
			}
			XMLHttpRequestObject.send(null);
		
	}
}

var lastClickedTab;
var lastClickedDiv;

function changeTabs(DivID, TabID){
	
	if(lastClickedTab == undefined && TabID != 'tab1'){
		
		/*alert(lastClickedTab);
		alert(TabID);*/
		
		lastClickedTab = TabID;
		lastClickedDiv = DivID;
		
		
		//J('#tab1Content').slideUp('normal');
		if(document.getElementById('tab1')){
			document.getElementById('tab1Content').style.display = 'none';
			J('#tab1').removeClass('tab1');
			J('#tab1').addClass('tab2');
		}else if(document.getElementById('tab2')){
			document.getElementById('tab2Content').style.display = 'none';
			J('#tab2').removeClass('tab1');
			J('#tab2').addClass('tab2');
		}else if(document.getElementById('tab3')){
			document.getElementById('tab3Content').style.display = 'none';
			J('#tab3').removeClass('tab1');
			J('#tab3').addClass('tab2');
		}else if(document.getElementById('tab4')){
			document.getElementById('tab4Content').style.display = 'none';
			J('#tab4').removeClass('tab1');
			J('#tab4').addClass('tab2');
		}else if(document.getElementById('tab5')){
			document.getElementById('tab5Content').style.display = 'none';
			J('#tab5').removeClass('tab1');
			J('#tab5').addClass('tab2');
		}
		
		
		J('#'+TabID).addClass('tab1');
		J('#'+TabID).removeClass(TabID);
		document.getElementById(DivID).style.display = '';
		//J('#'+DivID).slideDown('normal');		
		
	}else{
		document.getElementById(lastClickedDiv).style.display = 'none';
		//J('#'+lastClickedDiv).slideUp('normal');
		J('#'+lastClickedTab).removeClass('tab1');
		
		if(lastClickedTab != 'tab1'){
			J('#'+lastClickedTab).addClass(lastClickedTab);
		}else{
			J('#'+lastClickedTab).addClass('tab2');
		}
		//J('#'+lastClickedTab).addClass(lastClickedTab);
		
		lastClickedTab = TabID;
		lastClickedDiv = DivID;		
		J('#'+TabID).addClass('tab1');
		if(TabID != 'tab1'){
			J('#'+TabID).removeClass(TabID);
		}else{
			J('#'+TabID).removeClass('tab2');
		}
		document.getElementById(DivID).style.display = '';
		//J('#'+DivID).slideDown('normal');		
	}
	
	
}

function changeSrc(ID, src, Type, ColorName){
	if(Type == 'Frame'){
		if(document.getElementById('Metal_Frame_Name')){
			document.getElementById('Metal_Frame_Name').innerHTML = ColorName;
			document.getElementById('Metal_Frame').src = 'media/khxc/colors/'+src;
		}
		if(document.getElementById('Vinyl_Frame_Name')){
			document.getElementById('Vinyl_Frame_Name').innerHTML = ColorName;
			document.getElementById('Vinyl_Frame').src = 'media/khxc/colors/'+src;
		}
		if(document.getElementById('Fabric_Frame_Name')){
			document.getElementById('Fabric_Frame_Name').innerHTML = ColorName;
			document.getElementById('Fabric_Frame').src = 'media/khxc/colors/'+src;
		}
		if(document.getElementById('Wood_Frame_Name')){
			document.getElementById('Wood_Frame_Name').innerHTML = ColorName;
			document.getElementById('Wood_Frame').src = 'media/khxc/colors/'+src;
		}
	}else{
		document.getElementById(ID).src = 'media/khxc/colors/'+src;
		document.getElementById(ID+'_Name').innerHTML = ColorName;
	}
			
}

function ChngGrade(CategoryID, ProductID, Grade, Title, TabID, BigImageID, BigImage, FrameMetal){
	J.ajax({
		url: "/getAjaxData.php?CategoryID="+CategoryID+"&ProductID="+ProductID+"&Grade="+Grade+"&Title="+Title+"&TabID="+TabID+"&BigImageID="+BigImageID+"&BigImage="+BigImage+"&FrameMetal="+FrameMetal,
		dataType: 'html',
		type: 'GET',
		async: false,
		success: function(html){
			//alert(html);
			J('#'+TabID).html(html);
		}
	});	
}

function GetGrade(ProdID, SeatID){
	if(SeatID == '')
	{
		document.getElementById('GradeDivLabel').style.display = 'none';
		document.getElementById('GradeDiv').style.display = 'none';
		document.getElementById('colorDivLabel').style.display = 'none';
		document.getElementById('colorDiv').style.display = 'none';
	}
	else
	{
		J.ajax({
			url: "/getFrontEndData.php?ProdID="+ProdID+"&SeatID="+SeatID+"&Type=Grade",
			dataType: 'html',
			type: 'GET',
			async: false,
			success: function(html){
				//alert(html);
				document.getElementById('GradeDivLabel').style.display = '';
				document.getElementById('GradeDiv').style.display = '';
				J('#GradeDiv').html(html);
				J('#ProdColor').html('<option value="">Select Color</option>');
			}
		});	
	}
}

function GetColor(ProdID, SeatID, GradeID){
	if(GradeID == '')
	{
		document.getElementById('colorDivLabel').style.display = 'none';
		document.getElementById('colorDiv').style.display = 'none';
	}
	else
	{
		J.ajax({
			url: "/getFrontEndData.php?ProdID="+ProdID+"&SeatID="+SeatID+"&GradeID="+GradeID+"&Type=Color",
			dataType: 'html',
			type: 'GET',
			async: false,
			success: function(html){
				//alert(html);
				var ContentArray = html.split(':;');
				
				document.getElementById('colorDivLabel').style.display = '';
				document.getElementById('colorDiv').style.display = '';
				J('#colorDiv').html(ContentArray[0]);
				
				var ProductPrice = document.getElementById('myactual_price').value;
				var extraPrice = parseFloat(ContentArray[1]);
				var TotalValue = (parseFloat(ProductPrice) + extraPrice).toFixed(2);
				document.getElementById('khxc_price').innerHTML = "$"+TotalValue;
				document.getElementById('Custom_price').value = TotalValue;
				document.getElementById('SeatExtra_price').value = extraPrice;
			}
		});	
	}
}

function GetColorFrame(ProdID, FrameID){
	if(FrameID == '')
	{
		document.getElementById('colorDivFrameLabel').style.display = 'none';
		document.getElementById('colorDivFrame').style.display = 'none';
	}
	else
	{
		J.ajax({
			url: "/getFrontEndData.php?ProdID="+ProdID+"&FrameID="+FrameID+"&Type=ColorFrame",
			dataType: 'html',
			type: 'GET',
			async: false,
			success: function(html){
				//alert(html);
				eval(html);
				document.getElementById('colorDivFrameLabel').style.display = '';
				document.getElementById('colorDivFrame').style.display = '';
			}
		});
	}
}