﻿// JScript File


var flashlogoImage = "<table width='980' height='100%' border='0' cellpadding='0' cellspacing='4'><tr><td width='100%' valign='middle' align= 'center' style='height:200px' height='100%'><p>"
+ "<img src='img/loading.gif' width='45' height='45'/>"
+ "</p></td><tr></table>";

var flashlogoImage1 = "<table width='980' height='100%' border='0' cellpadding='0' cellspacing='4'>"
                         + "<tr><td width='100%' valign='middle' align= 'center' style='height:200px' height='100%'><p>"
                        + " <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
                        + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'"
                        + " width='45' height='45' id='ObjectFlash'>"
                        + "      <param name='movie' value='img/loader.swf' />"
                        + "       <param name='quality' value='high' />"
                        + "       <param name='bgcolor' value='#ffffff' />"
                        + "       <param name='LOOP' value='-1'>"
                        + "       <param name='allowScriptAccess' value='never'>"
                        + "     <embed  src='img/loader.swf' quality='high' bgcolor='#ffffff'"
                        + " width='45' height='45' name='mymoviename' type='application/x-shockwave-flash' "
                        + "pluginspage='http://www.macromedia.com/go/getflashplayer'> "
                        + "     </embed>"
                        + "  </object>"
                        + "</p></td><tr></table>";

xmlHttp = isAjax();



