
function getCountry(){
var country="US";
var language = navigator.language || navigator.browserLanguage;
var langCode = language.substr(0,2).toLowerCase();

if (langCode == "ar"){ // arabic languages
	 country=language.substr(3,2);
}
else if (langCode == "be")
	country="BE";
else if (langCode == "bg")
	country="BG";
else if (langCode == "cs")
	country="CS";
else if (langCode == "cz")
	country="CZ";
else if (langCode == "da")
	country="DK"; // denmark
else if (langCode == "de"){
	temp=language.substr(3,2).toLowerCase();
	if (temp == "at")
		country="AT";
	else if (temp == "ch")
		country="CH";
	else if (temp == "li")
		country="LI";
	else if (temp == "lu")
		country="LU";
	else 
		country="DE";
}
else if (langCode == "el")
	country="GR";
else if (langCode == "en"){
	temp=language.substr(3,2);
	if (temp == "us")
		country="US";
	else if (temp == "au")
		country="AU";
	else if (temp == "bz")
		country="BZ";
	else if (temp == "ca")
		country="CA";
	else if (temp == "gb")
		country="GB";
	else if (temp == "ie")
		country="IE";
	else if (temp == "jm")
		country="JM";
	else if (temp == "nz")
		country="NZ";
	else if (temp == "tt")
		country="TT";
	else if (temp == "za")
		country="ZA";
	else country="US";
}
else if (langCode == "es"){
	temp=language.substr(3,2);
	if (temp == "ar")
		country="AR";
	else if (temp == "co")
		country="CO"; // costa rica
	else if (temp == "cr")
		country="CR";
	else if (temp == "mx")
		country="MX"; // mexico
	else
		country="ES";
}
else if (langCode == "et")
	country="EE"; //estonia
else if (langCode == "eu")
	country="ES"; // spain
else if (langCode == "fa")
	country="IR"; // iran
else if (langCode == "fi")
	country="FI"; // finland
else if (langCode == "fo")
	country="DK"; // denmark speaking Faroese
else if (langCode == "fr"){
	temp=language.substr(3,2);
	if (temp == "be")
		country="BE";
	else if (temp == "ca")
		country="CA";
	else if (temp == "ch")
		country="CH";
	else if (temp == "LU")
		country="LU";
	else
		country="FR";
}
else if (langCode == "gd"){
	if (language.substr(3,2) == "ie")
		country="IE";
	else
		country="GB"; // scotland but refer to United Kingdom
}
else if (langCode == "he") // hebrew
	country="IL"; // Israel
else if (langCode == "hi") // hindi
	country="IN"; // india
else if (langCode == "hr")
	country="HR"; // Croatia
else if (langCode == "hu")
	country="HU"; // hungary
else if (langCode == "in")
	country="ID"; // indonesia
else if (langCode == "is")
	country="IS"; // iceland
else if (langCode == "it"){
	if (language.substr(3,2) == "ch")
		country="CH";
	else
		country="IT";
}
else if (langCode == "ja")
	country="JP";
else if (langCode == "ji")
	country="IL"; //Yiddish language, spoken by some jewish people so refer to Israel or Germany
else if (langCode == "ko")
	country="KR"; // refer to south corean
else if (langCode == "nl"){
	if (language.substr(3,2) == "be")
		country="BE";
	else
		country="NL"; // netherlands
}
else if (langCode == "pl")
	country="PL";
else if (langCode == "pt")
	country="PT";
else if (langCode == "rm")
	country="RO"; // romania
else if (langCode == "ro")
	country="RO";
else if (langCode == "sv"){
	if (language.substr(3,2) == "fi")
		country="FI"; // finland
	else
		country="SE"; // sweden
}
else if (langCode == "tr")
	country="TR"; // turkish
else if (langCode == "uk")
	country="UA"; // Ukraine
else if (langCode == "zh"){
	temp=language.substr(3,2);
	if (temp == "cn")
		country="CN"; // china
	else if (temp == "hk")
		country="HK"; // Hong Kong
	else if (temp == "sg")
		country="SG"; // singapore
	else if (temp == "tw")
		country="TW"; // Taiwan
	else 
		country="CN";
}

else
	country="US";
return country;
}

function goToInsert(){
	var temp = getCountry();
	var locUrl = "/insert/getHouseInfo.php?country=" + temp;
	location.href = locUrl;	
}

function newSessionCookie(name,value,hours){
	var date = new Date();
	date.setTime(date.getTime()+(hours*60*60*1000));
	var endDate = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+ endDate +"; path=/";
}

function trim( val ){
   return val.replace(/^\s*|\s*$/g,"");
}

function isNumeric(val){
	if(!val)
		return false;
	
	val = trim(val);
	if(val.length == 0)
		return false;
	index2 = val.indexOf('.');
	if(index2 ==0 || index2 == val.length)
		return false;
	for( i = 0; i<val.length; i++){
		var c = val.charAt(i);
		if(c <'0' || c>'9'){
			if(c!= '.')
				return false;
		}	
	}
	return true;
}

function isNumeric2(val){ // for integers only
	if(!val)
		return false;
	val = trim(val);
	if(val.length == 0)
		return false;
	for( i = 0; i<val.length; i++){
		var c = val.charAt(i);
		if(c<'0' || c>'9')
			return false;	
	}
	return true;
}

function getCountryName(val){
	if(!val)
		return "Not classified";
	if(val =="AU") return "Australia";
	else if(val == "AT") return "Austria";
	else if(val =="BE") return "Belgium";
	else if(val =="CA")   return "Canada";
	else if(val =="DK") return "Denmark";
	else if(val=="FI") return "Finland";
	else if(val=="FR") return "France";
	else if(val=="DE") return "Germany";
	else if(val=="IS") return "Iceland";
	else if(val=="IE") return "Ireland";
	else if(val=="IT") return "Italy";
	else if(val=="JP") return "Japan";
	else if(val=="MC") return "Monaco";
	else if(val=="MN") return "Mongolia";
	else if(val=="NL") return "Netherlands";
	else if(val=="NZ") return "New Zealand";
	else if(val=="NO") return "Norway";
	else if(val=="ES") return "Spain";
	else if(val=="SE") return "Sweden";
	else if(val=="CH") return "Switzerland";
	else if(val=="GB") return "United Kingdom";
	else if(val=="UK") return "United Kingdom";
	else if(val=="US") return "United States";
	else
		return "Not classified";	
}


