//Copywrite 2001 By WEBNet Logics.    Writen by Mal Formisano
//Last Update 25 Janvier 2010

var text = getHttpRequest("/includes/ce-cl/conf/postal.txt");
var postal_code = text.split("\r\n");

function getHttpRequest(url){
	var req;
	var buildUrl = "http://" + document.location.host + url;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
		} catch (e) {
			//alert("Permission could be denied for cross-domain scripting."); 
		}
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}




	var xmlHttp=req;
	xmlHttp.open("GET", buildUrl, false);
	xmlHttp.send();

	if (xmlHttp.status == "200"){
		return xmlHttp.responseText;
	}else{
		return false;
	}
}

function replaceString(oldS,newS,fullS) {
	for (var i=0; i<fullS.length; i++) {
		if (fullS.substring(i,i+oldS.length) == oldS) {
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
			}
	}
	return fullS;
}
function do_search(form){
	var all="";
	form.results.value="";
	if (form.lookup.value.length == 0){
		for(x=0;x<postal_code.length;x++){
			all = all + replaceString(";","\n",postal_code[x]);
			all = all + "\n\n";
		}	
		form.results.value=all;
	}else{
		if (form.lookup.value.length == 1){
			if (form.lang.value=="e")
				alert ("Sorry..\n\n Search request too short!");
			else				
				alert("La demande de recherche est trop courte.");
			return;
		}
		found=0;
		find = form.lookup.value.toUpperCase();			
		for(x=0;x<postal_code.length;x++){
			data=postal_code[x].split(";");				
			if (postal_code[x].toUpperCase().indexOf(find)>-1){
				all = all + replaceString(";","\n",postal_code[x]);
				all = all + "\n\n";						
				found=1;					
			}
		}
		if (found==0){
			if (form.lang.value=="e")
				alert("Sorry..\n\n\"" + form.lookup.value + "\" was not found.\n\nPlease try again.");
			else				
				alert("Aucun rsultat trouv.");
		}else{
			form.results.value=all;
		}
	}
}
