/* SURVEY */
function getCookie(cookie_name) {
	if (document.cookie) {
		index = document.cookie.indexOf(cookie_name);
		if (index != -1) {
			namestart = (document.cookie.indexOf("=", index) + 1);
			nameend = document.cookie.indexOf(";", index);
			if (nameend == -1) {nameend = document.cookie.length;}
			YouWrote = document.cookie.substring(namestart, nameend);
			return YouWrote;
		}
	}
}

function SetCookie (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=/")) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
	
function windowOpener(url) {
	var newWinObj=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=280');
}

function loadsurvey(lang, extra_param) {
	YouWrote=getCookie("theSurvey09_splitscreen");

	var checkDontShowAnySurvey;
	checkDontShowAnySurvey=getCookie("dont_show_any_survey");
		
	var surveyRnd = Math.ceil(Math.random() * 2); // PageID Random Number
		//alert(surveyRnd);
		
	if ((YouWrote == null) && (checkDontShowAnySurvey == null)) {

		if (surveyRnd == 1) { // show survey to user with rand #
		
			var exp = new Date();
			var expDays = 2;
			var exp = new Date();
			exp.setTime(exp.getTime() + (expDays*1*24*60*60*1000));
			SetCookie ('theSurvey09_splitscreen','later',exp,"/");

			var exp = new Date();
			var expDays = 30;
			var exp = new Date();
			exp.setTime(exp.getTime() + (expDays*1*24*60*60*1000));
			SetCookie ('dont_show_any_survey','true',exp,"/");
			
			windowOpener("/static/survey/survey_" + lang + ".htm");
			
		} else {
			
			var exp = new Date();
			var expDays = 30;
			var exp = new Date();
			exp.setTime(exp.getTime() + (expDays*1*24*60*60*1000));
			SetCookie ('dont_show_any_survey','true',exp,"/");
			
		}
	}
}

/* SURVEY */


function exitLinks(){
	if(!document.getElementsByTagName) return false;
	var extlinks = document.getElementsByTagName("a");
	for (i=0;i<extlinks.length;i++){
		if(extlinks[i].className == "extlink"){
		extlinks[i].onclick = function(){
			return popLink(this);
			}
		}
	}
	
}

function popLink(whichlink){
	var source = whichlink.getAttribute("href");
	window.open(source, '_blank');
	return false;
}

function addLoadEvent(func){
		var oldonload = window.onload;
		if (typeof window.onload != 'function'){
			window.onload = func;
		}else{
			window.onload = function(){
			oldonload();
			func();
			}
		}
}
	function WxbuttonCheckCity() {
		if ((this.document.searchform.recherche.value == "enter city") || (this.document.searchform.recherche.value == "votre ville")) {
			this.document.searchform.recherche.value = "";
		}
	}
	
	function CheckCity() {
		if ((this.document.searchform.recherche.value == "enter city") || (this.document.searchform.recherche.value == "votre ville")) {
			this.document.searchform.recherche.value = "";
		}
	}
	
	function CheckCityTravel() {
		if ((this.document.searchTravelform.recherche.value == "enter city") || (this.document.searchTravelform.recherche.value == "votre ville")) {
			this.document.searchTravelform.recherche.value = "";
		}
	}
	

	// bookmark us function
	function bookmark(siteTitle, url){

		if (document.all) {
			window.external.AddFavorite(url, siteTitle);
		} else if (window.sidebar) {
			window.sidebar.addPanel(siteTitle, url, "")
		}

	}
	
	var getURLStringForIndexPages = document.URL;
	
	var screenSize = 800;
	
	var d = document;
	

function focusBody(){
	window.focus();
}


function popUpLinks(){
if(!document.getElementsByTagName) return false;
	var poplinks = document.getElementsByTagName("a");
	for (i=0;i<poplinks.length;i++){
		if(poplinks[i].className == "poplink"){
		poplinks[i].onclick = function(){
			return popUp(this);
			}
		}
	}
}

function popUp(whichlink){
		var source = whichlink.getAttribute("href");
		window.open(source, '_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=485,height=405');
		return false;
}

function image_popup(link,window_name,height,width, windowtitle) {
window.open( link, window_name, "height =" + height + ", width =" + width + ",toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=auto,resizable=no" );
}

function image_popup1(link,window_name,height,width) {
window.open( link, "newwindow", "height =" + height + ", width =" + width + ",toolbar=no,location=no,directories=no,statusbar=no,menubar=no,scrollbars=auto,resizable=no" );
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );
  
  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );

  if ( secure )
        cookie_string += "; secure";

  document.cookie = cookie_string;
}

