
var allSP=[[ "","All States/Provinces"]];
var allS=[[ "","All States"]];
var allP=[[ "","All Provinces"]];

var us=[[ "1","Alabama"], [ "2","Alaska"], [ "3","Arizona"], [ "4","Arkansas"], [ "5","California"], [ "6","Colorado"], [ "7","Connecticut"], [ "8","Delaware"], [ "9","District of Columbia"], [ "10","Florida"], [ "11","Georgia"], [ "13","Hawaii"], [ "14","Idaho"], [ "15","Illinois"], [ "16","Indiana"], [ "17","Iowa"], [ "18","Kansas"], [ "19","Kentucky"], [ "20","Louisiana"], [ "21","Maine"], [ "22","Maryland"], [ "23","Massachusetts"], [ "24","Michigan"], [ "25","Minnesota"], [ "26","Mississippi"], [ "27","Missouri"], [ "28","Montana"], [ "29","Nebraska"], [ "30","Nevada"], [ "31","New Hampshire"], [ "32","New Jersey"], [ "33","New Mexico"], [ "34","New York"], [ "35","North Carolina"], [ "36","North Dakota"], [ "37","Ohio"], [ "38","Oklahoma"], [ "39","Oregon"], [ "40","Pennsylvania"], [ "42","Rhode Island"], [ "43","South Carolina"], [ "44","South Dakota"], [ "45","Tennessee"], [ "46","Texas"], [ "48","Utah"], [ "49","Vermont"], [ "51","Virginia"], [ "52","Washington"], [ "53","West Virginia"], [ "54","Wisconsin"], [ "55","Wyoming"]];

var line=[["","------------"]];

var canada=[[ "56","Alberta"], [ "57","British Columbia"], [ "58","Manitoba"], [ "59","New Brunswick"], [ "60","Newfoundland and Labrador"], [ "61","Northwest Territories"], [ "62","Nova Scotia"], [ "63","Ontario"], [ "64","Prince Edward Island"], [ "65","Quebec"], [ "66","Saskatchewan"], [ "67","Yukon Territory"]];

