var xmlHttp;
function getXmlHttpObject( handler ) {
    var objXmlHttp=null

    if ( navigator.userAgent.indexOf( "Opera" ) >= 0 ) {
        alert( "This example doesn't work in Opera" )
        return
    }
    if ( navigator.userAgent.indexOf( "MSIE" ) >=0 ) {
        var strName="Msxml2.XMLHTTP"
        if ( navigator.appVersion.indexOf( "MSIE 5.5" ) >= 0 ){
            strName = "Microsoft.XMLHTTP"
        }
        try{ 
            objXmlHttp = new ActiveXObject( strName )
            objXmlHttp.onreadystatechange = handler
            return objXmlHttp
        }catch( e ) { 
            alert( "Error. Scripting for ActiveX might be disabled" )
            return
        }
    }
    if ( navigator.userAgent.indexOf( "Mozilla" ) >= 0 ) {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
    }
}

function ValidateUsername(username) {
        var url = '../ajaxbroker.php?action=validateusername&username=' + username;
        xmlHttp=getXmlHttpObject(handleValidateUsername);
        xmlHttp.open( "GET", url , true);
        xmlHttp.setRequestHeader("If-Modified-Since","0"); 
        xmlHttp.send( null );
}

function handleValidateUsername() {
    if ( xmlHttp.readyState==4 || xmlHttp.readyState=="complete" ) { 
        if (xmlHttp.responseText && xmlHttp.responseText != ''){
            document.getElementById("username_error").innerHTML = "User Name already exists.";
            document.getElementById("validate_username").value = 1;
        }
        else
        {
            document.getElementById("username_error").innerHTML = "";
            document.getElementById("validate_username").value = ""
        }
    }
}
function ValidateRestaurantNum(username, from) {
        var url = 'ajaxbroker.php?action=validaterestaurantnum&username=' + username +'&from='+from;
        xmlHttp=getXmlHttpObject(handleRestaurantNum);
        xmlHttp.open( "GET", url , false);
        xmlHttp.setRequestHeader("If-Modified-Since","0"); 
        xmlHttp.send( null );
}

function handleRestaurantNum() {
    if ( xmlHttp.readyState==4 || xmlHttp.readyState=="complete" ) { 
        eval(xmlHttp.responseText)
        if (res_ar)
        {
            if (parseInt(res_ar[1]) >= parseInt(res_ar[0])){
                alert("You may have up to "+ res_ar[0] +" active restaurants.  You currently have " + res_ar[1] + " active in the database.")
            }
            else
                window.location = "addRestaurant.php";
        }
     }
}

function getFlash(v){
    var url = 'ajaxbroker.php?action=flashcolor&flash_color='+v;
    xmlHttp=getXmlHttpObject(handleLoadFlash);
    xmlHttp.open( "GET", url , false);
    xmlHttp.setRequestHeader("If-Modified-Since","0"); 
    xmlHttp.send( null );
}


function handleLoadFlash() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
           eval(xmlHttp.responseText);
           var s = ''
               s += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="browseImage" width="100%" height="350" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">'
               s += '     <param name="movie" value="flash/'+flash_value+'" />'
               s += '     <param name="quality" value="high" />'
               s += '     <param name="wmode" value="opaque">'
               s += '     <param name="bgcolor" value="#ffffff" />'
               s += '     <param name="allowScriptAccess" value="sameDomain" />'
               s += '     <embed src="flash/'+flash_value+'" quality="high" bgcolor="#ffffff"'
               s += '      width="100%" height="350" name="browseImage" align="middle"'
               s += '      play="true"'
               s += '      loop="false"'
               s += '      quality="high"'
               s += '      wmode="opaque"'
               s += '      allowScriptAccess="sameDomain"'
               s += '      type="application/x-shockwave-flash"'
               s += '      pluginspage="http://www.adobe.com/go/getflashplayer">'
               s += '     </embed>'
               s += '</object>'
           document.getElementById('flash_div').innerHTML = s;
    }
}

function ReserveAccessLog(ip, rest_id, member_id) {
        var url = 'ajaxbroker.php?action=reserveaccesslog&ip=' + ip +'&rest_id='+rest_id + '&member_id=' + member_id;
        xmlHttp=getXmlHttpObject(handleReserveAccessLog);
        xmlHttp.open( "GET", url , false);
        xmlHttp.setRequestHeader("If-Modified-Since","0"); 
        xmlHttp.send( null );
}

function handleReserveAccessLog() {
    if ( xmlHttp.readyState==4 || xmlHttp.readyState=="complete" ) { 
        if (xmlHttp.responseText)
        {
            alert('This restaurant is not available for reservation service at this time.');
        }
     }
}
