var xmlHttp;
var AdFirst;
var requestURL;
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;
var TrID;
var TrName;
var INC;
var RenewURL;
 
 var strURL = window.location.href.split("/");
 var tempstrURL=(strURL.length)-1;
 var URL="";
  for(var i=0;i<tempstrURL;i++){
		URL+=strURL[i];
		URL+="/";
 }

function changecouponcode(HURL){
		RenewURL=HURL;
		var CouponCode=document.getElementById("CouponCode").value
 		requestURL = HURL+'include/check_coupon_code.php?CouponCode='+CouponCode; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerCoupon);
		xmlHttp_Get(xmlHttp, url);
}

function stateChangeHandlerCoupon()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		//alert(str);
		if(str!=""){
 			location.href=RenewURL+str;
		}
		//document.getElementById(DIVNAME1).innerHTML = document.getElementById(DIVNAME1).innerHTML+str;
	}
}

function checkemailid(HURL,EmailID,TrName,CourseID){
		DIVFOREMAIL = TrName;
	requestURL = HURL+'include/check_email.php?EmailID='+EmailID+'&TrName='+TrName+'&CourseID='+CourseID; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerCheckEmail);
		xmlHttp_Get(xmlHttp, url);
}

function stateChangeHandlerCheckEmail()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		//alert(str);
		if(str!=""){
 			document.getElementById(DIVFOREMAIL).style.display='';
		} else {
			document.getElementById(DIVFOREMAIL).style.display='none';
		}
		//document.getElementById(DIVNAME1).innerHTML = document.getElementById(DIVNAME1).innerHTML+str;
	}
}

function showstateforshipping(HURL,CountryID,SelectedState){
 	if(CountryID){
 		requestURL = HURL+'include/show_state.php?CountryID='+CountryID+'&SelectedState='+SelectedState; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerShipStates);
		xmlHttp_Get(xmlHttp, url);
		if(document.getElementById('ShowState'))
		 document.getElementById('ShowState').style.display='';
	}
	if(CountryID==14){
		if(document.getElementById('TrGST'))
		document.getElementById('TrGST').style.display='';
	} else {
		if(document.getElementById('TrGST'))
		document.getElementById('TrGST').style.display='none';
	}
	if(CountryID==99999){
		if(document.getElementById('OtherCountry'))
		document.getElementById('OtherCountry').style.display='';
	} else {
		if(document.getElementById('OtherCountry'))
		document.getElementById('OtherCountry').style.display='none';
	}
	
}

function stateChangeHandlerShipStates()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		CartArr = str.split('^');
 		/*alert(CartArr[1]);
		alert(CartArr[2]);
		alert(CartArr[3]);
		alert(CartArr[4]);
		alert(CartArr[5]);
		alert(CartArr[6]);*/
		if(document.getElementById('ShowState'))
 			document.getElementById('ShowState').innerHTML = CartArr[0];
		if(document.getElementById('SubTotalAmount'))
			document.getElementById('SubTotalAmount').innerHTML = '<strong>$'+CartArr[1]+'</strong>';
		if(document.getElementById('ShippingAmount'))
			document.getElementById('ShippingAmount').innerHTML = '<strong>$'+CartArr[2]+'</strong>';
		if(document.getElementById('GSTAmount'))
			document.getElementById('GSTAmount').innerHTML = '<strong>$'+CartArr[3]+'</strong>';
		if(document.getElementById('TotalFinalAmount'))
			document.getElementById('TotalFinalAmount').innerHTML = '<strong>$'+CartArr[4]+'</strong>';
		if(document.getElementById('DiscountMembershipPrice'))
			document.getElementById('DiscountMembershipPrice').innerHTML = '<strong>$'+CartArr[5]+'</strong>';
		
		for(var i=6;i<CartArr.length;i=i+3){
				document.getElementById('ActualAmount_'+CartArr[i]).innerHTML = '$'+CartArr[i+1]+'';
				document.getElementById('Amount_'+CartArr[i]).innerHTML = '$'+CartArr[i+2]+'';
		}
	 
	}
}


