function submitsearch(){
	var nulllist=document.searchform.statenm_list;
	var countylist=document.searchform.statenm;
	
	var dateent=document.searchform.date1;
	var dateexit=document.searchform.date2;
	
	var alldatesx=document.searchform.alldates;
	
	if(alldatesx.checked==true){
		dateent.disabled=true;
		dateexit.disabled=true;
	} else {
		dateent.value=document.searchform.yrent.value+"-"+document.searchform.moent.value+"-"+document.searchform.dayent.value;
		document.searchform.yrent.disabled=true;
		document.searchform.moent.disabled=true;
		document.searchform.dayent.disabled=true;

		dateexit.value=document.searchform.yrexit.value+"-"+document.searchform.moexit.value+"-"+document.searchform.dayexit.value;
		document.searchform.yrexit.disabled=true;
		document.searchform.moexit.disabled=true;
		document.searchform.dayexit.disabled=true;
	}
	
	for(var i=0,l=nulllist.length;i<l;i++){
		nulllist.options[i].selected=false;
	}
	for(var k=0,m=countylist.length;k<m;k++){
		countylist.options[k].selected=true;
	}
	
		if(countylist.length>20){
			alert(countylist.length+" Countries Selected:\nPlease limit your country list to 20 countries or less\nor select the ALL COUNTRIES option.");
			var selall = document.searchform.alldates;
			document.searchform.yrent.disabled=(selall.checked);
			document.searchform.moent.disabled=(selall.checked);
			document.searchform.dayent.disabled=(selall.checked);
			
			document.searchform.yrexit.disabled=(selall.checked);
			document.searchform.moexit.disabled=(selall.checked);
			document.searchform.dayexit.disabled=(selall.checked);
		
		return false;
		}	
	
	if(countylist.length<1){
		alert("Please select a country");
		nulllist.focus();
		

	
	var selall = document.searchform.alldates;
	document.searchform.yrent.disabled=(selall.checked);
	document.searchform.moent.disabled=(selall.checked);
	document.searchform.dayent.disabled=(selall.checked);
	
	document.searchform.yrexit.disabled=(selall.checked);
	document.searchform.moexit.disabled=(selall.checked);
	document.searchform.dayexit.disabled=(selall.checked);
		
		return false;
	}
	
	return true;
};

function sortlist(obj){
	var tmpArray = new Array();
	for(var i=0,l=obj.options.length;i<l;i++){
		tmpArray[i]=obj.options[i].text;
	}
	tmpArray.sort();
	for(var i=0,l=tmpArray.length;i<l;i++){
		obj.options[i].text = obj.options[i].value = tmpArray[i];
	}
};

function deleteOption(object, index) {
    object.options[index] = null;
};


function addOption(object, text, value) {
    var defaultSelected = false;
    var selected = false;
    var optionName = new Option(text, value, defaultSelected, selected);    
    object.options[object.length] = optionName;
};

function checkallselect(rtol){
	var allcheck = document.searchform.statenm;
	var clist = document.searchform.statenm_list;
	if(allcheck.length>0 && rtol==1){
		if(allcheck.options[0].value=="+ ALL COUNTRIES"){
			if(allcheck.length>0){
				for (var i=1,l=allcheck.options.length;i<l;i++) {
						addOption(clist,allcheck.options[i].text, allcheck.options[i].value);
				}
				for (var i=allcheck.options.length-1;i>0;i--) {
						deleteOption(allcheck,i);
				}
			}
		}
	}
}

function unselectselections(){
	var list = document.searchform.statenm_list;
	var listb = document.searchform.statenm;

	if(list.length>0){
		for (var i=0,l=list.options.length;i<l;i++) {
			list.options[i].selected=false;
		}
	}
	
	if(listb.length>0){
		for (var c=0,k=listb.options.length;c<k;c++) {
			listb.options[c].selected=false;
		}
	}
}

function movetoright(fromObject, toObject, rtol){
	var allcheck = document.searchform.statenm;
	if(allcheck.length>0 && rtol==1){
		if(allcheck.options[0].value=="+ ALL COUNTRIES"){
			alert("All Countries are already selected.");
			document.searchform.reset();
			allcheck.options[0].selected=true;
			return false;
		}
	}
	
	for (var i=0,l=fromObject.options.length;i<l;i++) {
		if (fromObject.options[i].selected)
			addOption(toObject,fromObject.options[i].text, fromObject.options[i].value);
	}
	for (var i=fromObject.options.length-1;i>-1;i--) {
		if (fromObject.options[i].selected)
			deleteOption(fromObject,i);
	}
	sortlist(toObject);
	checkallselect(rtol);
	unselectselections();
	sortlist(toObject);
	sortlist(fromObject);
};

function includealldates(obj){
	document.searchform.yrent.disabled=(obj.checked);
	document.searchform.moent.disabled=(obj.checked);
	document.searchform.dayent.disabled=(obj.checked);
	
	document.searchform.yrexit.disabled=(obj.checked);
	document.searchform.moexit.disabled=(obj.checked);
	document.searchform.dayexit.disabled=(obj.checked);
};