function Hi() 
{    
        var query = document.getElementById('txtSearch').value;
        
        if(document.getElementById('rbtnSize').checked && query == "") {
            document.getElementById("lblSearcherror").innerHTML = "Please enter search value" ;return;
        }
        else if(document.getElementById('rbtnSize').checked && query != "")
        {
            // Checked size
            var size_forminus = query.split("-");
            //alert(size_forminus.length);
            if (size_forminus.length > 1 ) {
                document.getElementById("lblSearcherror").innerHTML = "";
                document.getElementById("lblSearcherror").innerHTML = "Please enter correct size for search"; return;
                return;
            }
            
            var size_array=query.split("x");
            if (size_array.length < 2) {
                document.getElementById("lblSearcherror").innerHTML = "";
                document.getElementById("lblSearcherror").innerHTML = "Please enter correct size for search"; return;
                return;
            }
            else if (size_array.length > 2) {
            document.getElementById("lblSearcherror").innerHTML = "";
            document.getElementById("lblSearcherror").innerHTML = "Please enter correct size for search"; return;
            return;
        }
            
            var size_num=0;

            while (size_num < size_array.length) {

                //alert(size_array[size_num])

                if (size_array[size_num] < 0) {
                    document.getElementById("lblSearcherror").innerHTML = "Please enter correct size for search";
                    return;
                }
                var numValue = size_array[size_num] - 0;
               // alert(numValue);
                    if(isNaN(numValue))
                   {
                        document.getElementById("lblSearcherror").innerHTML = "" ;
                        document.getElementById("lblSearcherror").innerHTML = "Please enter correct size for search" ;
                        return;
                   }
                    size_num+=1;  
                }
        }


        if (query.match('#')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match('<')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match('~')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match('!')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match(':')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match('>')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match('{')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else if (query.match('}')) { document.getElementById('lblSearcherror').innerHTML = "No special characters allowed!! "; }
        else
        {
            document.getElementById('lblSearcherror').innerHTML = "";
            var type="";
            var country=document.getElementById('cmbCountry').value;
            if(country==""||country==undefined)
            {
              var objcmbCountry=  document.getElementsByName('cmbCountry').item(0);
              country=(objcmbCountry.selected);
            }
            if (document.getElementById('rbtnBrand').checked) {
                type = "Brand";
            }
            else if (document.getElementById('rbtnSize').checked) {
                type = "Size";
            }
            else if (document.getElementById('rbtnPublisher').checked) {
            type = "Publisher";
            }
            else {
                type = "keyword";
            }

            //alert("In Hi() SearchType=" + type + "&SearchKey=" + query + "&SearchCountry=" + country);        
            window.location = "search.aspx?SearchType=" + type   + "&SearchKey=" + query+ "&SearchCountry=" + country;
        }
       }


function textboxValue() {
    document.SearchForm.txtSearch.value = "eg Nokia";
}
function textboxValuek() {
    document.SearchForm.txtSearch.value = "eg Home";
}

function a(check) {
    if (check.checked) {
        document.getElementById("SearchError").innerHTML = "";
        document.SearchForm.txtSearch.focus();
    }
}

function saveresult() {
    try {
        //alert(document.SearchForm.cbxSaveAll); 
        //alert(document.SearchForm.contentID_hidden.value);
        var query = document.getElementById('txtSearch').value;
        var type = "";
        var country = document.getElementById('cmbCountry').value;
        if (document.getElementById('rbtnBrand').checked) { type = "Brand"; } else { type = "keyword" }
        //window.location = "search.aspx?SearchType=" + type + "&SearchKey=" + query + "&SearchCountry=" + country;
      
        if (document.SearchForm.cbxSaveAll != null && document.SearchForm.cbxSaveAll.checked)
         {
            if (document.SearchForm.cbxSaveAll.checked)
             {
                window.location.href = "search.aspx?saveall=" + document.SearchForm.contentID_hidden.value + "&SearchType=" + type + "&SearchKey=" + query + "&SearchCountry=" + country;
            }
          }
          else if (document.SearchForm.contentID_hidden.value != "-1")
           {
            //window.location.href =document.SearchForm.submit();//"search.aspx";//?saveindividual="+document.SearchForm.contentID_hidden.value;
            window.location.href = "search.aspx?saveindividual=" + document.SearchForm.contentID_hidden.value+"&SearchType=" + type + "&SearchKey=" + query + "&SearchCountry=" + country;
           }
        
        else {
            document.getElementById('SearchError').innerHTML = "Please select some boxes to save";
            document.SearchForm.txtSearch.focus();
        }
    }
    catch (e) {

    }
}

function ajaxSaveAll(bChecked)
{
    xmlHttp = isAjax();

    xmlHttp.open("GET", "user_folder.aspx?saveAll="+bChecked, true);
            xmlHttp.send(null);
            xmlHttp.onreadystatechange = function()
             {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
                 {
                    response = xmlHttp.responseText;
                    //alert(response);
                    if (response == "-1")
                    {
                        window.location.replace("SessionExpired.aspx");
                    }
                    else
                    {
                        //alert(response);
                    }
                }
            }
}

function checkAllCheckBoxes(bChecked)
 {
    var i = 0;
    var noCheckBoxes=document.getElementsByName('cbxSaveIndividual').length;
    document.SearchForm.contentID_hidden.value = "-1";
    document.getElementsByName('checkAll').Value = "True";
     ajaxSaveAll(bChecked);
    if(noCheckBoxes==1)
    {
        var objcheckbox=document.getElementsByName('cbxSaveIndividual').item(0);
        //alert(noCheckBoxes+":"+document.getElementsByName('cbxSaveIndividual').length+":"+objcheckbox.value);
        objcheckbox.type="checkbox";
              if (bChecked) 
              {
                 objcheckbox.checked = true;
                document.SearchForm.contentID_hidden.value =  objcheckbox.value + "," + document.SearchForm.contentID_hidden.value;
              }
              else
              {            
                objcheckbox.checked = false;
              }
        
     }
     else
     {
        for (i = 0; i < document.SearchForm.cbxSaveIndividual.length; i++) 
        {
            if (bChecked)
             {
                document.SearchForm.cbxSaveIndividual[i].checked = true;
                document.SearchForm.contentID_hidden.value = document.SearchForm.cbxSaveIndividual[i].value + "," + document.SearchForm.contentID_hidden.value;
             }
             else 
             {
                 document.SearchForm.cbxSaveIndividual[i].checked = false;
             }
        //alert(document.SearchForm.cbxSaveIndividual[i].value+":"+document.SearchForm.cbxSaveIndividual[i].checked);
          }
    }
    //alert(document.SearchForm.contentID_hidden.value);
}

function checkBoxesCheck(bChecked) {
    try {
        var strContentIDs = document.SearchForm.contentID_hidden.value;
        var strContentIDs_toArray = strContentIDs.split(",");
        try {
           // alert("the no. checkboxes:" + document.SearchForm.cbxSaveIndividual.length);
            for (i = 0; i < document.SearchForm.cbxSaveIndividual.length; i++) {
                arrayLength = strContentIDs_toArray.length; //alert(strContentIDs_toArray.length);
                var j = 0;
                while (strContentIDs_toArray[j] != "-1") //for(j=0;j<arrayLength;j++)
                {//alert(strContentIDs_toArray[j]);alert(document.SearchForm.cbxSaveIndividual[i].value);
                    if (document.SearchForm.cbxSaveIndividual[i].value == strContentIDs_toArray[j]) 
                    {
                        //alert(strContentIDs_toArray[j]);alert(document.SearchForm.cbxSaveIndividual[i].value);
                        document.SearchForm.cbxSaveIndividual[i].checked = true;

                        break;
                    }
                    j++;
                }
            }
        }

        catch (err) {
            //alert("Exception in check boxes check");
            return;
        }
    }
    catch (e) {

    }
}

function getCheckVal(bChecked, cbxObject)//individual check box check
{    
    try {
        if (bChecked) {
            document.getElementById('SearchError').innerHTML = "";
            //alert(cbxObject.name+":"+cbxObject.value+" will be inserted");
            var strContentIDs = document.SearchForm.contentID_hidden.value;
            var strContentIDs_toArray = strContentIDs.split(",");
            var flag, intI = 0;
            while (strContentIDs_toArray[intI] != "-1") {
                if (strContentIDs_toArray[intI] == cbxObject.value) {
                    flag = 1;
                    break;
                }
                intI++;
            }
            if (flag != 1) {
                strContentIDs = cbxObject.value + "," + strContentIDs;
                document.SearchForm.contentID_hidden.value = strContentIDs;
                //alert(document.SearchForm.contentID_hidden.value);
            }
        }
        else {
            //alert(cbxObject.name+":"+cbxObject.value+" will be removed");
             strContentIDs = document.SearchForm.contentID_hidden.value;
             strContentIDs_toArray = strContentIDs.split(",");
            var resulting_ContentIDs_Array = new Array(strContentIDs_toArray.lenght);
            var intJ = 0;
            var intK = 0;
            while (strContentIDs_toArray[intJ] != "-1") {
                if (strContentIDs_toArray[intJ] != cbxObject.value) {
                    resulting_ContentIDs_Array[intK] = strContentIDs_toArray[intJ];
                    intK++; //alert(resulting_ContentIDs_Array[intJ]);
                }
                intJ++;
            }
            resulting_ContentIDs_Array[intK] = "-1";
            var Final_ContentIDs_str = "-1"; // new array(intJ);
            for (intX = 0; intX < intK; intX++) {
                Final_ContentIDs_str = resulting_ContentIDs_Array[intX] + "," + Final_ContentIDs_str;
            }

            //alert(Final_ContentIDs_str);
            document.SearchForm.contentID_hidden.value = Final_ContentIDs_str;
            //alert(document.SearchForm.contentID_hidden.value);
        }
    }
    catch (e) {

    }
}


function getSearch() {
    document.body.style.cursor = "wait";
    try {
        var SearchKey = "";
        var SearchType = "";
        if (document.getElementById('rbtnBrand').checked) {
            SearchType = "brand";
        }
        else { SearchType = "Keyword"; }
        if (!document.getElementById('txtSearch').value == "") {
            SearchKey = document.getElementById('txtSearch').value;
            xmlHttp.open("POST", "search.aspx?show=100" + "&SearchType=" + SearchType + "&SearchKey=" + SearchKey + "&SearchCountry=" + document.getElementById('cmbCountry').value, true);
            xmlHttp.send(null);

            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    //alert(xmlHttp.responseText);  
                    document.getElementById('MainDivision').innerHTML = xmlHttp.responseText;
                }
            }

        }
        else { alert("Give A Search Criteria"); }
        //document.SearchForm.txtSearch.focus();
    }
    catch (e) {

    }
    document.body.style.cursor = "auto";
}




