function getTagValue(tagName) {
        for (i=0;i<editParams.length;i++) {  
                if (editParams[i][0]==tagName) {
                        return editParams[i][1]; 
                } 
        }
};

function disabledState(labelset1){
	isl_clearError();
	// if there is a City field, reset it if the country is changed
	if(typeof document.int_storelocator.city != 'undefined'){
		document.getElementById("citylabel").style.color=getTagValue('cityLabelOff');
		document.getElementById("city").options[0].selected="true";
		document.getElementById("city").disabled="true";
	}
	if(labelset1==""){
		document.getElementById("statelabel").style.color=getTagValue('stateLabelOff');
		document.getElementById("state").options[0].selected="true";
		document.getElementById("state").disabled="true";
	}else{
		document.getElementById("statelabel").style.color=getTagValue('stateLabelOn');
	}
};

function disabledCity(labelset2){
	isl_clearError();
	if(typeof document.int_storelocator.city != 'undefined'){
		if(labelset2 ==""){
			document.getElementById("citylabel").style.color=getTagValue('cityLabelOff');
			document.getElementById("city").options[0].selected="true";
			document.getElementById("city").disabled="true";
		}else{
			document.getElementById("citylabel").style.color=getTagValue('cityLabelOn');
		}
	}
};

function showStoryList() {
var errorFlag = false; //setting a flag of false meaning no error
isl_clearError();
	if (document.int_storelocator.country.value == "") {
		errorFlag = isl_showError('country_error',document.getElementById('country_error_message').innerHTML);
	}
	if (document.getElementById('state_dropdown') && document.int_storelocator.country.value != "" && document.int_storelocator.state.value == "") {
		errorFlag = isl_showError('state_error',document.getElementById('state_error_message').innerHTML);
	}
	// error handling when there is no state dropdown but there is a city dropdown
	if (!document.getElementById('state_dropdown') && document.getElementById('city_dropdown') && document.int_storelocator.country.value != "" && document.int_storelocator.city.value == "") {
		errorFlag = isl_showError('city_error',document.getElementById('city_error_message').innerHTML);
	}
	if (errorFlag) { //if flag is true
		return false; //do not load store details
	}
	
	// check allows City select field to be removed if not needed
	if(typeof document.int_storelocator.city != 'undefined'){
		// load city store list if selected, or state list if city not selected
		if (document.int_storelocator.city.value != "") {
			if (getTagValue('refreshWindow')) { //if you want the store list loaded on a new screen
				window.location.href = document.int_storelocator.city.value;
			}
			else {ajaxFunction(document.int_storelocator.city.value+"&layout=noheaders&temp=_isl_storelist_ajax",'internationalstorelocator_results');}
		}
		else if (document.getElementById('state_dropdown') && document.int_storelocator.state.value != ""){
			showState();
		}
	}else{showState();}
};

function showCountryList() {
var errorFlag = false; //setting a flag of false meaning no error
isl_clearError();
	if (document.int_storelocator.country.value == "") {
		errorFlag = isl_showError('country_error',document.getElementById('country_error_message').innerHTML);
	}
	if (errorFlag) { //if flag is true
		return false; //do not load store details
	}
	valueArray = document.int_storelocator.country.value.split('&');
	if (getTagValue('countryisStorylist')) { // if you have specified in the page parameter that the Country category contains stories and not further categories
		if (getTagValue('refreshWindow')) { //if you want the store list loaded on a new screen
			window.location.href = valueArray[0]+"&layout="+getTagValue('defaultLayout')+"&temp=isl_storelist";
		}
		else {ajaxFunction(valueArray[0]+"&layout=noheaders&temp=_isl_storelist_ajax",'internationalstorelocator_results');}
	}
	else {
		if (getTagValue('refreshWindow')) { //if you want the store list loaded on a new screen
			window.location.href = valueArray[0]+"&layout="+getTagValue('defaultLayout')+"&temp=isl_scatlist";
		}
		else {ajaxFunction(valueArray[0]+"&layout=noheaders&temp=_isl_scatlist_ajax",'internationalstorelocator_results');}
	}
};

function showState() {
	//field value contains ajax specific layout and temp so we need to remove this before we use it
	valueArray = document.int_storelocator.state.value.split('&');
	if (getTagValue('refreshWindow')) { //if you want the store list loaded on a new screen
		window.location.href = valueArray[0]+"&layout="+getTagValue('defaultLayout')+"&temp=isl_scatlist";
	}
	else {ajaxFunction(valueArray[0]+"&layout=noheaders&temp=_isl_scatlist_ajax",'internationalstorelocator_results');}
};

//output error into a span with a specific id where id=id of span and errorText=the error msg
function isl_showError(id,errorText) {
	var errorDiv = document.getElementById(id); //set id names
	errorDiv.innerHTML = errorText; //replace text in span tag
	return true; //if there was an error run the function	
};

//if the error has been fixed but other errors exist clear old error msg
function isl_clearError() {
	var spans = document.getElementsByTagName("span"); //create array of all span tags
	for (var i = 0; i < spans.length; i++) { //loop through span tags
		var idName = spans[i].id; //get the id value of span tags
		if (idName.match(/_error$/)) { //if id value has _error
			spans[i].innerHTML = ''; // clear error
		}
	}
};
