﻿// Xpert4u :: Mobile Javascript
// Created By   : Raman Sachin Omar
// Created On   : 23th Feb, 2008    

function GetHttpObject(){
    var xmlHttpObj;
    try {   
        xmlHttpObj = new XMLHttpRequest();              
        return xmlHttpObj;
    }
    catch (e){        
        try{
            xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");                   
            return xmlHttpObj; 
        }
        catch (e){           
            try{
                xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");                      
                return xmlHttpObj;      
            }
            catch (e)
            {        
                alert("Sorry, Your browser does not support AJAX!");        
                return null;        
            }     
        }   
    }     
}

function ChangeDealTab(dealId, featureId, tab){
    // alert(dealId +"*"+ featureId +"*" + tab);
     //alert (dealId +" * "+ featureId +" * "+ tab);    
    var browserName = BrowserName();

    document.getElementById(dealId).style.display= "none";     
    document.getElementById(featureId).style.display= "none";
    
    if (browserName == "Chrome" || browserName == "Firefox")
        document.getElementById(tab).style.display= "table";

    else if (browserName == "Microsoft Internet Explorer")
        document.getElementById(tab).style.display= "block";
    
    else
        document.getElementById(tab).style.display= "table";

    if (tab == dealId){         
        document.getElementById('aDeals').className = "selected";
        document.getElementById('aFeatures').className = "";
    }else{
        document.getElementById('aDeals').className = "";
        document.getElementById('aFeatures').className = "selected";
    }    
}


function GetSearchUrl(d, m, h, n, p){

    //alert(d + "*" + m + "*" + h + "*" + n + "*" + p);
    var mv="", mt="", hv="", ht="", nv="", nt="", pv="", pt="", pUrl="", gUrl="";
    mo = document.getElementById(m);
    mv = mo.value;
    mt = mo.options[mo.selectedIndex].text;
    //alert(mv + " * " + mt);
    
    ho = document.getElementById(h);
    hv = ho.value;    
    ht = ho.options[ho.selectedIndex].text;
    //alert(hv + " * " + ht);
    
    if( n != "" && document.getElementById(n)){
        n = document.getElementById(n);
        nv = n.value;        
        nt = n.options[n.selectedIndex].text;         
    }
    if( p != "" && document.getElementById(p)){
        po = document.getElementById(p);
        pv = po.value;        
        pt = po.options[po.selectedIndex].text;         
    }
      
    //alert ("manu:" + mv +", handset:"+ hv +", network:"+ nv +", pr:"+ pv + "########## manu:" + mt +", handset:"+ ht +", network:"+ nt +", pr:"+ pt);
    
    if (d == 'c'){         
        if(mv != ""){
            if(hv != ""){
               pUrl = wsUrl + "mobile-phones/" + ht.replace(/ /g,"-").toLowerCase()+"-deals.html";
            }else{
                if(nv!=""){
                    pUrl = wsUrl + "mobile-phones/" + "search-phones.html";
                }else{
                    gUrl = wsUrl + "mobile-phones/" + mt.replace(/ /g,"-").toLowerCase()+"-mobile-phones.html";
                }               
            }
        }else{
            if(hv!=""){
               pUrl = wsUrl + "mobile-phones/" + ht.replace(/ /g,"-").toLowerCase()+"-deals.html";
            }else{
                if(nv!=""){
                    pUrl = wsUrl + "mobile-phones/" + "search-phones.html";
                }else{
                    gUrl = wsUrl + "mobile-phones/" + "contract-mobile-phones.html";
                }                
            }
        }    
    }
    
    else if (d=="p"){
        if(mv!=""){
            if(hv!=""){
               pUrl = wsUrl + ht.replace(/ /g,"-").toLowerCase()+"-deals.html";
            }else{
                if(nv!=""){
                    pUrl = wsUrl + "search-phones.html";
                }else{
                    gUrl = wsUrl + "payg-"+mt.replace(/ /g,"-").toLowerCase()+"-mobile-phones.html";
                }               
            }
        }else{
            if(hv!=""){
               pUrl = wsUrl + ht.replace(/ /g,"-").toLowerCase()+"-deals.html";
            }else{
                if(nv!=""){
                    pUrl = wsUrl + "search-phones.html";
                }else{
                    gUrl = wsUrl + "pay-as-you-go-deals.html";
                }                
            }
        }    
    }
    
     else if(d=="s"){
        if(mv!=""){
            if(hv!=""){
               pUrl = wsUrl + ht.replace(/ /g,"-").toLowerCase()+"-deals.html";
            }else{
                if(pv!=""){
                    pUrl = wsUrl + "search-phones.html";
                }else{
                    gUrl = wsUrl + "sim-free-"+mt.replace(/ /g,"-").toLowerCase()+"-mobile-phones.html";
                }               
            }
        }else{
            if(hv!=""){
               pUrl = wsUrl + ht.replace(/ /g,"-").toLowerCase()+"-deals.html";
            }else{
                if(pv!=""){
                    pUrl = wsUrl + "search-phones.html";
                }else{
                    gUrl = wsUrl + "sim-free-mobile-phones.html";
                }                
            }
        }    
    }

    
    //alert("pUrl: "+ pUrl);
    //alert("gUrl: "+ gUrl);
    //alert(typeof(document.frmsearch));

//    if(typeof(document.frmsearch) == "object")
//        formName = "frmsearch";
//    else
//        formName = "aspnetForm";
    
    if (pUrl!= ""){
//        if (formName == "frmsearch"){
//            document.frmsearch.action = pUrl;
//            document.frmsearch.submit();
//        }else{
            document.aspnetForm.action = pUrl;
            document.aspnetForm.submit();
//        }
        return true;
    }
    if (gUrl!=""){
        //alert("Hi");
        document.location.href = gUrl;
        return false;
    }
    
}


