/* 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_ski");

	var checkDontShowAnySurvey;
	checkDontShowAnySurvey=getCookie("dont_show_any_survey");
		
	var surveyRnd = Math.ceil(Math.random() * 4); // PageID Random Number
		//alert(surveyRnd);
		
	if ((YouWrote == null) && (checkDontShowAnySurvey == null)) {

		if (surveyRnd == 4) { // 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_ski','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 = "";
		}
	}
	
// ad call initialization
if ((typeof adServer!="undefined") && (typeof enableAds!="undefined") && (enableAds == "true")) {
	// ad serevr javascript functionality
		function showAds(numberAAMB) { document.write(numberAAMB); }

	// bserver ad call insert the adx variables
	document.write('<SCR' + 'IPT SRC="' + adServer + ad9 + ad10 + ad11 + ad12 + ad2 + ad4 + ad6 + ad3 + ad5 + ad7 + ad8 + '" type="text/JavaScript" language="JavaScript">');
	document.write('</SCR' + 'IPT>');


	// bserver ad call for transitional/voken ads
	document.write('<SCR' + 'IPT SRC="' + adServer + ad1 + '" type="text/JavaScript" language="JavaScript">');
	document.write('</SCR' + 'IPT>');
}

	// 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;
	
var currentTime = new Date()
var timenow;
var datenow;
var dated = currentTime.getDate()
var day = currentTime.getDay()
var month = currentTime.getMonth()
var year = currentTime.getFullYear()
var hour = currentTime.getHours()
var min = currentTime.getMinutes()
var sec = currentTime.getSeconds();
/*if (minutes < 10)
minutes = "0" + minutes
timenow = hours + ":" + minutes + " ";
if(hours > 11){
timenow = timenow + "PM";
} else {
timenow = timenow + "AM";
}
*/

var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

    if (hour > 12) {
      hour = hour - 12;
      add = " PM";
    } else {
      hour = hour;
      add = " AM";
    }
    if (hour == 12) {
      add = " p.m.";
    }
    if (hour == 00) {
      hour = "12";
    }
timenow=((hour<=9) ? "0" + hour : hour) + ":" + min + " "  + add;

datenow = dayNames[day] + ", " + monthNames[month] + " " + dated + ", " + year + " " + timenow;




//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
	//alert("into");
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}




var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i in params)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


function focusBody(){
	window.focus();
}


function loadPoll(poll_name) {
if (poll_name.length==0) { 
  document.getElementById("poll_insert").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
	var url="/vote/index.php";
	url=url+"?poll_name="+poll_name;
	url=url+"&sid="+Math.round(Math.random() * 100000000);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	//return false;
}


function stateChanged() { 
	if (xmlHttp.readyState==4) { 
		if(!document.getElementById("poll_insert")) return false;
		document.getElementById("poll_insert").innerHTML=xmlHttp.responseText;
	}
}


function loadResult(poll_name_passed) {
	loadPoll(poll_name_passed + '&result=true');
}


function submitpoll(poll_name_passed) {
temp_vote_var = document.getElementById('vote');
temp_vote_input_var = temp_vote_var.getElementsByTagName('input');
var submit_full_url = "";
	for(i=0;i<temp_vote_input_var.length;i++) {
		if (temp_vote_input_var[i].checked==true) {
			submit_full_url = poll_name_passed + "&" + poll_name_passed + "=" + temp_vote_input_var[i].getAttribute('value') + "&send=Submit";
		}
	}
	loadPoll(submit_full_url);
}

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 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<pairs3.length; i++){
key3   = pairs3[i].split("=")[0];
value3 = pairs3[i].split("=")[1];
a3 = value3;
b3=b3+"/"+a3;
}
current=b3;
current=current+"";
//////////////////////////////////////////////
var match=match*1;

