//servername = 'http://www.4t8.com/tiffinwallah/'; 
//servername = 'http://vv5/first/tiffinwallah/'; 
// CallbackObject
function CallBackObject(){
    this.XmlHttp = this.GetHttpObject();
}
var order=0,meat=0,veg=0,rice=0,other=0;
CallBackObject.prototype.GetHttpObject = function(){
    var xmlhttp;
    /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

CallBackObject.prototype.DoCallBack = function(url, postData)
{
    var theData = '';
    var theform = document.forms[0];
    var thePage = window.location.pathname + window.location.search;
    var eName = '';

    for( eName in postData ){
        if( eName && eName != ''){
            if( eName == 'hometypes[]'){
                for (var k = 0; k <  postData[eName].length; k++){
                    theData = theData + escape(eName.split("$").join(":")) + '=' + postData[eName][k] + '&';
                }
            }
            else {
                theData = theData + escape(eName.split("$").join(":")) + '=' + postData[eName] + '&';
            }
        }
    }

    if( this.XmlHttp ){
        if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 ){
            var oThis = this;
            this.XmlHttp.open('POST', url, true);
            this.XmlHttp.onreadystatechange = function(){
                oThis.ReadyStateChange();
            };
            this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            this.XmlHttp.send(theData);
        }
    }
}

CallBackObject.prototype.AbortCallBack = function()
{
    if( this.XmlHttp )
        this.XmlHttp.abort();
    this.XmlHttp = null;
}

CallBackObject.prototype.OnLoading = function()
{
    // Loading
    }

CallBackObject.prototype.OnLoaded = function()
{
    // Loaded
    }

CallBackObject.prototype.OnInteractive = function()
{
    // Interactive
    }

CallBackObject.prototype.OnComplete = function(responseText, responseXml)
{

    // Complete
    }

CallBackObject.prototype.OnAbort = function()
{
    // Abort
    }

CallBackObject.prototype.OnError = function(status, statusText)
{
    // Error
    }

CallBackObject.prototype.ReadyStateChange = function(){
    if( this.XmlHttp.readyState == 1 ){
        this.OnLoading();
    }
    else if( this.XmlHttp.readyState == 2 ){
        this.OnLoaded();
    }
    else if( this.XmlHttp.readyState == 3 ){
        this.OnInteractive();
    }
    else if( this.XmlHttp.readyState == 4 ){
        if( this.XmlHttp.status == 0 )
            this.OnAbort();
        else if( this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
            this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
        else
            this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);
    }
}
// Callback Object End
//--------------------------------------------------------------------

var cbo = new CallBackObject();

cbo.OnLoading = function() {}
cbo.OnAbort   = function(){
    alert('Request has been aborted');
};
cbo.OnError   = function(status, statusText){ 
    alert('Error - ' + statusText);
};

function el(id) {
    return document.getElementById(id);
}

function findPosX(obj){
    var curleft = 0;
    if (obj.offsetParent) { 
        while (obj.offsetParent) {
            curleft += obj.offsetLeft; obj = obj.offsetParent;
        }
    }
    else if (obj.x) { 
        curleft += obj.x;
    }
    return curleft;
}

function findPosY(obj){
    var curtop = 0;
    if (obj.offsetParent) { 
        while (obj.offsetParent) {
            curtop += obj.offsetTop; obj = obj.offsetParent;
        }
        }
    else if (obj.y) { 
        curtop += obj.y;
    }
    return curtop;
}

function showpopup(obj_reper, codename){


   if((obj_reper=='lnk2' || obj_reper=='lnk3' || obj_reper=='lnk4') && meat==0)
        return alert("Please follow the order selection.\n1) Meat \n2) Vegitable \n3) Rice \n4) Others ");
   
   else if((obj_reper=='lnk3' || obj_reper=='lnk4') && meat==1 && veg==0)
        return alert("Please follow the order selection.\n1) Meat \n2) Vegitable \n3) Rice \n4) Others ");

   else if((obj_reper=='lnk4') && meat==1 && veg==1 && rice==0)
        return alert("Please follow the order selection.\n1) Meat \n2) Vegitable \n3) Rice \n4) Others ");

    

    var obj = el('main_popupdiv');
    obj.style.visibility = "visible";
    obj.style.zIndex=190000;
    obj.style.display="block";
    obj.style.left = parseInt((findPosX(el(obj_reper)) - obj.style.width), 10) + "px";
    obj.style.top  = parseInt((findPosY(el(obj_reper)) + el(obj_reper).offsetHeight), 10) +"px";

    cbo.OnLoading = function(){
        var txt = '<br /><br /><br /><br />Loading ...';
        var loaderDiv = el('popupdiv_msg');
        loaderDiv.innerHTML = '';
        loaderDiv.innerHTML = txt;
    }

    cbo.OnComplete = function(text, xml){
        var loaderDiv = el('popupdiv_msg');
        loaderDiv.innerHTML = text;
    };


    var data = {
        "cmd" : 'sendtofrnd',
        "act" : 'email'
    };

    cbo.DoCallBack(servername+codename, data);

}

function closepopup(){
    var obj = el('main_popupdiv');
    obj.style.visibility = "hidden";
//history.go(0);
}

function chkoptions(elem){
    if (elem.value == ""){
        alert("Please select an option");
        return false;
    }
    return true;
}