function GetHttpObject_deal() {
    var xmlHttpObj_deal; 
    try {
        xmlHttpObj_deal = new XMLHttpRequest();        
        return xmlHttpObj_deal;
    }
    catch (e) {
        try {
            xmlHttpObj_deal = new ActiveXObject("Msxml2.XMLHTTP"); 
            return xmlHttpObj_deal;
        }
        catch (e) {
            try {
                xmlHttpObj_deal = new ActiveXObject("Microsoft.XMLHTTP");
                return xmlHttpObj_deal;
            }
            catch (e) {
                alert("Sorry, Your browser does not support AJAX!");
                return null;
            }
        }
    }
}

// Masked Handset By Type In Deal Page
function MaskedDeal(dealType, handset, network, term, minutes, texts, linerental, retailers,pagenumber,sortby,sorttype ){   
       try {     
       //alert ("Hi");
       //
        xmlHttpHandsetDeals = GetHttpObject_deal(); // Function Written In  
        var url =  wsUrl + "mobile-phones/phone/handset_deals_ajax.aspx?dealtype=" + dealType + "&handset=" + handset + "&network=" + network+ "&term=" + term + "&minutes=" + minutes + "&texts=" + texts + "&linerental=" + linerental + "&retailers=" + retailers + "&pagenumber=" + pagenumber + "&sortby="+ sortby +"&sorttype="+ sorttype +"&k=" + Math.random(); 
        //alert(url);
        xmlHttpHandsetDeals.open("GET", url, true);
       // alert(url);
        xmlHttpHandsetDeals.onreadystatechange = function() {
         //alert (xmlHttpHandset.responseText);
            if(xmlHttpHandsetDeals.readyState == 4 ){             
                // alert (xmlHttpHandset.responseText);
                document.getElementById("spndeal").innerHTML = xmlHttpHandsetDeals.responseText;
                //CreateNetworkIcons(xmlHttpHandset.responseText, freegift);    
            }else{
                  document.getElementById("spndeal").innerHTML = "<div style=\"text-align:center;\" ><img src=\"http://www.xpert4u.co.uk/images/ajaxloader.gif\" /></div>";                 
            }            
        }    
        xmlHttpHandsetDeals.send(null);
    }catch(errv) {
	alert("The application cannot contact the server at the moment. Please try again in a few seconds.\nError detail: " + errv.message);
	} 
}


