var tempobj;

function setCityFromSelections(ddlCountriesName, ddlCitiesName)
{
	var ddlCountries = findCtrl(ddlCountriesName);
	var ddlCities = findCtrl(ddlCitiesName);
	/*
	if (ddlCountries && ddlCities)
	{
		if (ddlCountries[ddlCountries.selectedIndex].value == '34')
		{
			select(ddlCitiesName, 'STO');
		}
		else if (ddlCountries[ddlCountries.selectedIndex].value == '31')
		{
			select(ddlCitiesName, 'OSL');
		}
		else if (ddlCountries[ddlCountries.selectedIndex].value == '145')
		{
			select(ddlCitiesName, 'HEL');
		}
		else if (ddlCountries[ddlCountries.selectedIndex].value == '23')
		{
			select(ddlCitiesName, 'MAD');
		}
	}
	*/
}
function select(select, value)
{
	if (document.getElementById(select) != null) 
	{
		select = document.getElementById(select);
		
		for (var i = 0; i < select.options.length; i++)
		{
			if (select.options[i].value == value)
			{
				select.selectedIndex = select.options[i].index;
			}
		}
	}
	else if (findCtrl(select) != null)
	{
		
		select = findCtrl(select);
		for (var i = 0; i < select.options.length; i++)
		{
			if (select.options[i].value == value)
			{
				select.selectedIndex = select.options[i].index;
			}
		}
	}
}
function RemoveText(obj, text) 
	{
		if (obj.value == text)
		{
			obj.value = '';
		}
	}
function HandleSummaryValidation(divName,src)
{
	if(document.getElementById)
	{
		obj = document.getElementById(divName);	
		
		if(obj)
		{
			obj.src = src;
			h = 0;
			if(document.body)
			{			
				h = document.body.scrollHeight
			}

			if(h>0)
			{
				obj.style.height = h;
				obj.height = h;			
			}
			
			showHideDiv(divName,'visible')
		}
	}
	
	return true;
}
function showHideDiv(divName, state)
{
	div = document.getElementById(divName);	
	div.style.visibility = state;
}
function findCtrl(name)
{			
	frm = document.forms[0];
	for(i=0;i<frm.elements.length;i++)
	{
		elName = frm.elements[i].id;
			
		startIndex= elName.length-name.length;		
		elNameRight = elName.substring(startIndex,elName.length);				
		foundName = false;
		if(elNameRight.toLowerCase()==name.toLowerCase())
			foundName = true;
		/*
		elId = frm.elements[i].id;		
		if(elId && elId!="")
		{
			startIndex= elId.length-name.length;		
			elIdRight = elName.substring(startIndex,elId.length);		
			
			alert(elIdRight.toLowerCase())
			if(elIdRight.toLowerCase()==name.toLowerCase())		
				foundName = true;
		}
		*/
						
						
		if(foundName)
		{		
			return frm.elements[i];
		}				
	}		
	
	return null;	
}
function moreInfo(URL) 
{
	popUp(URL, 700, 600, 1);
}
function popUp(URL, W, H, scrollbars) 
{
	props=window.open(URL, 'poppage', 'toolbars=0, scrollbars=' + scrollbars + ', location=0, statusbars=0, menubars=0, resizable=0, width='+ W +', height=' + H + ', left = 100, top = 100');
}

//ASYNC REQUEST:
var flightCityUrl = '/js/OutputFlightCitiesFromCountry.aspx';
var xmlHttp;
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
var is_ie7 = (navigator.appVersion.indexOf("MSIE 7") != -1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
//netscape, safari, mozilla behave the same???
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;
var ddlCities;
var selectedCountry = "";

function asyncReq(req,v1,v2,outCity,ddlCityName,cityUrl) 
{
	selectedCountry = "";
	ddlCities = findCtrl(ddlCityName);
    document.body.style.cursor = "progress";
    
    //var ajaximage = document.getElementById("imgAjaxLoadCity");
    
    //ajaximage.style.visibility = "visible";
    
    var noProgress = new Option();
    noProgress.text = "Loading";
    //ddlCities[-2] = noProgress;
    		
    //Append the name to search for to the requestURL
    var url = flightCityUrl + '?req='+ req +'&v1='+ v1 +'&s='+ v2 + '&out=' + outCity;// +'&v3='+ v3 +'&v4='+ v4 +'&v5='+ v5;
    //Create the xmlHttp object to use in the request
    //stateChangeHandler will fire when the state has changed, i.e. data is received back
    //This is non-blocking (asynchronous)
    xmlHttp = GetXmlHttpObject(stateChangeHandler);
    
    //Send the xmlHttp get to the specified url
    xmlHttp_Get(xmlHttp, url);
}
function stateChangeHandler()
{
    if (xmlHttp.readyState == "4")
    {
        var stringResult = xmlHttp.responseText;
        var arrayResult = stringResult.split(":::")
        
		if (arrayResult[0] == 'hko' || arrayResult[0] == 'hko') 
		{
			var arrayCityList = arrayResult[1].split("|")
			while (ddlCities.options.length>0) 
			{
				ddlCities.options[0] = null;
			}
            
			for (var i=0; i<arrayCityList.length-1; i++) 
			{
				var arrayCityItem = arrayCityList[i].split(":")
				var no = new Option();
				
     			no.value = arrayCityItem[0];
     			no.text = arrayCityItem[1];
     			ddlCities[ddlCities.options.length] = no;
			}
			
			/*make selection
			if (selectedCountry == 'Sverige')
			{
				selectByText(ddlCities.name, 'Stockholm');
			}
			else if (selectedCountry == 'Norge')
			{
				selectByText(ddlCities.name, 'Oslo');
			}
			else if (selectedCountry == 'Finland')
			{
				selectByText(ddlCities.name, 'Helsinki');
			}
			selectedCountry == "";*/
		}
		else
		{
		}
        document.body.style.cursor = "auto";
    }
    else
    {
    }
}
    
function GetXmlHttpObject(handler) 
{

    var objXmlHttp = null;    //Holds the local xmlHTTP object instance
    
    //checkForXMLHttpRequestSupport();
    //Depending on the browser, try to create the xmlHttp object
    if (is_ie) { //is_ie && is_ie7 && !
        //The object to create depends on version of IE
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
        //Attempt to create the object
        try {
			//alert('Attempt to create IE object');
            objXmlHttp = new ActiveXObject(strObjName);
            objXmlHttp.onreadystatechange = handler;
        }
        catch(e) {
        //Object creation errored
            //alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
            return;
        }
    }
    else if (is_opera) {
        //Opera has some issues with xmlHttp object functionality
        //alert('Opera detected. The page may not behave as expected.');
        return;
    }
    else{
        // Mozilla | Netscape | Safari
        objXmlHttp = new XMLHttpRequest();
        objXmlHttp.onload = handler;
        objXmlHttp.onerror = handler;
    }
    
    //Return the instantiated object
    return objXmlHttp;
}
function checkForXMLHttpRequestSupport()
{
    try 
    {
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) 
    {
        return 0;
    }
    return 1;
}
function xmlHttp_Get(xmlhttp, url) 
{
    xmlhttp.open('GET', url, true);
    xmlhttp.send("");
}