if(myarray){myarray.sort(mysortfn);
////////////////////////////////////////////////////
/*document.write("<b>Your Favourites</b>:<br />");
for (var x = 0; x <= 7; x++)
   {
   var a = myarray[x];
   var b=a.join(":");
   var my_array=b.split(":");
   if(my_array[0]!=''){ my_array[0]=my_array[0].replace("@", "'");
    document.write(" <a href="+my_array[1]+">"+my_array[0]+"</a><br />"); }
   }*/
////////////////////////////////////////////////////
var a7 = myarray[7];
b7=a7.join(":");
var my_array=b7.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{}

array7=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array7=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array7=myarray[7].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
////////////////////////////////////////////////////
var a6 = myarray[6];
b6=a6.join(":");
var my_array=b6.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{}

array6=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array6=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array6=myarray[6].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
///////////////////////////////////////////////////
var a5 = myarray[5];
b5=a5.join(":");
var my_array=b5.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{}

array5=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array5=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array5=myarray[5].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
///////////////////////////////////////////////////
var a4 = myarray[4];
b4=a4.join(":");
var my_array=b4.split(":");

if(current==my_array[1] && match!= 1 && 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{}

array4=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array4=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array4=myarray[4].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
////////////////////////////////////////////////////
var a3 = myarray[3];
b3=a3.join(":");
var my_array=b3.split(":");

if(current==my_array[1] && match != 1 && 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{}

array3=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array3=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array3=myarray[3].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
////////////////////////////////////////////////////
var a2 = myarray[2];
b2=a2.join(":");
var my_array=b2.split(":");

if(current==my_array[1] && match!= 1 && 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{}

array2=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array2=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array2=myarray[2].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
////////////////////////////////////////////////////
var a1 = myarray[1];
b1=a1.join(":");
var my_array=b1.split(":");


if(current==my_array[1] && match!= 1 && 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{}

array1=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array1=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array1=myarray[1].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
////////////////////////////////////////////////////
var a = myarray[0];
b=a.join(":");
var my_array=b.split(":");
if(current==my_array[1] && match!= 1 && 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{}

array0=""+my_array[0]+"','"+my_array[1]+"','"+count+"','"+my_array[3]+"";
match = 1;
}
else if(my_array[1]=='' && match!= 1)
{
array0=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
match = 1;
}
else
{
array0=myarray[0].join("','");
if(match==1){match = 1;}
else{match = 0;}
}
////////////////////////////////////////////////////

if(match==0 && my_array[1]!='')
{
array0=""+city+"','"+current+"','"+hits+"','"+prodtype+"";
myarray ="[ ['"+array0+"'],['"+array1+"'],['"+array2+"'],['"+array3+"'],['"+array4+"'],['"+array5+"'],['"+array6+"'],['"+array7+"'] ];";
//document.write(myarray);
}
else
{
myarray ="[ ['"+array0+"'],['"+array1+"'],['"+array2+"'],['"+array3+"'],['"+array4+"'],['"+array5+"'],['"+array6+"'],['"+array7+"'] ];";
//document.write("<br />"+myarray);
}

set_cookie("fav", myarray, "2068", "10", "29","/","","");
return("");
}
}
	
addLoadEvent(popUpLinks);			
addLoadEvent(focusBody);
addLoadEvent(exitLinks);
addLoadEvent(initSearch);
addLoadEvent(init_ie6_dropdown);
 
//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 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 = "";
		}	
	}
}

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<pairsr3.length; 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<pairsr3.length; 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"; 
		//document.searchform.drop_location.value="Refine Search"; 
		//document.searchform.prodtype.value="";
	}
	else {
		document.searchform.prodname.value="Chercher un endroit"; 
		//document.searchform.drop_location.value="Raffiner la recherche"; 
		//document.searchform.prodtype.value="";
	}
}	

function setprodtype(prodtype) {	
	switch(prodtype) {
		case "airport" :
			document.searchform.drop_location.value="Airports";
			break;
		case "all" :
			document.searchform.drop_location.value="All";
			break;
		case "attraction" :
			document.searchform.drop_location.value="Attractions";
			break;
		case "city" :
			document.searchform.drop_location.value="Cities/Towns";
			break;
		case "golf" :
			document.searchform.drop_location.value="Golf Courses";
			break;
		case "park" :
			document.searchform.drop_location.value="Parks";
			break;
		case "ski" :
			document.searchform.drop_location.value="Ski Resorts";
			break;
		case "school" :
			document.searchform.drop_location.value="Schools";
			break;
	}
	document.searchform.prodtype.value=prodtype;
	showhidelayer("locationtype_list","none");
}

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 */