// For Mobile Home Page Search
function GetSHandset(type, manu){       
     xmlHttpSHandset = GetHttpObject(); // Function Written In   

    var url =  wsUrl + "mobile-phones/get-search-result.aspx?c=0&t=" + type + "&m=" + manu;    
    if (navigator.userAgent.indexOf("Chrome")== -1){            
        xmlHttpSHandset.open("GET", url, true);            
    }
    else{
        xmlHttpSHandset.open("GET", url, false);              
    }  
    xmlHttpSHandset.onreadystatechange = function (){ 
        if(type == 'c'){
            if(xmlHttpSHandset.readyState == 4 ){ 
                document.getElementById("spnCHandset").innerHTML = xmlHttpSHandset.responseText;                
                GetSNetwork(type, manu,'');
            }else{
                document.getElementById("spnCHandset").innerHTML = "<select name ='ddlHContract' id = 'ddlHContract' style='width: 200px;'><option>Loading...</option>";
            }
        }
        else if(type == 'p'){
            if(xmlHttpSHandset.readyState == 4 ){ 
                document.getElementById("spnPHandset").innerHTML = xmlHttpSHandset.responseText;                
                GetSNetwork(type, manu,'');
            }else{
                document.getElementById("spnPHandset").innerHTML = "<select name ='ddlHPayg' id = 'ddlHPayg' style='width: 200px;'><option>Loading...</option>";
            }
        }
        else if(type == 's'){
            if(xmlHttpSHandset.readyState == 4 ){ 
                document.getElementById("spnSHandset").innerHTML = xmlHttpSHandset.responseText;                                    
                GetPriceRange('s',manu,null)
            }else{
                document.getElementById("spnSHandset").innerHTML = "<select name ='ddlHSimFree' id = 'ddlHSimFree' style='width: 200px;'><option>Loading...</option>";
            }
        }
    }
    xmlHttpSHandset.send(null);    
} 

// For Mobile Home Page Search
function GetSNetwork(type, manu, hid){ 
   // alert (type);
     xmlHttpHandset = GetHttpObject(); // Function Written In  
     var url =  wsUrl + "mobile-phones/get-search-result.aspx?c=1&t=" + type + "&m=" + manu + "&hid=" + hid;
   // alert(url);
    if (navigator.userAgent.indexOf("Chrome")== -1){            
        xmlHttpHandset.open("GET", url, true);            
    }
    else{
        xmlHttpHandset.open("GET", url, true);              
    }  

    xmlHttpHandset.onreadystatechange = function() {
        if(type == 'c'){
            if(xmlHttpHandset.readyState == 4 ){  
                document.getElementById("spnCNetwork").innerHTML = xmlHttpHandset.responseText;
            }
            else{
                document.getElementById("spnCNetwork").innerHTML = "<select name = 'ddlNContract' id = 'ddlNContract' style='width: 130px;'><option>Loading...</option>";
            }
        }
        else if(type == 'p'){
            if(xmlHttpHandset.readyState == 4){  
                document.getElementById("spnPNetwork").innerHTML = xmlHttpHandset.responseText;
            }else{
                document.getElementById("spnPNetwork").innerHTML = "<select name = 'ddlNPayg' id = 'ddlNPayg' style='width: 130px;'><option>Loading...</option>";
        }
     }
  }    
    xmlHttpHandset.send(null);    
}   
    
function GetPriceRange(type, manu, hid){ 
     if(type=='s' && (manu != null || manu != '') && hid != null){
        document.getElementById('ctl00_cnt_ucSearch_ddlSPriceRange').style.display = "none";   
     }else if(type=='s' && (manu == null || manu == '') && hid == null){
        document.getElementById('ctl00_cnt_ucSearch_ddlSPriceRange').style.display = "block";   
     }
}