function getDynamicContent() {
    document.body.style.cursor = "wait";
    var xmlHttp;
    xmlHttp = isAjax();

    if (xmlHttp == null) {
        alert("Ajax not support");
        return;
    }
    else {
        getShowDivision();
    }
    document.body.style.cursor = "auto";
    document.SearchForm.txtSearch.focus();
}




function getShowDivision() {
    document.body.style.cursor = "wait";
    var xmlHttp1;
    xmlHttp1 = isAjax();
    xmlHttp1.open("GET", "search.aspx?show=100", true);
    xmlHttp1.send(null);
    xmlHttp1.onreadystatechange = function() {
        if (xmlHttp1.readyState == 4 && document.getElementById("MainDivision") != null) {
            document.getElementById("MainDivision").innerHTML = xmlHttp1.responseText;
        }
    }
    document.SearchForm.txtSearch.focus();
    document.body.style.cursor = "auto";
}


function getPage(flag, pageNo) 
{
    document.body.style.cursor = "wait";
    try 
    {
        var xmlHttp;
        var response = "";
        xmlHttp = isAjax();

        if (xmlHttp == null) 
        {
            alert("Ajax not support");
        }
        else 
        {
            document.getElementById("SearchError").innerHTML = '';
            document.getElementById('FlashDivision').innerHTML = flashlogoImage;
            xmlHttp.open("GET", "search.aspx?show=100&flag=" + flag + "&showpage=" + pageNo, true);
            xmlHttp.send(null);
            while (xmlHttp.readyState == 3) 
            {
                document.body.style.cursor = "wait";
            }
            xmlHttp.onreadystatechange = function() 
            {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
                {
                    response = xmlHttp.responseText;
                    //alert(response);
                    if (response == "-1") 
                    {
                        window.location.replace("SessionExpired.aspx");
                    }
                    else 
                    {
                        document.getElementById('MainDivision').innerHTML = xmlHttp.responseText;
                    }
                }
            }
        }
        setTimeout("checkBoxesCheck()", 500);
        document.SearchForm.txtSearch.focus();
    }
    catch (e) {
        ;
    }
    setTimeout("getNormalCursor()", 500);
    //document.body.style.cursor="auto";
}

