var xmlHttp;
var Server="";
//var Server="http://www.mytownfsbo.com/";
var DIVNAME;
var VAL;
var WaitingHTML="Please wait. Processing your request";
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
var is_opera = ((navigator.userAgent.indexOf("Opera 6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

function doAjax(URL,DivName,Val)
{
	URL = Server+URL;
	xmlHttp = GetXmlHttpObject(stateChangeHandler);
	xmlHttp_Get(xmlHttp, URL);
	DIVNAME=DivName;
	VAL=Val;
}
function stateChangeHandler()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var response = xmlHttp.responseText;
		
		if(DIVNAME!=""){
			document.getElementById(DIVNAME).innerHTML=response;
		}
		if(VAL!=""){
			price=trim(response);
			factor=document.shcart.factor.value;
			if(factor=="" || factor=="0")
				factor=1;
			qty=document.shcart.qty.value;
			var widthvalue=return_width();
			var heightvalue=return_height();
			var mul;
			totoption=document.shcart.totoption.value;
			var totoptprice=0;
			mul = parseInt(widthvalue)*parseInt(heightvalue);
			uiwin=parseInt(widthvalue)+parseInt(heightvalue);
			glscal= mul/144;
			optprice=0;
			for(i=0;i<totoption;i++)
			{
				chk=eval("document.shcart.ch_opt_"+i+".checked");
				val=eval("document.shcart.pr_opt_"+i+".value");
				type=eval("document.shcart.type_opt_"+i+".value");
				if(chk==true)
				{
					if(type=='UI')				
						glsprice=uiwin*val;
					else if(type=='SQFT')
						glsprice=glscal*val;
					else if(type=='EACH')
					{
						eachqty=eval("document.shcart.each_opt_price_"+i+".value");
						glsprice=eachqty*val;
					}
					else if(type=='SASH')
						glsprice=val*2;
					else
						glsprice=val*1;
					
					optprice=glsprice+Number(optprice);
					totoptprice=optprice;
				}
			}
			
			price=price*factor;
			
			price+=totoptprice+ship_crg;
			price=price*qty;
			
			document.getElementById('sprice').value=price;
		}
	}
}

function xmlHttp_Get(xmlhttp, url)
{
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}

function GetXmlHttpObject(handler){
	var objXmlHttp = null;
	if (is_ie){
		var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
		try{
			objXmlHttp = new ActiveXObject(strObjName);
			objXmlHttp.onreadystatechange = handler;
		}catch(e){
			alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
			return;
		}
	}else if (is_opera){
		alert('Opera detected. The page may not behave as expected.');
		return;
	}else{
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload = handler;
		objXmlHttp.onerror = handler;
	}
	return objXmlHttp;
}
function LTrim( value ) {				
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
function trim( value ) {	
	return LTrim(RTrim(value));
}