function ChangeOtherHandset(handset, dealType){
    var handsets = handset.replace(/ /g,"-");
    if (dealType == "c"){
        document.location.href = wsUrl+"mobile-phones/"+ handsets.replace(/ /g,"-").toLowerCase() +"-deals.html";
    }
    else if (dealType == "p"){
         document.location.href = wsUrl+"mobile-phones/"+ handsets.replace(/ /g,"-").toLowerCase() +"-deals.html";
    }
    else if (dealType == "s"){
         document.location.href = wsUrl+"mobile-phones/"+ handsets.replace(/ /g,"-").toLowerCase() +"-deals.html";
    }
    else if (dealType == "cl"){
        document.location.href = wsUrl+"mobile/phones/"+"clearance.aspx?phonename=" + handsets;
    }
    else if (dealType == "flr12" ){
         document.location.href = wsUrl+"mobile-phones/"+ handsets.replace(/ /g,"-").toLowerCase() +"-deals.html";
    }
    else if (dealType == "u"){
        document.forms[0].submit();
    }
} 

function ChangeFreeGift(freegift){    
    var freegifts = freegift.replace(/ /g,"-").toLowerCase();
    //alert(freegifts);
    if (freegifts == "cashback" || freegifts == "instant-cashback"){
         document.location.href = freegifts+"-deals.html";   
    }else{
         document.location.href = "free-" + freegifts + "-deals.html";
    }    
} 

// Masked Handset By Type In Deal Page
function MaskedHandsetByType(dealType, handset){   
    try {     
        xmlHttpHandset = GetHttpObject(); // Function Written In  
        var url =  wsUrl + "mobile-phones/phone/getadvancesearch.aspx?dealtype=" + dealType + "&handset=" + handset + "&k=" + Math.random();;
        xmlHttpHandset.open("GET", url, true);
        //alert(url);
        xmlHttpHandset.onreadystatechange = function() {
            if(xmlHttpHandset.readyState == 4 ){             
                document.getElementById("spnOtherPhone").innerHTML = "Other Phones " + xmlHttpHandset.responseText;
            }else{
                document.getElementById("spnOtherPhone").innerHTML ="Other Phones <select name=\"ddlHandset\" id=\"ddlHandset\"><option>Loading...</option></select>"
            }            
        }    
        xmlHttpHandset.send(null);
    }catch(errv) {
		//alert("The application cannot contact the server at the moment. Please try again in a few seconds.\nError detail: " + errv.message);
	} 
}

// Masked Other Gifts in Gift Deal Page
function GetOtherGift(freegift){   
    try {     
        //alert(freegift);
        xmlHttpHandset = GetHttpObject(); // Function Written In xpert.js
        var url =  wsUrl + "mobile-phones/phone/getadvancesearch.aspx?gifttype=1&freegift=" + freegift + "&k=" + Math.random();;
        xmlHttpHandset.open("GET", url, true);
        xmlHttpHandset.onreadystatechange = function() {           
            if(xmlHttpHandset.readyState == 4 && xmlHttpHandset.status == 200){           
                //alert(xmlHttpHandset.responseText);  
                document.getElementById("spnOtherGift").innerHTML = "Change free gifts " + xmlHttpHandset.responseText;
            }else{
                document.getElementById("spnOtherGift").innerHTML = "Change Free gifts <select><option>Loading Free Gifts</option></select>";
            }            
        }    
        xmlHttpHandset.send(null);
    }catch(errv) {
		//alert("The application cannot contact the server at the moment. Please try again in a few seconds.\nError detail: " + errv.message);
	} 
}

// GetMobileLeftNavi: Masked Left Navi
function GetMobileLeftNavi(divId){   
    try {            
        xmlHttpHandset = GetHttpObject();
        var url =  wsUrl + "mobile-phones/usercontrols/ajax-left-navi.aspx?k=" + Math.random();
        //alert(wsUrl);
        xmlHttpHandset.open("GET", url, true);
        xmlHttpHandset.onreadystatechange = function() {           
            if(xmlHttpHandset.readyState == 4 && xmlHttpHandset.status == 200){                 
                document.getElementById(divId).innerHTML = xmlHttpHandset.responseText;
            }else{
                document.getElementById(divId).innerHTML = "Loading...";
            }            
        }    
        xmlHttpHandset.send(null);
    }catch(errv) {} 
}
    
