/*function ShowPurchase(CampaignID)
{
//alert(CampaignID);
     document.getElementById("divCoupon").style.display="none";
      document.getElementById("divpurchase").removeAttribute("style");
     document.getElementById("divpurchase").style.display="";
	document.getElementById("ifrmPurchase").src="http://"+document.domain+"/BusinessDetails/PurchaseCoupon.aspx?CampaignID="+CampaignID;
}*/
 /*
 function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}

var QueryString='';

if(getQueryVariable('DealCityID')!=null)
{
QueryString='?DealCityID='+getQueryVariable('DealCityID');
}
else if(getQueryVariable('RestaurantInfoID')!=null)
{
QueryString='?RestaurantInfoID='+getQueryVariable('RestaurantInfoID');
}
*/

var PageURL="";

 var scriptsSO = document.getElementsByTagName('script');
 var iSO=0;

 var indexSO = scriptsSO.length - 1;

 for(iSO=0;iSO<scriptsSO.length;iSO++)
    {
    if(scriptsSO[iSO].src.indexOf('SiteOwner.js')!=-1)
      {
      indexSO =iSO;
      }
    }
 
 var myScriptSO = scriptsSO[indexSO];
     
 var qsSO=myScriptSO.src.replace(/^[^\?]+\??/,'');
 
var FlagSO=0;    
    function UpdateBuyerStatus()
    {
       //temp document.getElementById('btnTotalSold').click();
//       alert("http://www."+document.domain+"/DotD/DotDProcess.aspx?"+qs);

        //loadXMLDocB("http://"+document.domain+"/BusinessOwners/CheckBuyerSession.aspx?"+qsSO);//+"&dt="+Date());
	
			loadXMLDocB(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?"+qsSO);//+"&dt="+Date());
		
    }

function SignOut(DotDBuyerID)
{
        //loadXMLDocSignOut("http://"+document.domain+"/BusinessOwners/CheckBuyerSession.aspx?DotDBuyerID="+DotDBuyerID);//+"&dt="+Date());
        
        loadXMLDocSignOut(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?DotDBuyerID="+DotDBuyerID);//+"&dt="+Date());
               
        SignIn();
}

function SignUp()
{
	 //loadXMLDocSignOut("http://"+document.domain+"/BusinessOwners/CheckBuyerSession.aspx?LogInType=2");
	 loadXMLDocSignOut(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?LogInType=2");

loadXMLDocSignUp(window.location.protocol+"//"+document.domain+"/BusinessDetails/GetDealPageURLForSiteOwner.aspx?RestaurantInfoID="+document.getElementById('hdnRestaurantInfoID').value);	

	//pause(5000);
//	 alert("1"+PageURL);

}
	
function SignIn()
{
 	//loadXMLDocSignOut("http://"+document.domain+"/BusinessOwners/CheckBuyerSession.aspx?LogInType=1");
 	
 		loadXMLDocSignOut(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?LogInType=1");
 		loadXMLDocSignIn(window.location.protocol+"//"+document.domain+"/BusinessDetails/GetDealPageURLForSiteOwner.aspx?RestaurantInfoID="+document.getElementById('hdnRestaurantInfoID').value);	
 	
		//pause(5000);  
	// alert("2"+PageURL);
	
	 
}
function Statistics()
{
 	//loadXMLDocSignOut("http://"+document.domain+"/BusinessOwners/CheckBuyerSession.aspx?LogInType=1");
 	
 	loadXMLDocSignOut(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?LogInType=3");
 	loadXMLDocSignIn(window.location.protocol+"//"+document.domain+"/BusinessDetails/GetDealPageURLForSiteOwner.aspx?RestaurantInfoID="+document.getElementById('hdnRestaurantInfoID').value);	
		//pause(5000);  
	// alert("2"+PageURL);
	
	 
}
	
	function pause(millisecondi)
    {
        var now = new Date();
        var exitTime = now.getTime() + millisecondi;

        while(true)
        {
            now = new Date();
            if(now.getTime() > exitTime) return;
        }
    }
    
function StartBuyerUpdate()
{
			if(FlagSO==0)
			{       
		setInterval('UpdateBuyerStatus();',1055);
			FlagSO=1;
			}
 }  
    
var reqB;

function loadXMLDocB(url) {
	reqB = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			reqB = new XMLHttpRequest();
        } catch(e) {
			reqB = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	reqB = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqB = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqB = false;
        	}
		}
    }
	if(reqB) {
	
		reqB.onreadystatechange = processReqChangeB;
		reqB.open("GET", url, true);
		reqB.send("");
		
		
	}
}

function processReqChangeB() {
    // only if req shows "loaded"
    if (reqB.readyState == 4) {
        // only if "OK"

        if (reqB.status == 200) {
	        	//alert(reqB.responseText);    
	        	var strDataB= new String(reqB.responseText);
	        	//alert(strDataB);
	        	  var DataB=strDataB.split('|');
	        	 // alert(Data[2]);
	        	 
	        	  
	        	try{  		
       		  
       		  
       		  document.getElementById("divBuyerStatus").innerHTML=(DataB[0]=="1"?"Logged in as "+DataB[2]:"");
       		  
       		  document.getElementById("divBuyerLinks").innerHTML=(DataB[0]=="1"?"<span style='cursor:pointer;cursor:hand;' onclick='Statistics();'>My Account</span>"+" | <span style='cursor:pointer;cursor:hand;' onclick='SignOut("+DataB[1]+")'>Sign Out</span>":"<span style='cursor:pointer;cursor:hand;' onclick='SignUp();'>Sign Up</span>"+" | <span style='cursor:pointer;cursor:hand;' onclick='SignIn();'>Sign In</span>");
       		  
       		  
       		  
       		 
       		   }
       		   catch(ex)
       		   {}
            // ...processing statements go here...
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
        
	//alert(req.responseText);
         
    }
}

function loadXMLDocSignOut(url) {
	reqSO = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			reqSO = new XMLHttpRequest();
        } catch(e) {
			reqSO = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	reqSO = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqSO = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqSO = false;
        	}
		}
    }
	if(reqSO) {
		reqSO.onreadystatechange = processReqChangeSignOut;
		reqSO.open("GET", url, true);
		reqSO.send("");
		
	}
}