function mysortfn(a,b) {
if (a[2]<b[2]) return -1;
if (a[2]>b[2]) return 1;
return 0;
}



function favourites(city,provcode,quesrystring,prodtype){
if(get_cookie("fav")==null)
{
		x = [
		['','','',''],
		['','','',''],
		['','','',''],
		['','','',''],
		['','','',''],
		['','','',''],
		['','','',''],
		['','','','']
];
}
else{
var x = get_cookie("fav");}
var myarray = eval(x);
/*if(city.length >= 38){
var city=city.substr(0,35);
city=city+"...";
}*/
if(provcode==''){var city=city;}
else{var city=city+" ,"+provcode;}
city=city.replace("'", "@");
var hits=hits*1;
hits="01";
var current3=quesrystring;
var prodtype=prodtype;
//////////////////////////////////////////////
var b3;
b3="";
query3 = current3;
pairs3 = query3.split("&");
for(i=0; i<2; i++){
key3   = pairs3[i].split("=")[0];
value3 = pairs3[i].split("=")[1];
a3 = value3;
b3=b3+"/"+a3;
}
current=b3;
current=current+"";
//alert(current);
//////////////////////////////////////////////
var match=match*1;

if(myarray){myarray.sort(mysortfn);
////////////////////////////////////////////////////
a = new Array();
b = new Array();
cityarray = new Array();
for (var y = 7; y >= 0; y--) {
	a[y] = myarray[y];
	b[y]=a[y].join(":");
	var my_array=b[y].split(":");
	if(current==my_array[1])
	{
	count=my_array[2];
	count=count*1;
	count=count+01;
	var count2=count+'';
	var length=count2.length;
	length=length*1;
	if(length==1){count="0"+count;}
	else{}

	cityarray[y]=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
	match = 1;
	}
	else if(my_array[1]=='' && match!= 1)
	{
	cityarray[y]=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
	match = 1;
	}
	else
	{
	cityarray[y]=myarray[y].join("','");
	if(match==1){match = 1;}
	else{match = 0;}
	}
	
}
////////////////////////////////////////////////////

if(match==0 && my_array[1]!='')
{
cityarray[0]=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
myarray ="[ ['"+cityarray[0]+"'],['"+cityarray[1]+"'],['"+cityarray[2]+"'],['"+cityarray[3]+"'],['"+cityarray[4]+"'],['"+cityarray[5]+"'],['"+cityarray[6]+"'],['"+cityarray[7]+"'] ];";
//document.write(myarray);
}
else
{
myarray ="[ ['"+cityarray[0]+"'],['"+cityarray[1]+"'],['"+cityarray[2]+"'],['"+cityarray[3]+"'],['"+cityarray[4]+"'],['"+cityarray[5]+"'],['"+cityarray[6]+"'],['"+cityarray[7]+"'] ];";
//document.write("<br />"+myarray);
}

set_cookie("fav", myarray, "2068", "10", "29","/","","");
return("");
}
}
	
addLoadEvent(popUpLinks);			
addLoadEvent(focusBody);
addLoadEvent(exitLinks);
addLoadEvent(initSearch);
addLoadEvent(init_ie6_dropdown);

function clearText() {
	if (lang=='en') {
		if (document.searchform.prodname.value == "Search for Location") { 
			document.searchform.prodname.value = "";
		}
	}
	else {
		if (document.searchform.prodname.value == "Chercher un endroit") { 
			document.searchform.prodname.value = "";
		}	
	}
} 
 
//My favourite locations script begins
if(get_cookie("fav")!=null){
	var cookieval=get_cookie("fav");
	var xr = get_cookier("fav");
	var myarrayr = eval(xr);
	myarrayr.sort(mysortfnr);
}		
function mysortfnr(a,b) {
	if (a[2]<b[2]) return 1;
	if (a[2]>b[2]) return -1;
	return 0;
}

function get_cookier ( cookie_name ){
  var resultsr = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( resultsr )
	return ( unescape ( resultsr[1] ) );
  else
	return null;
}