var countries=[[ "","All Countries"], [ "1","United States of America"], [ "2","Canada"], [ "7","Afghanistan"], [ "8","Albania"], [ "9","Algeria"], [ "210","Angola"], [ "10","Anguilla"], [ "11","Antigua"], [ "12","Argentina"], [ "212","Armenia"], [ "13","Aruba"], [ "14","Australia"], [ "15","Austria"], [ "16","Azerbaijan"], [ "18","Bahamas"], [ "19","Bahrain"], [ "20","Balearic Islands"], [ "21","Bangladesh"], [ "22","Barbados"], [ "23","Belarus"], [ "24","Belgium"], [ "25","Belize"], [ "26","Benin"], [ "27","Bermuda"], [ "213","Bhutan"], [ "28","Bolivia"], [ "29","Bosnia and Herzegovina"], [ "30","Botswana"], [ "31","Brazil"], [ "32","British Guiana"], [ "33","British Honduras"], [ "34","British Virgin Islands"], [ "35","Brunei Darussalam"], [ "36","Bulgaria"], [ "37","Burkina-Faso"], [ "39","Cambodia"], [ "40","Cameroon"], [ "41","Canary Islands"], [ "221","Cape Verde"], [ "42","Cayman Islands"], [ "43","Central African Republic"], [ "218","Chad"], [ "44","Channel Islands"], [ "45","Chile"], [ "46","China"], [ "47","Colombia"], [ "48","Congo"], [ "49","Cook Islands"], [ "50","Costa Rica"], [ "51","Cote D' Ivoire"], [ "52","Croatia"], [ "55","Cyprus"], [ "57","Czech Republic"], [ "58","Denmark"], [ "59","Dominica"], [ "60","Dominican Republic"], [ "61","Ecuador"], [ "62","Egypt"], [ "64","El Salvador"], [ "65","England"], [ "226","Equatorial Guinea"], [ "222","Eritrea"], [ "66","Estonia"], [ "67","Ethiopia"], [ "68","Falkland Islands"], [ "214","Fiji"], [ "69","Finland"], [ "71","France"], [ "72","French West Africa"], [ "74","Gabon"], [ "75","Georgia"], [ "76","Germany"], [ "77","Ghana"], [ "78","Gibraltar"], [ "79","Greece"], [ "80","Greenland"], [ "81","Grenada"], [ "82","Guadeloupe"], [ "3","Guam"], [ "83","Guatemala"], [ "220","Guinea-Bissau"], [ "84","Guyana"], [ "85","Haiti"], [ "87","Honduras"], [ "89","Hungary"], [ "90","Iceland"], [ "91","India"], [ "92","Indonesia"], [ "94","Iraq"], [ "95","Ireland"], [ "96","Isle of Man"], [ "97","Israel"], [ "98","Italy"], [ "100","Jamaica"], [ "101","Japan"], [ "102","Jersey"], [ "103","Jordan"], [ "104","Kazakhstan"], [ "105","Kenya"], [ "106","Korea"], [ "107","Kuwait"], [ "108","Kyrgyzstan"], [ "109","Laos"], [ "110","Latvia"], [ "111","Lebanon"], [ "216","Lesotho"], [ "112","Liberia"], [ "113","Libya"], [ "114","Liechtenstein"], [ "115","Lithuania"], [ "116","Luxembourg"], [ "117","Macedonia (F.Y.R.O.M.)"], [ "118","Madagascar"], [ "119","Madeira"], [ "120","Malawi"], [ "121","Malaysia"], [ "122","Mali"], [ "123","Malta"], [ "124","Mauritius"], [ "125","Mexico"], [ "126","Moldova"], [ "127","Monaco"], [ "128","Mongolia"], [ "224","Montserrat"], [ "129","Morocco"], [ "130","Mozambique"], [ "131","Myanmar"], [ "217","Namibia"], [ "132","Nauru"], [ "134","Nepal"], [ "135","Netherlands"], [ "136","Netherlands Antilles"], [ "137","Netherlands E. Indies"], [ "138","Netherlands Guiana"], [ "139","Nevis"], [ "140","New Guinea"], [ "141","New Zealand"], [ "142","Nicaragua"], [ "143","Nigeria"], [ "144","Niue"], [ "145","Northern Ireland"], [ "219","North Korea"], [ "146","Norway"], [ "147","Oman"], [ "148","Pakistan"], [ "149","Palestinian Territories"], [ "150","Panama"], [ "151","Papua New Guinea"], [ "152","Paraguay"], [ "153","Peru"], [ "154","Philippines"], [ "155","Poland"], [ "156","Portugal"], [ "4","Puerto Rico"], [ "157","Qatar"], [ "158","Romania"], [ "159","Russia"], [ "161","Saint Kitts and Nevis"], [ "162","Saint Lucia"], [ "163","Saint Vincent/Grenadines"], [ "211","Sao Tome e Principe"], [ "164","Saudi Arabia"], [ "165","Scotland"], [ "166","Senegal"], [ "206","Serbia & Montenegro"], [ "167","Seychelles"], [ "169","Sierra Leone"], [ "170","Singapore"], [ "171","Slovakia"], [ "172","Slovenia"], [ "173","South Africa"], [ "174","Spain"], [ "175","Sri Lanka"], [ "177","Surinam"], [ "178","Swaziland"], [ "179","Sweden"], [ "180","Switzerland"], [ "182","Taiwan"], [ "225","Tajikistan"], [ "183","Tanzania"], [ "184","Thailand"], [ "185","Togo"], [ "186","Tonga"], [ "187","Trinidad and Tobago"], [ "188","Tunisia"], [ "189","Turkey"], [ "190","Turkmenistan"], [ "191","Turks & Caicos Islands"], [ "5","U. S. Pacific Territories"], [ "202","U.S. Virgin Islands"], [ "192","Uganda"], [ "193","Ukraine"], [ "194","United Arab Emirates"], [ "196","Uruguay"], [ "198","Uzbekistan"], [ "199","Venezuela"], [ "200","Vietnam"], [ "203","Wales"], [ "205","Yemen"], [ "223","Zaire"], [ "208","Zambia"], [ "209","Zimbabwe"]];
							