function processReqChangeSignOut() {
    // only if req shows "loaded"
    if (reqSO.readyState == 4) {
        // only if "OK"

        if (reqSO.status == 200) {
	        
	        PageURL=reqSO.responseText;
	        
            // ...processing statements go here...
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
        
	//alert(req.responseText);
         
    }
}

function loadXMLDocSignIn(url) {
	reqIn = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			reqIn = new XMLHttpRequest();
        } catch(e) {
			reqIn = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	reqIn = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqIn = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqIn = false;
        	}
		}
    }
	if(reqIn) {
		reqIn.onreadystatechange = processReqChangeSignIn;
		reqIn.open("GET", url, true);
		reqIn.send("");
		
	}
}

function processReqChangeSignIn() {
    // only if req shows "loaded"
    if (reqIn.readyState == 4) {
        // only if "OK"

        if (reqIn.status == 200) {
	        
	        PageURL=reqIn.responseText;
	        if(window.location.protocol!="https:")
			{
	        	window.open("http://"+document.domain+"/Businesses/"+PageURL,"_self");
	        }
	        else
	        {
	        	if(document.getElementById('hdnSourceURL') != null && document.getElementById('hdnSourceURL').value != "")
	        	{
	        	
	        		loadXMLDocForDataV(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?RestaurantInfoID="+document.getElementById('hdnRestaurantInfoID').value+"&"+qsSO);//+"&dt="+Date());
	        		
	        		//window.open("http://"+document.getElementById('hdnSourceURL').value+"/Businesses/"+PageURL,"_self");
	        	}
	        }

            // ...processing statements go here...
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
        
	//alert(req.responseText);
         
    }
}

function loadXMLDocSignUp(url) {
	reqUp = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			reqUp = new XMLHttpRequest();
        } catch(e) {
			reqIn = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	reqUp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqUp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqUp = false;
        	}
		}
    }
	if(reqUp) {
		reqUp.onreadystatechange = processReqChangeSignUp;
		reqUp.open("GET", url, true);
		reqUp.send("");
		
	}
}

function processReqChangeSignUp() {
    // only if req shows "loaded"
    if (reqUp.readyState == 4) {
        // only if "OK"

        if (reqUp.status == 200) {
	        
	        PageURL=reqUp.responseText;
	        if(window.location.protocol!="https:")
			{
	         window.open("http://"+document.domain+"/Businesses/"+PageURL,"_self");
	        }
	        else
	        {
	        	if(document.getElementById('hdnSourceURL') != null && document.getElementById('hdnSourceURL').value != "")
	        	{
	        	
	        		loadXMLDocForDataV(window.location.protocol+"//"+document.domain+"/BusinessDetails/CheckBuyerSession.aspx?RestaurantInfoID="+document.getElementById('hdnRestaurantInfoID').value+"&"+qsSO);//+"&dt="+Date());
	        		
	        		//window.open("http://"+document.getElementById('hdnSourceURL').value+"/Businesses/"+PageURL,"_self");
	        	}
	        }
            // ...processing statements go here...
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
        
	//alert(req.responseText);
         
    }
}


//New Pulak

var reqForDataV;

function loadXMLDocForDataV(url) {
	reqForDataV= false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			reqForDataV= new XMLHttpRequest();
        } catch(e) {
			reqForDataV= false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	reqForDataV= new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqForDataV= new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqForDataV= false;
        	}
		}
    }
	if(reqForDataV) {
		reqForDataV.onreadystatechange = processReqChangeForDataV;
		reqForDataV.open("GET", url, true);
		reqForDataV.send("");
		
	}
}

function processReqChangeForDataV() {
    // only if req shows "loaded"
    if (reqForDataV.readyState == 4) {
        // only if "OK"

        if (reqForDataV.status == 200) {
	        	//alert(reqB.responseText);    
	        	var strDataForDataV= new String(reqForDataV.responseText);
	        	//alert(strDataB);
	        	  var DataForDataV=strDataForDataV.split('|');
	        	 // alert(Data[2]);
	        	 //alert(strDataForDataV);
	        	  
	        	try{  		
       		  
       		  		if(DataForDataV.length>3)
       		  		{
       		  			var Data = "";
       		  			for(i=3; i<DataForDataV.length; i++)
       		  			{
       		  				if(i<DataForDataV.length-1)
       		  				{
       		  					Data += DataForDataV[i]+"|";
       		  				}
       		  				else
       		  				{
       		  					Data += DataForDataV[i];
       		  				}
       		  				
       		  			}
       		  			window.open("http://"+document.getElementById('hdnSourceURL').value+"/BusinessDetails/SecureSession.aspx?Data="+Data,"_self");
       		 		}
       		   }
       		   catch(ex)
       		   {}
            // ...processing statements go here...
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
        
	//alert(req.responseText);
         
    }
}


