﻿
//************GLOBAL VARIABLES****
var XmlHttp
var ScriptEngine = "AjaxFunction.aspx";
var strVal = '';
//*******************************


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();

    //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 (ProcessedCase) {
            case 'ShowTechnology':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'ShowProductDownloads':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'ShowProductSpecification':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'FindComparisionProducts':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'DownloadCategory':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'DownloadSubCategory':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'DownloadResult':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'ProductSorting':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'ShowProductReviewAndAwards':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'ShowGlossary':
                document.getElementById('hdnGlossaryResult').value = ProcessedValues;
                break;
			case 'BindSubCategory':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
			case 'BindProduct':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'CheckEmailExists':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'Logout':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;
            case 'SendEmailToDealer':
                document.getElementById('hdnResultDealer').value = ProcessedValues;
                break;
            case 'getKoreaZipInfo':
                document.getElementById('hdnResultZipInfo').value = ProcessedValues;
                break;
			case 'ShowProductParts':
                document.getElementById('hdnResult').value = ProcessedValues;
                break;


            default:
                break;
        }

        return true;

    }
}