function cookieavail() {
	clearText();
	if (get_cookie("fav")!=null) { 	
		document.getElementById('mylocations').style.display='block';
		document.getElementById('mylocations').style.visibility='visible';
	}
	else {
		document.getElementById('mylocations').style.display='none';
		document.getElementById('mylocations').style.visibility='hidden';
	}					
}

function displayfavs(getcookieval,myarrayr,prodtypeq,citytt,provcodett,urlr,golfcode,parkscode,airportcode,attractionscode,skicode,schoolcode,placecode){
	var returnval="";
	if(getcookieval!=null){
		var br4;
		br4="";
		for (var x = 0; x <= 7; x++) {
		   var ar = myarrayr[x];
		   
		   var br=ar.join(":");
		   var my_arrayr=br.split(":");
			if(my_arrayr[0]!=''){ 
				var cityrr=my_arrayr[0];
				var cityss=cityrr.split(",");
				citysr=cityss[0];
				provsr=cityss[1];
				
				if(citysr.length >= 38)	{
					var citysr=citysr.substr(0,35);
					citysr=citysr+"...";
				}
				citysr=citysr.replace("@", "'");
				ar4=my_arrayr[1];
				br4=br4+":"+my_arrayr[1];
				returnval=returnval+"<li><a href="+my_arrayr[1]+"?ref=topnav_"+prodtypeq+"_savedcity>"+citysr+", "+provsr+"</a></li>"; 
			
			}
		}
	   var br5=br4.split(":");
	      
	   if(prodtypeq=="weather" || prodtypeq=="golffx" || prodtypeq=="skifx" || prodtypeq=="attractionsfx" || prodtypeq=="airportfx" || prodtypeq=="parksfx" || prodtypeq=="schools" ) {
	   //////////////////////////////////////////
		var br3;
		br3="";
		pairsr3 = urlr.split("&");
		for(i=0; i<2; i++){
			 keyr3   = pairsr3[i].split("=")[0];
			 valuer3 = pairsr3[i].split("=")[1];
			 ar3 = valuer3;
			 br3=br3+"/"+ar3;
		 }
		 //alert(br3);
		  //////////////////////////////////////////
		 if(br3!=br5[1] && br3!=br5[2] && br3!=br5[3] && br3!=br5[4] && br3!=br5[5] && br3!=br5[6] && br3!=br5[7] && br3!=br5[8]){	 
		  
			if(golfcode!='' || parkscode!='' || (placecode!='' && prodtypeq=="weather")  || attractionscode!='' || airportcode!='' || skicode!='' || schoolcode!=''){
				returnval=returnval+"<li><a href="+br3+">"+citytt+", "+provcodett+"</a></li>"; 
			}
		 } else { }
	   } else { }
		
	 } else {
	 
		 //////////////////////////////////////////
		 var br3;
		 br3="";
		 pairsr3 = urlr.split("&");
		 for(i=0; i<2; i++){
			 keyr3   = pairsr3[i].split("=")[0];
			 valuer3 = pairsr3[i].split("=")[1];
			 ar3 = valuer3;
			 br3=br3+"/"+ar3;
		 }
	 
		returnval=returnval+"<li><a href="+br3+">"+citytt+", "+provcodett+"</a></li>";
	 
	 }
	return returnval;
							   
}

//My favourite locations script ends

//Nav hover fix for IE6
function init_ie6_dropdown() {
	if (document.all&&document.getElementById) { 
		navRoot = document.getElementById("top_blue_nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") { 
				node.onmouseover=function() { this.className+=" over";  }
				node.onmouseout=function() { this.className=this.className.replace(" over", ""); }
			}
		}
	}
}


//Show/hide layers
function showhidelayer(id, visibility) {
	document.getElementById(id).style.display = visibility;
}

//check form for blank search
function checksearchformEn(searchterm){ 
	if((searchterm=='Search for Location')||(searchterm=='')){
		alert('Please enter your search criteria.');
		clearText();
		document.searchform.prodname.focus(); 
	}
	else { document.searchform.submit(); }
}

function checksearchformFr(searchterm){ 
	if((searchterm=='Chercher un endroit')||(searchterm=='')){
		alert('Veuillez entrer vos critères de recherche.');
		clearText();
		document.searchform.prodname.focus(); 
	}
	else { document.searchform.submit(); }
}

