var http = getHTTPObject(); // We create the HTTP Object  
var dv=null;
var hide_div=null;

function getHTTPObject(){
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
        return xmlHttp;
    }catch (e){
    // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            return xmlHttp;
        }catch (e){
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                return xmlHttp;
            }catch (e){
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
}

function handleHttpResponse() {
    if (http.readyState == 4) {
          if(http.status==200) 
          {
                var results = http.responseText;
                //alert(results);
                
                if(dv==null){ alert("Div not set! set div first..."); }
                else
                { 
                    document.getElementById(dv).innerHTML = results; 
                    
                    if(hide_div != '')
                    {
                        //sleep(4000);
                        document.getElementById(hide_div).style.display = 'none';
                    }
                }
          }
          else 
          {
                document.getElementById(dv).innerHTML = 'Loading Content...';
          }

    }
} 

function tell_friend(rsp)
{
    var forms = document.tell_friend;
    
    var s_name = forms.sender_name.value;
    var s_email = forms.sender_email.value;
    
    var name = forms.name.value;
    var email = forms.email.value;
    var name2 = forms.name2.value;
    var email2 = forms.email2.value;
    var name3 = forms.name3.value;
    var email3 = forms.email3.value;
    var name4 = forms.name4.value;
    var email4 = forms.email4.value;
    var name5 = forms.name5.value;
    var email5 = forms.email5.value;
        
    if(rsp == 'resp_msg')
    { 
        var url = "tell_friend_ops.php?s_name="+s_name+"&s_email="+s_email+"&name="+name+"&email="+email+"&name2="+name2+"&email2="+email2+"&name3="+name3+"&email3="+email3+"&name4="+name4+"&email4="+email4+"&name5="+name5+"&email5="+email5;
        dv = rsp;
        var hide_div = form;
    }
    
    http.open("GET", url, true);    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
}

function registration(rsp)
{
    var f_name = document.reg_form.f_name.value;
    var l_name = document.reg_form.l_name.value;
    var address = document.reg_form.address.value;
    var city = document.reg_form.city.value;
    var state = document.reg_form.state.value;
    var country = document.reg_form.country.value;
    var zip = document.reg_form.zip.value;
    var phone = document.reg_form.phone.value;
    var email = document.reg_form.email.value;
    var password = document.reg_form.password.value;
    var purchase = getRadioValue('purchase');  //alert(purchase); 
    var location = document.reg_form.location.value;
        
    if(rsp == 'resp_msg')
    { 
        var url = "reg_ops.php?f_name="+f_name+"&l_name="+l_name+"&address="+address+"&city="+city+"&state="+state+"&country="+country+"&zip="+zip+"&phone="+phone+"&email="+email+"&password="+password+"&purchase="+purchase+"&location="+location;
        dv = rsp;   
        hide_div = 'div_form';
        var hide_div = form;
    }
    
    http.open("GET", url, true);    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
}



function post_review(rsp, form)
{   
    //alert(rsp);
    name = document.comment_form.name.value;
    email = document.comment_form.email.value;
    comment = document.comment_form.comment.value;
    zip = document.comment_form.zip.value;
    rate = document.comment_form.rate.value;
    spam = document.comment_form.spam.value;
    business_id = document.comment_form.business_id.value;
    title = document.comment_form.title.value;
        
    if(rsp=='resp_msg_new')
    { 
        var url = "post_review.php?name="+name+"&email="+email+"&rate="+rate+"&comment="+comment+"&zip="+zip+"&spam="+spam+"&business_id="+business_id+"&title="+title;
        dv=rsp;
        hide_div = form;
    }
    
    http.open("GET", url, true);    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);        
}

function business_id(business_id)
{               
     
    var url = "../incs/business_id.php?business_id="+business_id;
        //dv=rsp;   
    
    http.open("GET", url, true);    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);        
}

/*function blog_status(rsp, )
{       
    email = document.login_form.email.value;
    password = document.login_form.pass.value;
        
    if(rsp=='stat')
    { 
        var url = 'incs/update-blog.php?do='+actn+'&tgt='+id;
        dv=rsp;
    }
    
    http.open("GET", url, true);    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);        
}*/

function user_login(rsp)
{       
    email = document.login_form.email.value;
    password = document.login_form.pass.value;
        
    if(rsp=='resp_msg_new')
    { 
        var url = "post_login.php?email="+email+"&password="+password;
        dv=rsp;
    }
    
    http.open("GET", url, true);    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);        
}

function post_deal(rsp, form)
{   
    name = document.comment_form.name.value;
    email = document.comment_form.email.value;
    comment = document.comment_form.comment.value;
    zip = document.comment_form.zip.value;  
    spam = document.comment_form.spam.value;
    from_business_id = document.comment_form.from_business_id.value;
    to_business_id = document.comment_form.to_business_id.value;
    to_client_id = document.comment_form.to_client_id.value;
    subject = document.comment_form.subject.value;
    message = document.comment_form.message.value;
        
    //alert(rsp);
    
    if(rsp=='resp_msg_new')
    { 
        var url = "request-deal-ops.php?name="+name+"&email="+email+"&comment="+comment+"&zip="+zip+"&spam="+spam+"&from_business_id="+from_business_id+"&to_business_id="+to_business_id+"&to_client_id="+to_client_id+"&subject="+subject+"&message="+message;
        dv=rsp;
        hide_div = form;
    }
    
    http.open("GET", url, true);
    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);        
}

function post_to_friend(rsp)
{   
    name = document.comment_form.name.value;
    email = document.comment_form.email.value;
    comment = document.comment_form.comment.value;
    zip = document.comment_form.zip.value;  
    spam = document.comment_form.spam.value;
    business_id = document.comment_form.business_id.value;
    title = document.comment_form.title.value;
        
    //alert(rsp);
    
    if(rsp=='resp_msg_new')
    { 
        var url = "share-this-ops.php?name="+name+"&email="+email+"&comment="+comment+"&zip="+zip+"&spam="+spam+"&business_id="+business_id+"&title="+title;
        dv=rsp;
    }
    
    http.open("GET", url, true);
    
    http.onreadystatechange = handleHttpResponse;
    http.send(null);        
}

function state_change(str,rsp){
        
        if(rsp=='msg_dis'){ 
        var url="incs/chk-user.php?id="+str;
        dv=rsp;
        }
        http.open("GET", url , true);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
}

function state_changes_city(state_id,div_id)
{       
    //alert(state_id);  //alert(div_id);

        if(div_id == 'city')
        { 
            var url = "incs/inter_city.php?state_id="+state_id;
            dv = div_id;
        }
        http.open("GET", url , true);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
}

function country_changes_state(country_id,div_id)
{   
        if(div_id == 'state')
        { 
            var url = "incs/inter_state.php?country_id="+country_id;
            dv = div_id;
        }
        http.open("GET", url , true);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
}