function wait(msecs){
    var start = new Date().getTime();
    var cur = start
    while(cur - start < msecs){        
        cur = new Date().getTime();
    }
} 

function GetInnerText (node){
    return (node.textContent || node.innerText || node.text) ;
}
// window.alert = function(){return null;}

///////////////////////// Gift Deal Page ///////////////////////////

function GiftAdvanceSearch(freegift, handset, cost, net, term, min, txt, lr, merch, dc, selection){        
    var xmlHttpHandset = GetHttpObject(); // Function Written In  
    var url =  wsUrl + "mobile-phones/phone/getadvancesearch.aspx?deal=fg&freegift="+freegift+"&handset="+handset+"&cost="+cost+"&net="+net+"&term="+term+"&min="+min+"&txt="+txt+"&lr="+lr+"&merch="+merch+"&dc="+dc+"&sel="+selection+"&k="+Math.random();    
    //alert(url);
    xmlHttpHandset.open("GET", url, true);              
    xmlHttpHandset.onreadystatechange = function() {
        if(xmlHttpHandset.readyState == 4 && xmlHttpHandset.status== 200){             
             GetOtherGift(freegift);
             //document.write(xmlHttpHandset.responseText);
             document.getElementById("divAdvSearch").innerHTML = xmlHttpHandset.responseText;
             CreateNetworkIcons(xmlHttpHandset.responseText, freegift);         
        }else{
             document.getElementById("divAdvSearch").innerHTML = "<div class=\"left1\"><select name=\"ddlASHandset\" id=\"ddlASHandset\" class='ddl_230'><option value=\"\">Change Handset</option></select></div> <div class=\"gift_search_bar\"><select id=\"ddlASHandsetCost\" name=\"ddlASHandsetCost\" class='ddl_60'><option value=\"\">Cost</option></select> <select name=\"ddlASNetwork\" id=\"ddlASNetwork\" class='ddl_75'><option value=\"\">Network</option></select> <select name=\"ddlASContractMonths\" id=\"ddlASContractMonths\" class='ddl_60'><option value=\"\">Term</option></select> <select name=\"ddlASMinutes\" id=\"ddlASMinutes\" class='ddl_75'><option value=\"\">Minutes</option></select> <select name=\"ddlASTexts\" id=\"ddlASTexts\" class='ddl_75'><option value=\"\">Texts</option></select> <select name=\"ddlASLinerental\" id=\"ddlASLinerental\" class='ddl_75'><option value=\"\">Line Rental</option></select> <select name=\"ddlASMerchant\" id=\"ddlASMerchant\" class='ddl_125'><option value=\"\">Select Merchant</option></select></div>";
           
        }            
    }      
    xmlHttpHandset.send(null);    
}

function SubmitForm(){
    document.forms[0].hidHandset.value = 'true';
    document.forms[0].submit();  
}

function CreateNetworkIcons(res, freegift){ 
    //alert (res);
    pattern =  '<\s*select name="ddlASNetwork" [^>]*>(.*?)<\s*/\s*select>';
    attributes = 'm';  

    var txt=new RegExp(pattern,'g')
    var refineOptions = res.match(txt);  

    var re = new RegExp('<option value ="(.*?)"*.>(.*?)</option>', 'g');
    var myArray = refineOptions[0].match(re);

    var networkImages = "";
    var selectedImage = "";

    if ( myArray != null) {
        for ( i = 0; i < myArray.length; i++ ) { 
            if (myArray[i].search("selected")>-1)
                selectedImage = "_s";
            else
                selectedImage = "";
            myArray[i] = stripHTML(myArray[i]);
            if (myArray[i] != "Network"){           
                networkImages = networkImages + "<img alt='" + myArray[i] + "' src = '../images/telecom/networks/icons/" + myArray[i] + selectedImage + ".gif' onclick = \"document.getElementById('ddlASNetwork').value = '" + myArray[i] + "';document.getElementById('ctl00_cp_networkIdSelected').value = '" + myArray[i] + "'; document.aspnetForm.submit();\"/>";         
            }            
        }        
        networkImages = networkImages + "<div class='cl'></div>";        
    }        
    //alert (networkImages);
    document.getElementById("divNetwork").innerHTML = networkImages;
}