function initSearch() {
	if (lang=='en') {
		document.searchform.prodname.value="Search for Location"; 
		
	}
	else {
		document.searchform.prodname.value="Chercher un endroit"; 
  	}
}	


function checkWhitespace() {
	val=document.searchform.prodname.value;
	reWhiteSpace = new RegExp(/^\s+$/);
	// Check for white space
	if((reWhiteSpace.test(val))||(val=="")) {
		if (lang=='en') {document.searchform.prodname.value="Search for Location";}
		else {document.searchform.prodname.value="Chercher un endroit";}
	}
}


function populateH1(value) {
	document.getElementById("h1em").innerHTML=value;
}


function setHome(url) { 
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage(url);
}
function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}

/* form validation functions start*/

function validateLoginForm(theForm,lang) {
 var reason = "";
  if(theForm.user){
	reason += validateEmail(theForm.user,lang); /* for forgot password form*/
  }
  if(theForm.email){
	reason += validateEmail(theForm.email,lang);
  }
  if(theForm.password){
	 reason += validatePassword(theForm.password,lang);
  }
    if (reason != "") {
	if(lang=="fr"){
		alert("Certains champs doivent etre modifies.:\n" + reason);
	}else{
		alert("Some fields need correction:\n" + reason);
	}	
	return false;
  }

  return true;
}

function validateRegisterForm(theForm,lang) {
 var reason = "";

  if((theForm.email)&&(!theForm.confirmemail)){
		reason += validateConfirmEmail(theForm.email,theForm.email,lang);
  }
  if((theForm.email)&&(theForm.confirmemail)){
	 reason += validateConfirmEmail(theForm.email,theForm.confirmemail,lang);
  }
  /*reason += validatePhone(theForm.phone)*/
  if(theForm.password){
	 reason += validateConfirmPassword(theForm.password,theForm.confirmpassword,lang);
  }
  if(theForm.displayname){
	reason += validateField(theForm.displayname,lang);
  } 
  if(theForm.postal){
	reason += validateField(theForm.postal,lang);
  }

  if (theForm.eighteenorolder){
	  if (theForm.eighteenorolder.checked==false){ 	 
		  if(lang=="fr"){
			reason += 'Êtes-vous âgé de 18 ans ou plus ?\n';
		  }else{
			reason += 'Please identify that you are 18 years of age or older.\n';
		  }
		}
  }

  if (theForm.releasecontentrights){
	if (theForm.releasecontentrights.checked==false){ 	
		if(lang=="fr"){
			reason += 'Veuillez cocher la case « Je consens a respecter votre politique relative a l\'Information soumise ».\n';
		}else{
			reason += 'Please check or tick off the "I agree to your Submissions Policy" checkbox.\n';
		} 		
	}
  }
  if (theForm.sendInfoAboutTWN){
	  if (theForm.sendInfoAboutTWN.checked==true){ 	 
			theForm.sendInfoAboutTWN.value="yes";
		}
  }
  if (theForm.sendInfoFromSponsors){
	if (theForm.sendInfoFromSponsors.checked==true){ 	 
 		theForm.sendInfoFromSponsors.value="yes";
	}
  }
  if (reason != "") {
	if(lang=="fr"){
		alert("Certains champs doivent etre modifies.:\n" + reason);
	}else{
		alert("Some fields need correction:\n" + reason);
	}	
	return false;
  }

  return true;
}


