﻿// JScript File

function load_sel_l2(){
    var sel_obj = document.getElementById("sel_l1");
    var txt_obj = document.getElementById("txt_l1");
    var val_ = sel_obj.options[sel_obj.selectedIndex].value;
    if(val_!= 0){
        if (val_ != txt_obj.value){
            var obj = document.getElementById("txt_l2");
            obj.value = "";
            var txt_obj2 = document.getElementById("txt_l2_text");                
            txt_obj2.value = "";
        }
        var url = ws_url + "xml_processor.aspx?p=" + val_ + "|2|" + val_ + "&rt=1&r=holiday_destination&pg="
        txt_obj.value = val_;
        ajaxLoader(url, "sel_l2");
        var span_obj = document.getElementById("lbl_arr_err_msg");
        span_obj.style.display = "none";
    }else{
        var obj = document.getElementById("sel_l2");
        txt_obj.value = val_;
        for (var i = obj.getElementsByTagName("option").length - 1; i >= 0; i--) {
            obj.removeChild(obj.getElementsByTagName("option")[i]);
        }  
        var span_obj = document.getElementById("lbl_arr_err_msg");
        span_obj.style.display = "inline";
    }
}
function store_sel_l2(){
    var sel_obj = document.getElementById("sel_l2");
    var txt_obj = document.getElementById("txt_l2");
    var val_ = sel_obj.options[sel_obj.selectedIndex].value;
    txt_obj.value = val_;
    var val2_ = sel_obj.options[sel_obj.selectedIndex].text;
    var txt_obj2 = document.getElementById("txt_l2_text");
    txt_obj2.value = val2_;
    if (val_ == "0"){
        txt_obj.value = "";
        txt_obj2.value = "";
    }
}

function load_sel_l1(){
    var url = ws_url + "xml_processor.aspx?p=0|1|-1&rt=1&r=holiday_destination&pg="
    ajaxLoader(url, "sel_l1");
}

function add_option(value_, text_, select, className_){
    var opt = document.createElement('OPTION');
    opt.innerHTML = text_;
    opt.value = value_;
    opt.className = className_;
    select_obj = document.getElementById(select);
    select_obj.appendChild(opt);
}
		
function ajaxLoader(url, p_){
    if (document.getElementById){
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
	if (x) {
		x.onreadystatechange = function()
		    {
			if(x.readyState == 4 && x.status == 200){
					if(isMoz){moz_function(x, p_)}
                    if(isIE){ie_function(x, p_)}
				}
		    }
		x.open("GET", url, true);
		x.send(null);
    }
}

function moz_function(x, p_){
       var parser=new DOMParser();
        var xmlDocument=parser.parseFromString(x.responseText,"text/xml"); 
        var oroot = xmlDocument.documentElement;
        if (!isNull(oroot)){
           var result = oroot.getElementsByTagName("Table1");
            var obj = document.getElementById(p_);
            for (var i = obj.getElementsByTagName("option").length - 1; i >= 0; i--) {
                obj.removeChild(obj.getElementsByTagName("option")[i]);
            }         
                            
        for(var j = 0; j < result.length; j++) {

            var temp_text = result[j].getElementsByTagName("levelname")[0].childNodes[0].nodeValue;
            var temp_value = result[j].getElementsByTagName("id")[0].childNodes[0].nodeValue;
            var className_ = ""
            if (temp_text.indexOf("(All)") != -1){className_ = "mar"}
            add_option(temp_value, temp_text, p_, className_);
            
                                
        }
        if (p_ == "sel_l1"){
            var sel_obj = document.getElementById("sel_l1");
		    var txt_obj = document.getElementById("txt_l1");
            var temp = txt_obj.value;
            for (i =0; i<sel_obj.length;i++ ){
                if (sel_obj.options[i].value == temp){
                    break;
                }
            }
           sel_obj.focus();
           if(sel_obj.length == i){i = 0;}
           
           sel_obj.selectedIndex = i;
           if (i > 0){load_sel_l2();}
           
        }else if(p_ == "sel_l2"){
            var sel_obj = document.getElementById("sel_l2");
		    var txt_obj = document.getElementById("txt_l2");
            var temp = txt_obj.value;
            for (i =0; i<sel_obj.length;i++ ){
                if (sel_obj.options[i].value == temp){
                    break;
                }
            }
           sel_obj.focus();
           if(sel_obj.length == i){i = 0;}
           
           sel_obj.selectedIndex = i;
           
        }
        
    }
}		


function ie_function(x, p_){
        var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
        
        xmlDocument.loadXML(x.responseText);
        var oroot = xmlDocument.documentElement;
        if (!isNull(oroot)){
           var result = oroot.getElementsByTagName("Table1");
            var obj = document.getElementById(p_);
            for (var i = obj.getElementsByTagName("option").length - 1; i >= 0; i--) {
                obj.removeChild(obj.getElementsByTagName("option")[i]);
            }         
                            
        for(var j = 0; j < result.length; j++) {

            var temp_text = result[j].getElementsByTagName("levelname")[0].childNodes[0].nodeValue;
            var temp_value = result[j].getElementsByTagName("id")[0].childNodes[0].nodeValue;
            var className_ = ""
            if (temp_text.indexOf("(All)") != -1){className_ = "mar"}
            add_option(temp_value, temp_text, p_, className_);

            
                                
        }
        if (p_ == "sel_l1"){
            var sel_obj = document.getElementById("sel_l1");
		    var txt_obj = document.getElementById("txt_l1");
            var temp = txt_obj.value;
            for (i =0; i<sel_obj.length;i++ ){
                if (sel_obj.options(i).value == temp){
                    break;
                }
            }
           sel_obj.focus();
           if(sel_obj.length == i){i = 0;}
           
           sel_obj.selectedIndex = i;
           if (i > 0){load_sel_l2();}
           
        }else if(p_ == "sel_l2"){
            var sel_obj = document.getElementById("sel_l2");
		    var txt_obj = document.getElementById("txt_l2");
            var temp = txt_obj.value;
            for (i =0; i<sel_obj.length;i++ ){
                if (sel_obj.options(i).value == temp){
                    break;
                }
            }
           sel_obj.focus();
           if(sel_obj.length == i){i = 0;}
           
           sel_obj.selectedIndex = i;
           
        }
        
    }
}		

