var lang='';

	/**
	 *
	 * FORM SUBMISSION AND AJAX FUNCTIONS
	 *
	 */


function postForm() {
    var theForm = document.getElementById('dialFormAdv');
    theForm.submit();
}

function getRegions(){
    var countryID = document.getElementById('selCountry3').options[document.getElementById('selCountry3').selectedIndex].value;
	var lobjAjax = new sack("http://orangespotfinder.coverage-finder.com/ajax/dial_ajax_process.php");
	lobjAjax.setVar("action","ajax");
	lobjAjax.setVar("countryID", countryID); // recomended method of setting data to be parsed.

    //set the country name in the hidden field:
    document.getElementById('txtCountryName').value = document.getElementById('selCountry3').options[document.getElementById('selCountry3').selectedIndex].text;
    lobjAjax.onCompletion = function() {
        //alert('Regions'+lobjAjax.response);
        if (lobjAjax.response != "empty"){
	        lintCounter=0;
	        var larrOptions = [];
            if(lang=='EN') {
                larrOptions["-1"] = "Select...";
            } else {
                larrOptions["-1"] = "S"+unescape('%E9')+"lectionner...";
            }

            eval(lobjAjax.response);
		    document.getElementById('selStateCounty').disabled = false;
            document.getElementById('selStateCounty').options.length=0;
            for(i in larrOptions) {
                document.getElementById('selStateCounty').options[lintCounter] = new Option(larrOptions[i],i);
                //if (lstrPostCounty==larrOptions[i]) {
                    //document.getElementById('selStateCounty').selectedIndex = i;
                //}
                lintCounter++;
            }
            if (lintCounter==2) {
                //postForm();
            }
        } else {
	        // if there are no regions, just submit the form.
	        //postForm();
        }
    };
	lobjAjax.runAJAX();
}

function getAreaCodesByState(){
    var lobjAjax = new sack("http://orangespotfinder.coverage-finder.com/ajax/dial_ajax_process.php");
    lobjAjax.setVar("action","areacodebystate");
    lobjAjax.setVar("state", document.getElementById('selStateCounty').options[document.getElementById('selStateCounty').selectedIndex].value); // recomended method of setting data to be parsed.

    lobjAjax.onCompletion = function() {
        //alert(lobjAjax.response);
        if (lobjAjax.response != "empty"){
            lintCounter=0;
            var larrOptions = [];
            if(lang=='EN') {
                larrOptions["-1"] = "Select...";
            } else {
                larrOptions["-1"] = "S"+unescape('%E9')+"lectionner...";
            }

            eval(lobjAjax.response);
            document.getElementById('selAreaCode').disabled = false;
            document.getElementById('selAreaCode').options.length=0;
            for(i in larrOptions) {
                document.getElementById('selAreaCode').options[lintCounter] = new Option(larrOptions[i],i);
                lintCounter++;
            }
            if(lintCounter==2) {
                //postForm();
            }

        } else {
            // if there are no regions, just submit the form.
            //postForm();
        }
    };
    lobjAjax.runAJAX();
}

function getAreaCodesByCountry(countrycode){
    var lobjAjax2 = new sack("http://orangespotfinder.coverage-finder.com/ajax/dial_ajax_process.php");
    lobjAjax2.setVar("action","areacodebycountry");
    lobjAjax2.setVar("country", countrycode);

    lobjAjax2.onCompletion = function() {
        if (lobjAjax2.response != "empty"){
            lintCounter=0;
            var larrOptions = [];
            if(lang=='EN') {
                larrOptions["-1"] = "Select...";
            } else {
                larrOptions["-1"] = "S"+unescape('%E9')+"lectionner...";
            }

            eval(lobjAjax2.response);
            document.getElementById('selAreaCode').disabled = false;
            document.getElementById('selAreaCode').options.length=0;

            for(i in larrOptions) {
                document.getElementById('selAreaCode').options[lintCounter] = new Option(larrOptions[i],i);
                lintCounter++;
            }
        } else {
            // if there are no regions, just submit the form.
            //postForm();
        }
    };
    lobjAjax2.runAJAX();
}

function changeLanguage(pstrNewLang) {
    var thisURL = unescape(window.location.pathname);
    var otherURL = unescape(window.location);
    if (thisURL.indexOf("news_dynamic.php")>0) {
        otherURL = "news_dynamic.php";
    }
    lobjAjax = new sack("http://orangespotfinder.coverage-finder.com/shared/setLanguage.php");
    lobjAjax.method="GET";
    lobjAjax.setVar("lang",pstrNewLang);
    lobjAjax.onCompletion = function() {
       // alert(otherURL);
        window.location.href=otherURL;
    }
    lobjAjax.runAJAX();

}

function fnValidateQuicksearch() {
	if (document.getElementById("txtQuickSearch").value == "" || document.getElementById("txtQuickSearch").value == "Postcode/ZIP or location or Venue Name") {
		document.getElementById("divQuickSearchError").style.display = "block";
		}
	else {
		document.getElementById("divQuickSearchError").style.display = "none";
		document.getElementById('frmQuick').submit();
		}
	return false;
	}


function fnValidateAdvancedSearch() {
	if (document.getElementById("selCountry").value == -1 && document.getElementById("selSiteType").value == -1) {
		document.getElementById("divAdvancedSearchError").style.display = "block";
		}
	else {
		document.getElementById("divAdvancedSearchError").style.display = "none";
		document.getElementById('frmAdv').submit();
		}

	return false;
	}