function validateField(fld,lang) {
	var error = "";
	if (trim(fld.value) == "") {
		 
		if(fld.name=="postal"){
			if(lang=="fr"){
				error  += 'Veuillez inscrire votre code postal.\n';
			}else{
				error = "Please enter your postal or zip code.\n";
			} 			
		}else if(fld.id=="text_content"){
			if(lang=="fr"){
				error  += 'Veuillez inscrire le nom de la ville le plus pres du lieu ou vous avez pris la photo ou enregistre la video.\n';
			}else{
				error = "Please enter the nearest city/town to where you shot the photo or video.\n";
			} 			
		}else if(fld.id=="weathercondition"){
			if(lang=="fr"){
				error  += 'Veuillez decrire les conditions meteorologiques presentes au moment ou vous avez pris la photo ou enregistre la video.\n';
			}else{
				error = "Please enter the weather condition when you shot the photo or video.\n";
			} 			
		}else if(fld.id=="mediacategory"){
			if(lang=="fr"){
				error  += 'Veuillez decrire le type de media qui decrit le mieux la photo ou la video que vous vous preparez a nous envoyer.\n';
			}else{
				error = "Please select the Media Category that best describes the type or photo or video you are going to upload.\n";
			} 
			
		}else if(fld.id=="message"){
			if(lang=="fr"){
				error  += 'Veuillez cocher la case « Je cede les droits relatifs au contenu ».\n';
			}else{
				error = "Please enter your description.\n";
			} 
		}else{
			if(lang=="fr"){
				error  += 'Veuillez inscrire le '+fld.name+'.\n';
			}else{
				error = "Please enter your "+fld.name+".\n";
			} 
			
		}
	}
	if(fld.value=="mm-dd-yyyy"){
		 
		if(lang=="fr"){
			error  += 'Veuillez inscrire la date a laquelle la capture a eu lieu.\n';
		}else{
			error = "Please enter the date shot.\n";
		} 		
	 }
	 if (fld.value == "N/A") {
		 
		if(lang=="fr"){
			error  += 'Veuillez cocher la case « Je cede les droits relatifs au contenu ».\n';
		}else{
			error = "Please choose your province/state.\n";
		} 	
		
	}
	if (fld.value == "choose") {
		 
		if(lang=="fr"){
			error  += 'Etes-vous age de 18 ans ou plus ?\n';
		}else{
			error = "Please choose your year of birth.\n";
		} 
		
	}
	
	return error;
}


function validatePassword(fld,lang) {
	var error = "";
	if (fld.value=="") {
		 
		if(lang=="fr"){
			error  += 'Veuillez inscrire un mot de passe.\n';
		}else{
			error = error+ "Please enter a password.\n";
		} 		
	}else if (fld.value.length < 4) {
		 
		if(lang=="fr"){
			error  += 'Votre mot de passe devrait contenir au moins 4 caracteres.\n';
		}else{
			error = error+ "Your password should be at least 4 characters.\n";
		} 			
	}
	
	return error;
}

function validateConfirmPassword(fld,fld1,lang) {
	var error = "";
	if (fld.value=="") {
		 
		if(lang=="fr"){
			error  += 'Veuillez inscrire un mot de passe.\n';
		}else{
			error = error+ "Please enter a password.\n";
		} 	
		
	}else if (fld.value.length < 4) {
		 
		if(lang=="fr"){
			error  += 'Votre mot de passe devrait contenir au moins 4 caracteres.\n';
		}else{
			error = error+ "Your password should be at least 4 characters.\n";
		} 
		
	}
	if (fld.value != fld1.value) {		 
		
		if(lang=="fr"){
			error  += "Les mots de passe ne correspondent pas.\n";
		}else{
			error = error+ "The passwords don't match.\n";
		} 	
	}
	
	return error;
}

function validateEmail(fld,lang) {
	var error="";
	var tfld = trim(fld.value);         
	// value of field with whitespace trimmed off
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
	if (fld.value == "") {
		if(lang=="fr"){
			error  += 'Veuillez inscrire une adresse de courriel.\n';
		}else{
			error = "Please enter an email address.\n";
		}
		
	} else if (!emailFilter.test(tfld)) {              //test email for illegal characters
		if(lang=="fr"){
			error  += 'Veuillez inscrire une adresse de courriel valide.\n';
		}else{
			error = "Please enter a valid email address.\n";
		}
		
	} else if (fld.value.match(illegalChars)) {
		if(lang=="fr"){
			error  += 'Veuillez inscrire une adresse de courriel valide.\n';
		}else{
			error = "The email address contains invalid characters.\n";
		}
		
	} 
	return error;
}
function validateConfirmEmail(fld,fld1,lang) {
	var error="";
	var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]\*\?]/ ;
   
	if (fld.value == "") {
		if(lang=="fr"){
			error  += 'Veuillez inscrire une adresse de courriel.\n';
		}else{
			error = "Please enter an email address.\n";
		}
	} else if (!emailFilter.test(tfld)) {              //test email for illegal characters
		if(lang=="fr"){
			error  += 'Veuillez inscrire une adresse de courriel valide.\n';
		}else{
			error = "Please enter a valid email address.\n";
		}
	} else if (fld.value.match(illegalChars)) {
		
		if(lang=="fr"){
			error  += 'Veuillez inscrire une adresse de courriel valide.\n';
		}else{
			error = "The email address contains invalid characters.\n";
		}
	} 
	if (fld.value != fld1.value) {	 
		if(lang=="fr"){
			error  += 'Les adresses de courriel ne correspondent pas.\n';
		}else{
			error = error+ "The email addresses don't match.\n";
		}		
	}
	return error;
}