function getNormalCursor() {
    document.body.style.cursor = "auto";
}
function getLastPage(flag, lastPage) {
    document.body.style.cursor = "wait";
    try {
        var xmlHttp;
        var response = "";
        xmlHttp = isAjax();

        if (xmlHttp == null) {
            alert("Ajax not support");
        }
        else {
            document.getElementById("SearchError").innerHTML = '';
            document.getElementById('FlashDivision').innerHTML = flashlogoImage;
            xmlHttp.open("GET", "search.aspx?show=100&flag=" + flag + "&lastpage=" + lastPage, true);
            xmlHttp.send(null);
            while (xmlHttp.readyState == 3) {
                document.body.style.cursor = "wait";
            }
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    response = xmlHttp.responseText;
                    //alert(response);
                    if (response == "-1") {
                        window.location.replace("SessionExpired.aspx");
                    }
                    else {
                        document.getElementById('MainDivision').innerHTML = xmlHttp.responseText;
                    }
                }
            }

        }
        setTimeout("checkBoxesCheck()", 500);
        document.SearchForm.txtSearch.focus();
    }
    catch (e) {

    }
    setTimeout("getNormalCursor()", 500);
    //document.body.style.cursor="auto";
}

function isAjax() {
    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) {
                return null;
            }
        }
    }
}


function getResultDivision() {
    try {
        var xmlHttp2;
        xmlHttp2 = isAjax();
        xmlHttp2.open("GET", "search.aspx?show=91", true);
        xmlHttp2.send(null);
        xmlHttp2.onreadystatechange = function() {
            if (xmlHttp2.readyState == 4) { //alert(xmlHttp2.responseText);                
                //document.getElementById('ResultDivision').innerHTML=xmlHttp2.responseText;         
            }
        }
    }
    catch (e) {

    }
}

function getNavigationDivision() {
    try {
        var xmlHttp3;
        xmlHttp3 = isAjax();
        xmlHttp3.open("GET", "search.aspx?show=92", true);
        xmlHttp3.send(null);

        xmlHttp3.onreadystatechange = function() {
            if (xmlHttp3.readyState == 4) {       // alert(xmlHttp3.responseText);         
                document.getElementById('NavigateDivision').innerHTML = xmlHttp3.responseText;
            }
        }
        //document.SearchForm.txtSearch.focus(); 
    }
    catch (e) {

    }
}



function checkBoxesCheck2(contentID, cbxObject) {
    var strContentIDs = document.SearchForm.contentID_hidden.value;
    var strContentIDs_toArray = strContentIDs.split(",");
    try {
        arrayLength = strContentIDs_toArray.length; //alert(strContentIDs_toArray.length);
        var j = 0;
        while (strContentIDs_toArray[j] != "-1") //for(j=0;j<arrayLength;j++)
        {
            if (contentID == strContentIDs_toArray[j]) {
                cbxObject.checked = true; break;
            }
            j++;
        }

    } catch (err) {//alert("Exception");
    }
}

function textboxpersistvalue() {
    if (document.SearchForm.txtSearch.value == "chevy" || document.SearchForm.txtSearch.value == "hotels") {
        document.SearchForm.txtSearch.value = "";
    }
    else {
        ;
    }
}


function isMozilla(e) {
    var xmlHttp2;
    try {
        xmlHttp2 = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari              

        if (navigator.userAgent.indexOf("Firefox") != -1)//var array=navigator.userAgent.split
        {
            var versionindex = navigator.userAgent.indexOf("Firefox") + 8
            if (parseInt(navigator.userAgent.charAt(versionindex)) >= 1) {                       //alert("You are using Firefox 1.x or above");
                checkifEnter(e);
            }
        }
        /* else
        {
        return false
        }*/
    }
    catch (e) {
    }
}
javascript: window.history.forward(1);

//function goNoWhere() { }
//javascript:window.history.forward(1);