/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 
/*
function getCatO(){
//selVal=document.frm.city_name.options[document.frm.city_name.selectedIndex].value;

http.open('get', '1.php?cc=Others');


http.onreadystatechange = handleSC1; 
http.send(null);
}
*/

var dTime = new Date();
tim=dTime.setHours(dTime.getHours(),dTime.getMinutes(),dTime.getSeconds());

function selectUrgency1(){
selVal=document.order.documenttype.value;
//alert(selVal);
http.open('get', 'profList1.php?noday='+selVal+"&ti="+tim);
http.onreadystatechange = handleSC1; 
http.send(null);
}

/*function profDet(){
selVal=document.faculty.prof.options[document.faculty.prof.selectedIndex].value;

http.open('get', 'profDetails.php?cat='+selVal+"&ti="+tim);
http.onreadystatechange = handleSC2; 
http.send(null);
}*/

function selectLevel1(){
//selVal=document.findprice.worktype.options[document.findprice.worktype.selectedIndex].value;
selVal=document.order.documenttype.value;
//alert(selVal);
http.open('get', 'profLevel1.php?noday='+selVal+"&ti="+tim);
http.onreadystatechange = handleSC2; 
http.send(null);

}


function calTotal(){
//selVal=document.findprice.worktype.options[document.findprice.worktype.selectedIndex].value;
selVal=document.order.price.value;
nopage=document.order.noofpage.value;
//alert('price='+selVal);
//alert('page='+nopage)
	var tot=selVal*nopage;
//alert('total='+tot);
document.order.tot.value=tot;
//http.onreadystatechange = handleSC4; 
//http.send(null);
calDiscount()
}


function calPrice1(){
//selVal=document.findprice.worktype.options[document.findprice.worktype.selectedIndex].value;
wrkVal=document.order.documenttype.value;
urgVal=document.order.urgency.value;
lvlVal=document.order.academic.value;
nopage=document.order.noofpage.value;
//alert(wrkVal);
//alert(urgVal);
//alert(lvlVal);
http.open('get', 'calPrice1.php?wrkVal='+wrkVal+"&urgVal="+urgVal+"&lvlVal="+lvlVal+"&nopage="+nopage+"&ti="+tim);

http.onreadystatechange = handleSC3; 
http.send(null);
				
//calDiscount()				
				
}

function calDiscount(){
//selVal=document.findprice.worktype.options[document.findprice.worktype.selectedIndex].value;
wrkVal=document.order.documenttype.value;
urgVal=document.order.urgency.value;
lvlVal=document.order.academic.value;
nopage=document.order.noofpage.value;

//alert(wrkVal);
//alert(urgVal);
//alert(lvlVal);
http.open('get', 'calDiscount.php?wrkVal='+wrkVal+"&urgVal="+urgVal+"&lvlVal="+lvlVal+"&nopage="+nopage+"&ti="+tim);

http.onreadystatechange = handleSC4; 
http.send(null);				
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleSC1(){
	//alert("sankar");
	obj='urgency';//object name
	if(http.readyState == 1){//load(obj);nosub(obj);
	}
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		//
			if (response=="")
			{//alert(response+"ssss");
				nosub(obj);	//nosub(obj1);//getLov();	//	load(obj2)
				t1=setTimeout("selectLevel1()",200);
			}else{

				pop(response,obj);
				t1=setTimeout("selectLevel1()",200);
			}
	}
}


function handleSC2(){
	
	obj='academic';//object name
	if(http.readyState == 1){
		//load(obj);nosub(obj);
		}
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
			if (response=="")
			{//alert(response+"ssss2");
				nosub(obj);	//nosub(obj1);//getLov();	//	load(obj2)
			}else{
//alert(response);
				pop(response,obj);
			}
	}
}


function handleSC3(){
	
	
	if(http.readyState == 1){};
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
			if (response=="")
			{
			//	nosub(obj);//	nosub(obj1);//getLov();	//	load(obj2)
			}else{
			//	alert(response);
				
				//document.getElementById('pDetails').innerHTML='$'+response;
				document.order.price.value=response;
				
				calTotal();
				
			}
	}
}

function handleSC4(){
	
	
	if(http.readyState == 1){};
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
			if (response=="")
			{
			//	nosub(obj);//	nosub(obj1);//getLov();	//	load(obj2)
			}else{
			//	alert(response);
				
				//document.getElementById('pDetails').innerHTML='$'+response;
				document.order.dis.value=response;
				
			}
	}
}


/*function handleSC2(){
	
	
	if(http.readyState == 1){};
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
			if (response=="")
			{
			//	nosub(obj);//	nosub(obj1);//getLov();	//	load(obj2)
			}else{
			//	alert(response);
				
				document.getElementById('pDetails').innerHTML=response;
			}
	}
}*/

///////////////////////////////////////////////////////////////////////////////////////////

// No need to edit below this	

function pop(st1,obj)
{
		selNum=1;

		var selbox = eval('document.order.'+ obj);//eval('document.frm.s' + cnt);
		selbox.length=0;



	opt11 = "Select"; // for assigning thedefault value


			var opt = new Option(opt11,""); // for assigning thedefault value
		selbox.options[0] = opt;
			optStr=st1.split("~");



                        for (i=0;i<optStr.length - 1; i++)
                        {
							
							optStr1=optStr[i].split("#$");
						
                        var optText=optStr1[0];
                        var optVal=optStr1[1];
                        var opt = new Option(optText,optVal);

                        selbox.options[selNum] = opt;opt.selected;
                        selNum=selNum+1;
						
                        }
selbox.disabled=0;
}



function load(obj)
{
		var selbox = eval('document.order.'+ obj);
		selbox.length=0;

		var opt = new Option("Loading....",""); // for assigning thedefault value
		selbox.options[0] = opt;
		
		selbox.disabled=1;
}

function nosub(obj)
{
		var selbox = eval('document.order.'+ obj);
		selbox.length=0;

		var opt = new Option("No Value",""); // for assigning thedefault value
		selbox.options[0] = opt;
		
		selbox.disabled=1;
}