function Change_Status(Status,ID,Type)
{ 
  	if (ID)
	{
		DIVNAME = "CheckStatus_"+ID;
		document.getElementById("LoaderDiv").style.display='';
 		requestURL = 'include/change_status.php?Status='+Status+'&ID='+ID+'&Type='+Type; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandler1);
		xmlHttp_Get(xmlHttp, url);
	}
	else 
	{
		alert('Invalid data');
	}
}
function Change_Member_Status(Status,ID)
{ 
  	if (ID)
	{
		DIVNAME = "CheckStatus_"+ID;
		document.getElementById("LoaderDiv").style.display='';
 		requestURL = 'include/change_member_status.php?Status='+Status+'&ID='+ID; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerMember);
		xmlHttp_Get(xmlHttp, url);
	}
	else 
	{
		alert('Invalid data');
	}
}
function stateChangeHandlerMember()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		//alert(str);
		
		//alert(DIVNAME1);
		document.getElementById(DIVNAME).innerHTML = str
		document.getElementById("LoaderDiv").style.display='none';
		//document.getElementById(DIVNAME1).innerHTML = document.getElementById(DIVNAME1).innerHTML+str;
	}
}

 function FillStates(Type,CountryID,SelectedState,HURL)
{ 
  	if (CountryID)
	{
		  
		if(Type==1)
		   divname='TDBillState';
		else if(Type==2)
		   divname='TDShipState';
		else if(Type==3)
		   divname='TrState';
		else if(Type==4)
		   divname='TrStateBackEnd';   
		    
		
 		requestURL = HURL+'include/fill_states.php?CountryID='+CountryID+'&Type='+Type+'&SelectedState='+SelectedState; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerStates);
		xmlHttp_Get(xmlHttp, url);
	}
	else 
	{
		alert('Invalid data');
	}
}

function stateChangeHandlerStates()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		 
	 
		document.getElementById(divname).innerHTML = str;
	   
			   
	}
}
 

 function FillStatesBackEnd(Type,CountryID,SelectedState)
{ 
  	if (CountryID)
	{
		  if(Type==4)
		   divname='TrStateBackEnd';   
		   
		   
		
 		requestURL = '../include/fill_states.php?CountryID='+CountryID+'&Type='+Type+'&SelectedState='+SelectedState; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerStatesBackEnd);
		xmlHttp_Get(xmlHttp, url);
	}
	else 
	{
		alert('Invalid data');
	}
}
function stateChangeHandlerStatesBackEnd()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		 
		document.getElementById(divname).innerHTML = str
	 
	}
}
 
function stateChangeHandler1()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		//alert(str);
		
		//alert(DIVNAME1);
		document.getElementById(DIVNAME).innerHTML = str
		document.getElementById("LoaderDiv").style.display='none';
		//document.getElementById(DIVNAME1).innerHTML = document.getElementById(DIVNAME1).innerHTML+str;
	}
}

function changecurency(HURL,URL,CurrencyPrice){
		requestURL = HURL+'include/change_currency.php?CurrencyPrice='+CurrencyPrice+'&URL='+URL;
 		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerSetCurrency);
		xmlHttp_Get(xmlHttp, url);	
}
function stateChangeHandlerSetCurrency(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		location.href=str;
   	}	
}
function addproduct(HURL,ProductID,URLPATH){
		//alert(URLPATH);
		requestURL = HURL+'include/addproduct.php?ProductID='+ProductID+'&URLPATH='+URLPATH;
 		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandlerAddProduct);
		xmlHttp_Get(xmlHttp, url);
}
function updateCartQty(Qty,pId)
{ 
  if (pId)
	{
		requestURL = 'include/updatecartqty.php?Qty='+Qty+'&pId='+pId; 
		//alert(requestURL);
		var url = requestURL;
		xmlHttp = GetXmlHttpObject(stateChangeHandler3);
		xmlHttp_Get(xmlHttp, url);
	}
	else 
	{
		alert('Invalid data');
	}
}
function stateChangeHandlerAddProduct(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
 			//alert(str);
			location.href=str;
   	}	
}
function stateChangeHandler3()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	{
		var str = xmlHttp.responseText;
		CartArr = str.split('^');
 		document.getElementById('Amount_'+CartArr[1]).innerHTML = '$'+CartArr[2];
		document.getElementById('ActualAmount_'+CartArr[1]).innerHTML = '$'+CartArr[3];
 		//document.getElementById('RightMenuQty_'+CartArr[1]).innerHTML=CartArr[5];
		//document.getElementById('RightMenuPrice_'+CartArr[1]).innerHTML = '$&nbsp;'+CartArr[2];
		//document.getElementById('RightMenuTotalPrice').innerHTML = '<strong>$'+CartArr[4]+'</strong>';
		document.getElementById('SubTotalAmount').innerHTML = '<strong>$'+CartArr[6]+'</strong>';
		document.getElementById('ShippingAmount').innerHTML = '<strong>$'+CartArr[7]+'</strong>';
		document.getElementById('GSTAmount').innerHTML = '<strong>$'+CartArr[8]+'</strong>';
		document.getElementById('TotalFinalAmount').innerHTML = '<strong>$'+CartArr[9]+'</strong>';
		document.getElementById('DiscountMembershipPrice').innerHTML = '<strong>$'+CartArr[10]+'</strong>';
		document.getElementById('MultiMembershipDiscount').innerHTML = '<strong>$'+CartArr[11]+'</strong>';
		
	}
}
function xmlHttp_Get(xmlhttp, url)
{
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}
function xmlHttp_Post(xmlhttp, url,params)
{
	xmlhttp.open('POST', 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;
}