function validatePhone(fld,lang) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Please enter your phone number.\n";
        
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        
    }
    return error;
}

function validateUploadForm(theForm,lang) {
 var reason = "";
  reason += validateField(theForm.text_content,lang);
  reason += validateField(theForm.title,lang);
  reason += validateField(theForm.mediacategory,lang);
  reason += validateField(theForm.weathercondition,lang);
  reason += validateField(theForm.dateshot,lang);
  reason += validateFile(theForm.filenametwn,lang);
  //this is how you use the form array field in javascript
  theForm.metadateshot.value=theForm.dateshot.value;
  if((theForm.weathercondition.value!="othertext")&&(theForm.weathercondition.value!="autres")){
	 theForm.metauserweathercondition.value=theForm.weathercondition.value;
  }
  theForm.metausermediacategory.value=theForm.mediacategory.value;
  if (reason != "") {
	if(lang=="fr"){
		alert("Certains champs doivent etre modifies.:\n" + reason);
	}else{
		alert("Some fields need correction:\n" + reason);
	}	
	
	return false;
  }


  return true;
}

function validateFile(fld,lang) {
	var error = "";
	if (fld.value.length < 1) {
		if(lang=="fr"){
			error  += 'Veuillez joindre une photo ou une video.\n';
		}else{
			error = error+ "Please attach a photo or video.\n";
		} 
	}
	
	return error;
}

function submitForgotpassword(thisform,lang){
	success=validateLoginForm(thisform,lang);
	if(success==true){ thisform.submit(); return true;}
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}
/* form validation functions end*/



function GetXmlHttpObject() {
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}


/* current content box ajax starts */
	
var xmlHttp;
function loadCCB(lang, product, countrycode, provcode, placecode, ccb_id, profiles_append_params) {
	if (lang.length==0) { 
		document.getElementById("ccb_container").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/ccb/ccb_process.php";
	url=url+"?lang="+lang;
	url=url+"&product="+product;
	url=url+"&placecode="+placecode;
	url=url+"&provcode="+provcode;
	url=url+"&countrycode="+countrycode;
	url=url+"&ccb_id="+ccb_id;
	url=url+profiles_append_params;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedCCB;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChangedCCB() { 
	if (xmlHttp.readyState==4) { 
		document.getElementById("ccb_container").innerHTML=xmlHttp.responseText;
	}
}

/* current content box ajax ends */


/* your weather city page ajax starts */
	
var xmlHttpFM1;
function fmajax(lang, placecode, countrycode, product, pagecontent, plplat, plplong, configFMfilename, extraparam1) {
	if (lang.length==0) { 
		document.getElementById("fm1_container").innerHTML="";
		return;
	}
	xmlHttpFM1=GetXmlHttpObject();
	if (xmlHttpFM1==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="/fm_citypage_ajax.php?";
	url=url+"lang="+lang;
	url=url+"&placecode="+placecode;	
	url=url+"&countrycode="+countrycode;
	url=url+"&extraparam1="+extraparam1; // ie dogparkcode
	url=url+"&product="+product;
	url=url+"&pagecontent="+pagecontent;
	url=url+"&plplat="+plplat;
	url=url+"&plplong="+plplong;
	url=url+"&configFMfilename="+configFMfilename;
	url=url+"&sid="+Math.random();
	xmlHttpFM1.onreadystatechange=stateChangedFM1;
	xmlHttpFM1.open("GET",url,true);
	xmlHttpFM1.send(null);
} 

function stateChangedFM1() { 
	if (xmlHttpFM1.readyState==4) { 
		document.getElementById("fm1_container").innerHTML=xmlHttpFM1.responseText;
	}
}

/* your weather city page ajax ends */

if(typeof getCookie('gn')!="undefined") { var gn = getCookie('gn'); } else { var gn = ""; }
if(typeof getCookie('by')!="undefined") { var by = getCookie('by'); } else { var by = ""; }