function checkCountry() {
	var doc = document.qsearch;
	var val = doc.CRY.options[doc.CRY.selectedIndex].value; 
	var numOptions = 0;
	var obj = document.forms['qsearch'].STS;
	var showBlock = "block";
	if (val == 1) { // USA
		clearDropDown();
		loadDropDown(obj, allS, numOptions);
		loadDropDown(obj, us, numOptions+1);	
		doLabel("none", "block", "none");
	} else if (val == 2) { // Canada
		clearDropDown();
		loadDropDown(obj, allP, numOptions);
		loadDropDown(obj, canada, numOptions+1);	
		doLabel("none", "none", "block");
	} else if (val == 0) { // All Countries
		loadAll();
		showBlock = "block";
	} else { // not USA or Canada
		loadAll();
		doLabel("none", "none", "none");
		showBlock = "none";
	}
	if (!((val == 1)||(val == 2)||(val == 3)||(val == 4)||(val == 5)||(val == 202)||(val == ""))){
		doc.ratind.checked = false;
		doc.ratind.disabled = true;
	} else {
		doc.ratind.disabled = false;
	}
	document.getElementById("divStateProvince").style.display = showBlock;
}
function checkState(){
	var doc = document.qsearch;
	var val = doc.STS.options[doc.STS.selectedIndex].value; 
	if (val != "") { 
		var isCanada = false;
		for(i=0; i<canada.length; i++){
			if (canada[i][0] == val){
				isCanada = true;
			}
		}
		if (isCanada){
			doc.CRY.options[2].selected = true;
		}else{//USA
			doc.CRY.options[1].selected = true;
		}
	}else{
		doc.CRY.options[0].selected = true;
	}
}
function doLabel(all, state, prov){
	document.getElementById("divAllLabel").style.display = all;
	document.getElementById("divStateLabel").style.display = state;
	document.getElementById("divProvinceLabel").style.display = prov;	
}
function trimString(str)
{
	if (!(str == "")) {
	while('' + str.charAt(0) == ' '){
		str=str.substring(1,str.length);
	}
	}
	//take out trailing spaces
	if (!(str == "")) {
	while (str.charAt(str.length - 1) == ' '){
    	str = str.substring(0, str.length - 1);
	}
	}
	return str;
}
function loadAll(){
	var numOptions = 0;
	var obj = document.forms['qsearch'].STS;
	doLabel("block", "none", "none");
	clearDropDown();
	loadDropDown(obj, allSP, numOptions);
	loadDropDown(obj, us, numOptions+1);
	numOptions = document.forms['qsearch'].STS.options.length;
	loadDropDown(obj, line, numOptions);	
	loadDropDown(obj, canada, numOptions+1);
	obj.options[0].selected = false;
}
function loadDropDown(obj, arr, numOptions){
	for(i=0; i<arr.length; i++){
		obj.options[numOptions+i] = new Option(arr[i][1],arr[i][0]);
	}
	obj.options[0].selected = true;
}
function clearDropDown(){
	document.forms['qsearch'].STS.options.length = 0;
}
function validateSize(obj, limit){
	var val = trimString(obj.value);
	if (val.length > limit){
		alert("You have exceeded the field limit of " + limit + " characters.");
		obj.value = val.substring(0, limit);
	}
}
function replaceDiacriticals(obj) {
    text = obj.value;
	text = replace(text,'‘',unescape('%27'));
	text = replace(text,'’',unescape('%27'));
    text = replace(text,'“',unescape('%22'));
	text = replace(text,'”',unescape('%22'));
	text = replace(text,unescape('%u2014'),'-');//replace em dash
	text = replace(text,unescape('%u2013'),'-');//replace en dash
	text = replace(text,unescape('%u2003'),' ');//replace em space
	text = replace(text,unescape('%u2003'),' ');//replace en space
    obj.value = text;
}
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length;
    var txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function launchwin(winurl,winname,winfeatures)
	{
		if (winname == null) {
			winname = 'search_form';
		}
		if (winfeatures == null) {
			winfeatures = 'height=500,width=500,resizable=yes,scrollbars=yes,toolbar=yes';
		}
		//This launches a new window and then
		//focuses it if window.focus() is supported.
		newwin = window.open(winurl,winname,winfeatures);
	}
