// Get the HTTP Object
function getHTTPObject() {
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();
	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
}



// Change the value of the outputText field
function setStockOutput() {
	if(httpObject.readyState == 1 || httpObject.readyState == 2 || httpObject.readyState == 3){
		document.getElementById('stockdiv').innerHTML = "<font size=2>Loading...</font>";
	}
	if(httpObject.readyState == 4){  //data is retrieved from server
		data = httpObject.responseText;
		if (httpObject.status == 200)  // which represents ok status
		document.getElementById('stockdiv').innerHTML = data;
	}
}

/////////// To Show All Price ////////////////////
function showAllPrice(strURL)
{
	//alert(strURL);
	httpObject = getHTTPObject();
	if (httpObject != null) {
    	//httpObject.onreadystatechange = setStockOutput;
		httpObject.onreadystatechange = function() {
		
			if(httpObject.readyState == 1 || httpObject.readyState == 2 || httpObject.readyState == 3){
				document.getElementById('stockdiv').innerHTML = "<font size=2>Loading...</font>";
			}
			if(httpObject.readyState == 4){  //data is retrieved from server
				data = httpObject.responseText;
				if (httpObject.status == 200)  // which represents ok status
				document.getElementById('stockdiv').innerHTML = data;
			}

		}

		httpObject.open("GET", strURL, true); //open url using get method
		httpObject.send(null);
 	}
}
//////////////end code of price////////////////////




function showSubchar(charId,strURL) {
	
	//alert(strURL);
	httpObject = getHTTPObject();
	if (httpObject != null) {
    	//httpObject.onreadystatechange = setStockOutput;
		httpObject.onreadystatechange = function() {
		
			if(httpObject.readyState == 1 || httpObject.readyState == 2 || httpObject.readyState == 3){
				document.getElementById('stockdiv'+charId).innerHTML = "<font size=2>Loading...</font>";
			}
			if(httpObject.readyState == 4){  //data is retrieved from server
				data = httpObject.responseText;
				if (httpObject.status == 200)  // which represents ok status
				document.getElementById('stockdiv'+charId).innerHTML = data;
			}

		}

		httpObject.open("GET", strURL, true); //open url using get method
		httpObject.send(null);
 	}
}

function showSubCharImage(img,varID)
{ 
	if(img!='0')
	{
		var spl =img.split('_');
		//var spl = img.substring(img.indexOf('_')+4,img.length);
		//alert(spl[4]);
		var spath = spl[6];
		
		if(spath != '')
		{
			var ImgPath = 'http://lakesgaragedoors.neotericuk.co.uk/images/lakesgaragedoors.neotericuk.co.uk/characteristics/'+spath;
			//document.getElementById('showSbCharImg'+varID).src = ImgPath;
			document.getElementById('chaImage'+varID).innerHTML="<img src='"+ImgPath+"' width='50' height='50'  />";
		 //window.open ('http://lakesgaragedoors.neotericuk.co.uk/images/lakesgaragedoors.neotericuk.co.uk/stains/'+spath,'',"menubar=0,status=0, resizable=0, width=300, height=300,left=300,top=300");
		}
		else {
			document.getElementById('chaImage'+varID).innerHTML="";
		
		}
	}else
	{
		document.getElementById('chaImage'+varID).innerHTML="";
	}
  }
  
  
  //////////////Price functionality/////////////////
  
  function showPrices(prc)
  {  //alert(prc);
	if(prc!='')
	{
		//alert("fdgdsgh");
		var showAllprice=0;
		prdPrice = document.getElementById('mainPrdPrice').value;
		for (i=0; i<document.getElementsByTagName("select").length; i++)
		{
			if (document.getElementsByTagName("select")[i].value != '')
			{
						var hiselect = document.getElementsByTagName("select")[i].value;
						//alert(hiselect);
						var spl =hiselect.split('_');
						var charPrice = spl[0];
						//alert(charPrice);
						showAllprice = showAllprice + parseFloat(charPrice);
						//alert(showAllprice);
							
			}

		}
		var showAlldispprice = parseFloat(showAllprice)+parseFloat(prdPrice);
		var finalPrice = roundNumber(showAlldispprice,2);
		document.getElementById('showMainPrices').innerHTML=finalPrice;
		
		
		
		
	}
  }
  
  
  function roundNumber(num, dec)
  {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	result = result.toFixed(2);
	return result;
 }
  
  
  
  
