﻿
//************GLOBAL VARIABLES****
var XmlHttp
var ScriptEngine = "AjaxFunction.aspx";
var strVal = '';
var strCase = '';
//*******************************


function GetXmlHttpObject() {

    var xmlHttp = null;
    try {
        //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
        xmlHttp.overrideMimeType('text/xml');

    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    return xmlHttp;
}
//************FUNCTION FOR AJAX CALL********
function GetRequest(RequestValues, ActionCase) {
    //GENERATING XML HTTP REQUEST
    XmlHttp = GetXmlHttpObject();
    strCase = ActionCase;
    //IF REQUEST IS NULL IT MEANS BROWSER DOESNOT SUPPORT HTTP REQUEST

   

    if (XmlHttp == null) {
        alert("BROWSER DOES NOT SUPPORT HTTP REQUEST.");
        return;
    }

    //SETTING SERVER SCRIPTING PAGE URL(Scripting Engine Page)

    var url = "/Assets/Pages/" + ScriptEngine;

    if (location.protocol == "https:" || location.protocol == "HTTPS:") {
        reqUrl = "https://" + location.host + "/Assets/Pages/AjaxFunctionHttps.aspx";
        url = reqUrl;
        // alert("after Https url is \n " + url);
    }

    url = url + "?ReqVal=" + RequestValues;

    url = url + "&ReqCase=" + ActionCase;
    url = url + "&Random=" + Math.random();

   
    XmlHttp.open("GET", url, false);

    XmlHttp.send(null);
    StateChanged();

}



//***************AJAX RESPONSE FUNCTION***********************
function StateChanged() {
			
    if (XmlHttp.readyState == 4 || XmlHttp.readyState == "Complete") {
        //STORING THE AJAX PROCESSED VALUE 		
        var ResponseValue = XmlHttp.responseText;
		
        // Ascii Code for æ is ALT + 1452
        //SPLITTING THE PROCESSED VALUE AND THE CASE FOR WHICH WE ARE PROCESSING REQUEST

        var ValCaseSplitter = ResponseValue.split("~");
        var ProcessedValues = ValCaseSplitter[0];
        var ProcessedCase = ValCaseSplitter[1];

        switch (strCase) {            
			case 'BindProduct':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;            
            case 'Logout':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;		
   	   	    case 'CheckEmailExists':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'ModelNo':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'ProductDetail':
                document.getElementById('hdnSelect').value = ProcessedValues;
                break;
            case 'ProductCollection':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'BindDepartment':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'ShowFilteredFAQs':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'AddToWishList':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'ProductsForComparison':
                document.getElementById('hdnCompareData').value = ProcessedValues;
                break;
            case 'EmaiToFriend':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'DealerDashBoard':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			 case 'RemoveFromWishlist':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'BindState':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'BrandNews':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'RemoveProduct':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'BindSelectProduct':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'BindProductOnBehalfOfCounter':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'BindProductInProductRegistration':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'BindProductOnBehalfOfCounterInProductRegistration':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            default:
                break;
        }

        return true;

    }
}