function stripHTML(oldString) {
    var newString = "";
    var inTag = false;
    for(var i = 0; i < oldString.length; i++) {
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
            if(oldString.charAt(i+1)=="<"){
                //dont do anything
            }else{
                inTag = false;
                i++;
            }
        }
        if(!inTag) newString += oldString.charAt(i);
    }
    return newString;
}


//////////////////////  Handset Deal Page ///////////////////////

function BindAdvanceSearch(deal, net, min, txt, freegift, handset, lr, merch, cd, pd, sd, hname, term, pr, selection, clr, plan){     
    //alert("hi");   
    var xmlHttpHandset = GetHttpObject(); // Function Written In  
    //alert("hi");
    var url =  wsUrl + "mobile-phones/phone/getadvancesearch.aspx?deal="+deal+"&net="+net+"&min="+min+"&txt="+txt+"&freegift="+freegift+"&handset="+handset+"&lr="+lr+"&cd="+cd+"&pd="+pd+"&sd="+sd+"&merch="+merch+"&term="+term+"&pr="+pr+"&sel="+selection+"&clr="+clr+"&plan="+plan+"&k="+Math.random();
    //alert(url);
    xmlHttpHandset.open("GET", url, true);              
    xmlHttpHandset.onreadystatechange = function() {
        if(xmlHttpHandset.readyState == 4 && xmlHttpHandset.status== 200){
            MaskedHandsetByType(deal, handset);
            //alert(xmlHttpHandset.responseText);
            document.getElementById("divAdvSearch").innerHTML = xmlHttpHandset.responseText;
        }else{
            if (deal == "c" || deal == "flr12")
                document.getElementById("divAdvSearch").innerHTML = "<select name='ddlASDealType' id='ddlASDealType' style='display:none;' class='ddl_100'><option value=''>Contract</option></select> <select name='ddlASNetwork' id='ddlASNetwork' class='ddl_110'><option value=''>Network</option></select> <select name='ddlASContractMonths' id='ddlASContractMonths' class='ddl_70'><option value=''>Term</option></select> <select name='ddlASMinutes' id='ddlASMinutes' class='ddl_80'><option value=''>Minutes</option></select> <select name='ddlASTexts' id='ddlASTexts' class='ddl_80'><option value=''>Texts</option></select> <select name='ddlASLinerental' id='ddlASLinerental' class='ddl_90'><option value=''>Line Rental</option></select> <select name='ddlASMerchant' id='ddlASMerchant' class='ddl_120'><option value=''>Select Merchant</option></select>";
        }
        
    }      
    xmlHttpHandset.send(null);    
}

//------------Add Advavance Serach---------

function GetSearch(dt, mf, nt, hn, pr, mn, tx, sel){
  //alert("HI");
    var xmlHttpHandset = GetHttpObject();    
    
    var url =  wsUrl + "mobile-phones/getmobilehomesearch.aspx?dt="+dt+"&mf="+mf+"&nt="+nt+"&hn="+hn+"&pr="+pr+"&mn="+mn+"&tx="+tx+"&sel="+sel+"&k="+Math.random();  
    //alert(url);
    xmlHttpHandset.open("GET", url, true);   
    xmlHttpHandset.onreadystatechange = function() {
        if(xmlHttpHandset.readyState == 4 && xmlHttpHandset.status== 200){
            //alert(xmlHttpHandset.responseText)
            document.getElementById("dvMobileSearch").innerHTML = xmlHttpHandset.responseText;
        }else{            
            document.getElementById("dvMobileSearch").innerHTML =  "<select name=\"ddlManufacturer\" id=\"ddlManufacturer\" class=\"ad_manufacturer\"><option value=\"\">Loading</option></select><select name=\"ddlHandset\" id=\"ddlHandset\" class=\"ad_handset\"><option value=\"\">Loading</option></select><label id=\"dvNetwork\"><select name=\"ddlNetwork\" id=\"ddlNetwork\" class=\"ad_network\"><option value=\"\">Loading</option></select></label>"
        }        
    }      
    xmlHttpHandset.send(null);    
} 

