var XMLHTTP;
function CreateXMLHTTP(){
	var XMLHTTP;

	try{
		XMLHTTP=null
	}
	catch(e1){}
	try{
		XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc){
			try
			{
				XMLHTTP = new XMLHttpRequest();
			}
			catch(oc1)
			{
				XMLHTTP = null;
			}
		}
	}
	//Creating object in Mozilla and Safari 
	
	if(!XMLHTTP && typeof XMLHttpRequest != "undefined"){
		XMLHTTP = new XMLHttpRequest();
	}
	return (XMLHTTP)
}

function prntH()
{
    alert ('Hello');
}

function setSession(name)
{
    
    var requestUrl="functions.aspx?aspSession="+name ;
    //alert(requestUrl);
	
	XMLHTTPU=CreateXMLHTTP();
	// If browser supports XMLHTTPRequest object
	
	if(XMLHTTPU){
		//Setting the event handler for the response
		//alert(requestUrl);
		
		XMLHTTPU.onreadystatechange = function()
		{
			if (XMLHTTPU.readyState==4){		
				if (XMLHTTPU.status==200){						
					//showData(XMLHTTP.responseText,'SessionDiv');
					//var txt1=document.getElementById("txtSess");
	                //alert(XMLHTTPU.responseText);
	                //return txt1.value;
	               // divItem.innerHTML=txtval;	
	               //alert('Say hello');
				   }
				else{					
					alert("Could not retreive data from the server" );					
				}
			}
			else{
				//alert(showItem);				
				//var divItem=document.getElementById('SessionDiv');
				//divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XMLHTTPU.open("GET", requestUrl);		
		//Sends the request to server
		XMLHTTPU.send(null);		
		
	}
	
}


function displayProduct(prodPrefix,prodCat,prodName){
	// construct the URL
	
	var requestUrl="pssProductSearch.asp?prodPrefix=" + prodPrefix + "&prodCat=" + prodCat+"&prod="+prodName ;
	
	XMLHTTP=CreateXMLHTTP();
	// If browser supports XMLHTTPRequest object
	if(XMLHTTP){
		//Setting the event handler for the response
		//alert(requestUrl);
		XMLHTTP.onreadystatechange = function()
		{
			if (XMLHTTP.readyState==4){		
				if (XMLHTTP.status==200){						
					showData(XMLHTTP.responseText,'divItem');
				}
				else{					
					alert("Could not retreive data from the server" );					
				}
			}
			else{
				//alert(showItem);				
				var divItem=document.getElementById('divItem');
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XMLHTTP.open("GET", requestUrl);		
		//Sends the request to server
		XMLHTTP.send(null);		
	}
}

	

/////////////////////////////////////////
//For Search Product by search text box//
/////////////////////////////////////////
function searchProduct(page,ordBy,order,refineBy){
	//var XMLHTTP;
	var altSearch=document.getElementById("altSearch");
	var txtSearch=altSearch.value;	
	//var htOrderBy=document.getElementById("htOrderBy")
//	var txtOrderBy=htOrderBy.value;
//	var htOrder=document.getElementById("htOrder")
	var txtOrder=order;
	//alert(txtOrder);
	var txtOrderBy=ordBy;
	
	var htCategory=document.getElementById("htCategory")
	var txtCategory=htCategory.value;
	var htManufacturer=document.getElementById("htManufacturer")
	var txtManufacturer=htManufacturer.value;
	var htBrand=document.getElementById("htBrand")
	var txtBrand=htBrand.value;
	var htPrice=document.getElementById("htPrice")
	var txtPrice=htPrice.value;
	var htAction=document.getElementById("htAction")
	var txtAction=htAction.value;
	
	var htgender=document.getElementById("htgender")
	var txtgender=htgender.value;	
	var htclassification=document.getElementById("htclassification")
	var txtclassification=htclassification.value;
	var htstrength=document.getElementById("htstrength")
	var txtstrength=htstrength.value;
	var htusetime=document.getElementById("htusetime")
	var txtusetime=htusetime.value;
	var htseason=document.getElementById("htseason")
	var txtseason=htseason.value;
	var htmatch=document.getElementById("htmatch")
	var txtmatch=htmatch.value;
	
	
	var requestUrl="pssProdSearchAction.asp?search="+txtSearch+"&orderBy="+txtOrderBy+"&order="+txtOrder+"&category="+txtCategory+"&manufacturer="+txtManufacturer+"&brand="+txtBrand+"&price="+txtPrice+"&gender="+txtgender+"&classification="+txtclassification+"&strength="+txtstrength+"&usetime="+txtusetime+"&season="+txtseason+"&match="+txtmatch+"&Action="+txtAction+"&page="+page+"&refineBy="+refineBy+"&Filter=0";
	
	//alert(requestUrl);
	XMLHTTP=CreateXMLHTTP();
	if(XMLHTTP)
	{
		XMLHTTP.onreadystatechange = function()
		{
			
			if (XMLHTTP.readyState==4)
			{		
			
				if (XMLHTTP.status==200){						
					showData(XMLHTTP.responseText,"SearchItem1");	
					//var var1=document.getElementById("pageDiv");
//					var var2=document.getElementById("SearchItem1");
//					
//					var xmlvar1=XMLHTTP.responseXML.documentElement
//					
//					if(xmlvar1!=1)
//					{
//						var xml1=xmlvar1.getElementsByTagName('pageCount');
//						var xml2=xmlvar1.getElementsByTagName('productValue');
//						
//						var1.innerHTML=GetInnerText(xml1[0]);
//						var2.innerHTML=GetInnerText(xml2[0]);
//						alert(xml1[0].textContent);
//						alert(xml2[0].innerText);
//					}
//					else
//					{
//						var1.innerHTML="Error1"
//						var2.innerHTML="Error2"
//					}
				}
				else{
					alert("Could not retreive data from the server" );
					//document.getElementById("lblFindEmployeeStatus").innerHTML="";
				}
			}
			else{
				//var divItem=document.getElementById('SearchItem1');
				//divItem.innerHTML="<img src='images/wait.gif' />";				
				showData("<img src='images/wait.gif' />","SearchItem1");	
			}
		}
		XMLHTTP.open("GET", requestUrl,  false);		
		XMLHTTP.send(null);		
	}
	else
	{
		alert ("Error");
	}
	
}

function getRefineQry()
	{
		var Cmb1=document.getElementById("CmbCategory");
		var Cmb2=document.getElementById("CmbBrand");
		var Cmb3=document.getElementById("CmbPrice");
		retStr='';
		if (Cmb1.value=='--Refine Search--' && Cmb2.value=='--Refine Search--' && Cmb3.value=='--Refine Search--')
			retStr='';
		else
		{
		if (Cmb1.value !='--Refine Search--')
			retStr +=' sectionName=\''+Cmb1.value+'\' and ';
		if (Cmb2.value !='--Refine Search--')
			retStr +=' brandName=\''+Cmb2.value+'\' and ';
		if (Cmb3.value !='--Refine Search--')
			retStr +=' pPrice=\''+Cmb3.value+'\' and ';
			
			retStr=retStr.substring(0,retStr.length-4);			
			
		}
		alert(retStr);
		return (retStr);
	}

function CreateFilter(page,ordBy,order,refineBy){
	var altSearch=document.getElementById("altSearch")
	var txtSearch=altSearch.value;	
	//var htOrderBy=document.getElementById("htOrderBy")
//	var txtOrderBy=htOrderBy.value;
//	var htOrder=document.getElementById("htOrder")
	var txtOrder=order;
	//alert(txtOrder);
	var txtOrderBy=ordBy;
	
	var htCategory=document.getElementById("htCategory")
	var txtCategory=htCategory.value;
	var htManufacturer=document.getElementById("htManufacturer")
	var txtManufacturer=htManufacturer.value;
	var htBrand=document.getElementById("htBrand")
	var txtBrand=htBrand.value;
	var htPrice=document.getElementById("htPrice")
	var txtPrice=htPrice.value;
	var htAction=document.getElementById("htAction")
	var txtAction=htAction.value;
	
	var htgender=document.getElementById("htgender")
	var txtgender=htgender.value;	
	var htclassification=document.getElementById("htclassification")
	var txtclassification=htclassification.value;
	var htstrength=document.getElementById("htstrength")
	var txtstrength=htstrength.value;
	var htusetime=document.getElementById("htusetime")
	var txtusetime=htusetime.value;
	var htseason=document.getElementById("htseason")
	var txtseason=htseason.value;
	var htmatch=document.getElementById("htmatch")
	var txtmatch=htmatch.value;
	
	
	var requestUrl="pssProdSearchAction.asp?search="+txtSearch+"&orderBy="+txtOrderBy+"&order="+txtOrder+
	                "&category="+txtCategory+"&manufacturer="+txtManufacturer+"&brand="+txtBrand+"&price="+
	                txtPrice+"&gender="+txtgender+"&classification="+txtclassification+"&strength="+txtstrength+
	                "&usetime="+txtusetime+"&season="+txtseason+"&match="+txtmatch+"&Action="+txtAction+"&page="+
	                page+"&refineBy="+refineBy+"&Filter=1";
	
	alert(requestUrl);
	XMLHTTP=CreateXMLHTTP();
	if(XMLHTTP)
	{
		XMLHTTP.onreadystatechange = function()
		{
			
			if (XMLHTTP.readyState==4)
			{		
			
				if (XMLHTTP.status==200){						
					showData(XMLHTTP.responseText,"pageDiv");	
    		}
				else{
					alert("Could not retreive data from the server" );
					//document.getElementById("lblFindEmployeeStatus").innerHTML="";
				}
			}
			else{
				//var divItem=document.getElementById('SearchItem1');
				//divItem.innerHTML="<img src='images/wait.gif' />";
				showData("<img src='images/wait.gif' />","pageDiv");	
			}
		}
		XMLHTTP.open("GET", requestUrl,  false);		
		XMLHTTP.send(null);		
	}
	else
	{
		alert ("Error");
	}
	
}

function getRefineQry()
	{
	
		var Cmb1=document.getElementById("CmbCategory");
		var Cmb2=document.getElementById("CmbBrand");
		var Cmb3=document.getElementById("CmbPrice");
		var retStr='';
		if (Cmb1.value=='--Refine Search--' && Cmb2.value=='--Refine Search--' && Cmb3.value=='--Refine Search--')
			retStr='';
		else
		{
			//retStr='and ';
		if (Cmb1.value !='--Refine Search--')
			retStr +=' sectionName=\''+Cmb1.value+'\' and ';
		if (Cmb2.value !='--Refine Search--')
			retStr +=' brandName=\''+Cmb2.value+'\' and ';
		if (Cmb3.value !='--Refine Search--')
			retStr +=' pPrice=\''+Cmb3.value+'\' and ';
			
			retStr =retStr.substring(0,retStr.length-4);
			retStr = 'and ' + retStr.toString();			
			
		}
		
		//retStr=" sectionName='Man'";
		//alert(retStr);
		return (retStr);
	}
	
function showData(txtval,showItem){
	var divItem=document.getElementById(showItem);
	divItem.innerHTML="";
	divItem.innerHTML=txtval;	
}

function fillQuestion(qid,Act){
		window.open ('pssAdminReviewQ.asp?Qid='+qid+"&act="+Act);
}

function fillQuestion11(qid,act){
	alert ('Qid=' + qid);
	document.mainform.action="pssAdminReviewQ.asp";
	document.mainform.qid.value = id;
	document.mainform.Act.value = act;
	//document.mainform.posted.value = "1";
	document.mainform.submit();
}

function GetInnerText(node){
	 return (node.textContent || node.innerText || node.text) ;
}

//////////////////////////////////////////
//Script for Product Advance Search////////
///////////////////////////////////////////

function fillCategoryCombo()
{
	var requestUrl="pssAdvSearchAction.asp?Action=fillcatcmb";
	
	XMLHTTP=CreateXMLHTTP();
	if(XMLHTTP)
	{
		XMLHTTP.onreadystatechange = function()
		{
			if (XMLHTTP.readyState==4)
			{		
				if (XMLHTTP.status==200){						
					showData(XMLHTTP.responseText,"CatDiv");				
				}
				else{
					alert("Could not retreive data from the server" );
					//document.getElementById("lblFindEmployeeStatus").innerHTML="";
				}
			}
			else{
				var divItem=document.getElementById("CatDiv");
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		XMLHTTP.open("GET", requestUrl);		
		XMLHTTP.send(null);		
	}
	else
	{
		alert ("Error");
	}
}

function fillBrandCombo()
{
	var requestUrl="pssAdvSearchAction.asp?Action=fillbrandcmb";
	
	XMLHTTP=CreateXMLHTTP();
	if(XMLHTTP)
	{
		XMLHTTP.onreadystatechange = function()
		{
			if (XMLHTTP.readyState==4)
			{		
				if (XMLHTTP.status==200){						
					showData(XMLHTTP.responseText,"BrandDiv");	
					alert('In BrandCmb');
				}
				else{
					alert("Could not retreive data from the server" );
					//document.getElementById("lblFindEmployeeStatus").innerHTML="";
				}
			}
			else{
				var divItem=document.getElementById("BrandDiv");
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		XMLHTTP.open("GET", requestUrl,  false);		
		XMLHTTP.send(null);		
	}
	else
	{
		alert ("Error");
	}
}


function fillBrandComboAS()
{
	var requestUrl="pssAdvSearchAction.asp?Action=fillbrandcmbAS";
	
	XMLHTTPBrd=CreateXMLHTTP();
	if(XMLHTTPBrd)
	{
		XMLHTTPBrd.onreadystatechange = function()
		{
			if (XMLHTTPBrd.readyState==4)
			{		
				if (XMLHTTPBrd.status==200){						
					showData(XMLHTTPBrd.responseText,"BrandDiv");				
				}
				else{
					alert("Could not retreive data from the server" );
					//document.getElementById("lblFindEmployeeStatus").innerHTML="";
				}
			}
			else{
				var divItem=document.getElementById("BrandDiv");
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		XMLHTTPBrd.open("GET", requestUrl);		
		XMLHTTPBrd.send(null);		
	}
	else
	{
		alert ("Error");
	}
}


function searchAdv(){
	var txtSearchVal1=document.getElementById("txtSearch2")
	var txtval=txtSearchVal1.value;	
	
	var txtOrdBy=document.getElementById("txtOrdBy")
	var txtOrdBy=txtOrdBy.value;	
	
	var txtOrd=document.getElementById("txtOrd")
	var txtOrd=txtOrd.value;
	
	var keyword=document.getElementById("keyword");	
	var category=document.getElementById("category");
	var price=document.getElementById("price");
	
	keyword=keyword.value;
	category=category.value;
	price=price.value;
	
	//window.location="pssProdSearch.asp?oBy="+oBy+"&order="+ord+"&search="+txtSearchVal.value;	
	var requestUrl="pssProdSearchAction.asp?Action=advsearch&oBy="+txtOrdBy+"&order="+txtOrd+"&search="+txtval+"&keyword="+keyword+"&category="+category+"&price="+price;
	
	//alert(requestUrl);
	
	XMLHTTP=CreateXMLHTTP();
	if(XMLHTTP)
	{
		XMLHTTP.onreadystatechange = function()
		{
			if (XMLHTTP.readyState==4)
			{		
				if (XMLHTTP.status==200){						
					showData(XMLHTTP.responseText,"SearchItem1");				
				}
				else{
					alert("Could not retreive data from the server" );
					//document.getElementById("lblFindEmployeeStatus").innerHTML="";
				}
			}
			else{
				var divItem=document.getElementById("SearchItem1");
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		XMLHTTP.open("GET", requestUrl,  false);		
		XMLHTTP.send(null);		
	}
	else
	{
		alert ("Error");
	}

}	

function cleartextbox()
   {
	var txtbox=document.getElementById("search");
	txtbox.value='';
	}
function fillManufacturerCombo()
{
	var requestUrl="pssAdvSearchAction.asp?Action=fillmanufacturercmb";
	
	XMLHTTPMF=CreateXMLHTTP();
	if(XMLHTTPMF)
	{
		XMLHTTPMF.onreadystatechange = function()
		{
			if (XMLHTTPMF.readyState==4)
			{		
				if (XMLHTTPMF.status==200){						
					showData(XMLHTTPMF.responseText,"manufacturerDiv");				
				}
				else{
					alert("Could not retreive data from the server" );
				}
			}
			else{
				var divItem=document.getElementById("manufacturerDiv");
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		XMLHTTPMF.open("GET", requestUrl);		
		XMLHTTPMF.send(null);		
	}
	else
	{
		alert ("Error");
	}
	
}


	function review(prodid){
		var requestUrl="pssReviewAction.asp?prod="+ prodid +"&action=srev"
		
		XMLHTTP=CreateXMLHTTP();
		// If browser supports XMLHTTPRequest object
		if(XMLHTTP){
			//Setting the event handler for the response
			//alert(requestUrl);
			XMLHTTP.onreadystatechange = function()
			{
				if (XMLHTTP.readyState==4){		
					if (XMLHTTP.status==200){						
						showData(XMLHTTP.responseText,'revDiv');
					}
					else{					
						alert("Could not retreive data from the server" );					
					}
				}
				else{
					//alert(showItem);				
					var divItem=document.getElementById('revDiv');
					divItem.innerHTML="<img src='images/wait.gif' />";	
				}
			}
			//Initializes the request object with GET (METHOD of posting), 
			//Request URL and sets the request as asynchronous.
			XMLHTTP.open("GET", requestUrl, true);		
			//Sends the request to server
			XMLHTTP.send(null);		
		}
	}
	
	
	function wealsorecommendforman(section,menufacturer,brand,divName){
	var XMLHTTP2
	var requestUrl="psswealsorecommendaction.asp?section=" + section + "&mf=" + menufacturer+"&brand="+brand ;
	
	XMLHTTP2=CreateXMLHTTP();
	// If browser supports XMLHTTPRequest object
	if(XMLHTTP2){
		//Setting the event handler for the response
		//alert(requestUrl);
		XMLHTTP2.onreadystatechange = function()
		{
			if (XMLHTTP2.readyState==4){		
				if (XMLHTTP2.status==200){						
					showData(XMLHTTP2.responseText,divName.toString());
				}
				else{					
					alert("Could not retreive data from the server" );					
				}
			}
			else{			
				alert(XMLHTTP2.onreadystatechange);
				var divItem=document.getElementById(divName.toString());
				divItem.innerHTML="<img src='images/wait.gif' />";	
			}
		}
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XMLHTTP2.open("GET", requestUrl, true);		
		//Sends the request to server
		XMLHTTP2.send(null);		
	}
	//return 1;
}