function RedirecrSearch(){
    //alert(wsUrl);
    var d="", m="", h="", n="", p="", v="", t="", r="", s="", nn="",mm="",hh="",j="";
    d = document.forms[0].ddlDealType.value;
    m = document.forms[0].ddlManufacturer.value;
    k = document.forms[0].ddlManufacturer.selectedIndex;
    mm = document.forms[0].ddlManufacturer.options[k].text;
    if(m=="")
        mm="";       
    else
        mm = mm.replace(/ /g,"-");      

    h = document.forms[0].ddlHandset.value;
    l = document.forms[0].ddlHandset.selectedIndex;
    hh = document.forms[0].ddlHandset.options[l].text;
    if(h=="")
        hh="";           
    else
        hh = hh.replace(/ /g,"-");           

    if (document.forms[0].ddlNetwork && document.forms[0].ddlNetwork!=null){
        nn=document.forms[0].ddlNetwork.value;
        j = document.forms[0].ddlNetwork.selectedIndex;
        n= document.forms[0].ddlNetwork.options[j].text;
    }
    if(nn=="")
        n="";          
    else
        n = n.replace(/ /g,"-");

    n=n.split(' ').join('');
    if (document.forms[0].ddlPriceRange)
        p = document.forms[0].ddlPriceRange.value;
    p=p.replace(/ /g,"-").toLowerCase();

    //alert("d="+ d + "*m=" + m + "*h=" + h + "*n=" + n + "*p=" + p);   

    r = wsUrl + "mobile-phones/";
    if (d=="c"){//Contract Search
        r = wsUrl + "mobile-phones/contract-mobile-phones.html";
        if (h!=""){
            if(n!=""){
                //alert(n);
                //r= wsUrl + "mobile-phones/contract-deals/"+hh.toLowerCase()+"-on-"+n.toLowerCase()+"/";
                r= wsUrl + "mobile-phones/"+hh.toLowerCase()+"-deals.html";
            }else{
                r= wsUrl + "mobile-phones/"+hh.toLowerCase()+"-deals.html";
            }
        }
        else{    
            if(n!=""){
                if(m!=""){
                    r= wsUrl + "mobile-phones/"+mm.toLowerCase()+"-contract-mobiles-on-"+n.toLowerCase()+"/";
                    //r= wsUrl + "mobile-phones/network.aspx?name="+n+"&brand="+mm;  
                }else{
                    r = wsUrl + "mobile-phones/"+n.toLowerCase().replace("-mobile","")+"-contract-mobile-network/"
                    //r= wsUrl + "mobile-phones/network.aspx?name="+n;
                }
            }else{
                if(m!=""){
                    r =wsUrl+ "mobile-phones/"+mm.toLowerCase()+"-mobile-phones.html"
                    //r =wsUrl+ "mobile-phones/mobile-gallery.aspx?name="+mm;
                }
            }
        }
    }else if (d=="p"){// Pay as you go search
        //r = wsUrl + "mobile-phones/pay-as-you-go.aspx";    
        r = wsUrl + "mobile-phones/pay-as-you-go-deals.html";    
        if(h!=""){
            if(n!=""){
                //r= wsUrl + "mobile-phones/mobile-deals.aspx?phonename="+hh.toLowerCase()+"&dealtype=payasyougo&net="+n.toLowerCase();
                //r= wsUrl + "mobile-phones/pay-as-you-go-deals/"+hh.toLowerCase()+"-on-"+n.toLowerCase()+"/";
                r= wsUrl + "mobile-phones/"+hh.toLowerCase()+"-deals.html";
            }else{
                //r= wsUrl + "mobile-phones/mobile-deals.aspx?phonename="+hh.toLowerCase()+"&dealtype=payasyougo";
                 r= wsUrl + "mobile-phones/"+hh.toLowerCase()+"-deals.html";
            }
        }else{
            if(n!=""){
                if(m!=""){
                    r = wsUrl + "mobile-phones/"+mm.toLowerCase()+"-payasyougo-mobiles-on-"+n.toLowerCase()+"/";
                    //r = wsUrl + "mobile/network.aspx?name="+n.toLowerCase()+"&dealtype=payasyougo&brand="+mm.toLowerCase(); 
                }else{
                    //r = wsUrl + "mobile/network.aspx?name="+n.toLowerCase()+"&dealtype=payasyougo";
                    //r = wsUrl + "mobile-phones/pay-as-you-go-mobiles-on-"+n.toLowerCase()+"/";
                    r = wsUrl + "mobile-phones/"+n.toLowerCase().replace("-mobile","")+"-payasyougo-mobile-network/"
                }
            }else{
                if (m!=""){
                    //r = wsUrl + "mobile/mobile-gallery.aspx?name="+mm.toLowerCase()+"&phonetype=payasyougo";
                    r =wsUrl+ "mobile-phones/payg-"+mm.toLowerCase()+"-mobile-phones.html"
                }
            }
        }
    }else if(d=="s"){//Simfree Search .toLowerCase()
        r = wsUrl + "mobile-phones/sim-free-mobile-phones.html";
        if(h!=""){
            if(p!=""){
                //r = wsUrl + "mobile/mobile-deals.aspx?phonename="+hh.toLowerCase()+"&dealtype=simfree&pricerange="+p.toLowerCase();
                //r = wsUrl + "mobile-phones/sim-free-deals/"+hh.toLowerCase()+"-in-"+p.toLowerCase()+"/";
                r= wsUrl + "mobile-phones/"+hh.toLowerCase()+"-deals.html";
            }else{
                //r = wsUrl + "mobile/mobile-deals.aspx?phonename="+hh.toLowerCase()+"&dealtype=simfree";
                r = wsUrl + "mobile-phones/"+hh.toLowerCase()+"-deals.html";
            }
        }else{
            if(p!=""){
                if(m!=""){
                    //r = wsUrl + "mobile-gallery.aspx?name="+mm.toLowerCase()+"&pricerange="+p.toLowerCase()+"&phonetype=simfree";
                    r = wsUrl + "mobile-phones/sim-free-"+mm.toLowerCase()+"-mobile-phones.html";
                }else{
                    //r = wsUrl + "mobile/mobile-gallery.aspx?pricerange="+p.toLowerCase()+"&phonetype=simfree";
                    r = wsUrl + "mobile-phones/sim-free-mobile-phones.html";
                }        
            }else{
                if(m!=""){
                    //r="mobile-gallery.aspx?name="+mm.toLowerCase()+"&phonetype=simfree";
                   r =wsUrl+ "mobile-phones/sim-free-"+mm.toLowerCase()+"-mobile-phones.html"
                }
            }
        }
    }
    //alert("r="+r);     
    window.location.href = r;

}

function SetDealType(name, value, seconds) {
	val = document.getElementById("ddlNetwork").value; 
	type = document.getElementById("ddlDealType").value; 

	if (type == "c")
	{
	    value = "contract";
	}
	else if (type == "p")
	{
	    value = "payasyougo";
	}
	else if (type == "s")
	{
	    value = "simfree";
	}
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	if (val != "")
	{
	    document.cookie = name+"="+value+val+expires+"; path=/";
	}
	else
	{
	     document.cookie = name+"="+value+expires+"; path=/";
	}
	//alert(value);
	//alert(document.cookie);
}
//------------End  Advavance Serach---------
//keyfeature and description

function specs()
{

	document.getElementById("desc").style.display="none";
	document.getElementById("specs").style.display="block";
	document.getElementById("keyword").style.display="none";
	document.getElementById("description").style.display="block";
}
function desc()
{
	document.getElementById("specs").style.display="none";
	document.getElementById("desc").style.display="block";
	document.getElementById("keyword").style.display="block";
	document.getElementById("description").style.display="none";
}
//End keyfeature and description
