<!--
if (top.frames.length!=0) top.location=self.document.location;
//-->	

var v_coef=0;
var v_coef_wrap=70;
var v_coef_full=100;
var id_page=0;
var courpage=0;
var coursection=0;
var p_choose_country=false;
var yaduflash="";

window.onload=init;

function init() {
	o=_(courpage);
	oo=_(coursection);
	if (o) {
		o.style.fontWeight="bold";
	}
	if (oo) {
		oo.style.fontWeight="bold";
	}
	agt=navigator.userAgent.toLowerCase();
	if(agt.indexOf("msie 6")==-1){
		if (document.body.className=='benefits' || document.body.className=='offers' || document.body.className=='points') {
			myPartSRC=_('main_menu1').src.split('.png');		
			mySRC=myPartSRC[0]+'_over.png';
			_('main_menu1').src=mySRC;	
		} else if (document.body.className=='apply') {
			myPartSRC=_('main_menu2').src.split('.png');
			mySRC=myPartSRC[0]+'_over.png';
			_('main_menu2').src=mySRC;			
		}
	}
}

function _(o) {
	if (!o) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById(o)) return false;
	return document.getElementById(o);
}

function getWidth() {
  myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	myWidth = document.body.clientWidth;
  }
  return myWidth;
}	

function getHeight() {
  myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function xhrRequest(type) {
	var xhrSend;
	if (!type) {
		type = 'text';
	}
	if (window.ActiveXObject) {
		try {
			xhrSend = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhrSend = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhrSend = new XMLHttpRequest();
		if (xhrSend.overrideMimeType) {
			xhrSend.overrideMimeType('text/' + type);
		}
	}
	return (xhrSend);
}

function update_lng(myVar) {
	if (!_('select_language') || !_('select_country')) return false;
	if (!myVar) myVar=0;
	myCountry = _('select_country').value;
	if (myCountry != "") {
		var xhrRec = xhrRequest('html');
		xhrRec.onreadystatechange = function() {
			if (xhrRec.readyState == 4 && xhrRec.status == 200) {
				if (parseInt(xhrRec.responseText)==1) {
					myVal=xhrRec.responseText;
					_('select_language').innerHTML='<option selected="selected" value="'+myVal.substring(1, 3)+'">'+myVal.substring(1, 3)+'</option>';
					_('select_language').style.display='none';						
				} else if (parseInt(xhrRec.responseText)==2) {
					myVal=xhrRec.responseText;
					myredir=myVal.split('2');
					window.location.replace(myredir[1]);
				} else {
					_('select_language_container').innerHTML = xhrRec.responseText;
					affiDiv('select_language');	
				}
			}
		}
		xhrRec.open("POST",'/ajaxreturn.php',true);
		xhrRec.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhrRec.setRequestHeader("Accept-Charset","UTF-8");
		xhrRec.send("TYPE=select_pays&myCountry="+myCountry+"&myVar="+myVar);				
	}
}	

function update_indicatif() {
	if (!_('COUNTRY') && !_('COUNTRY_REG')) return false;
	if (_('COUNTRY_REG')) {
		myCountry = document.forms.my_form.COUNTRY_REG.options.value;
	} else {
		myCountry = document.forms.my_form.COUNTRY.options.value;
	}
	if (typeof(myCountry)=='undefined') {
		if (_('COUNTRY_REG')) {
			myCountry = _('COUNTRY_REG').value;
		} else {
			myCountry = _('COUNTRY').value;
		}
	}
	if (myCountry != "") {
		var xhrRec = xhrRequest('html');
		xhrRec.onreadystatechange = function() {
			if (xhrRec.readyState == 4 && xhrRec.status == 200) {
				if (parseInt(xhrRec.responseText)!=1) {
					myIndic=xhrRec.responseText;
					reg=myIndic.split('_');
					_('MOBILEPHONE_INDICATIF').value=reg[0];
					_('MOBILEPHONE_INDICATIF_VISU').innerHTML=reg[0];
					if (_('MOBILEPHONE_INDICATIF_EX')) _('MOBILEPHONE_INDICATIF_EX').innerHTML=reg[1];
				}
			}
		}
		xhrRec.open("POST",'/ajaxreturn.php',true);
		xhrRec.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhrRec.setRequestHeader("Accept-Charset","UTF-8");
		xhrRec.send("TYPE=select_indicatif&myCountry="+myCountry);				
	}
}	

function valid_form_welcome() {
	country=_('select_country').value;
	lng=_('select_language').value;
	if (country=='') {
		alert('Please select a country.');
		return false;
	}
	if (lng=='' && _('select_language').style.display=='block') {
		alert('Please select a language.');
		return false;
	}
	var xhrRec = xhrRequest('html');
	xhrRec.onreadystatechange = function() {
		if (xhrRec.readyState == 4 && xhrRec.status == 200) {
			if (parseInt(xhrRec.responseText)==1) {
				x = xhrRec.responseText.length;
				x--;			
				_('content_coming_loc').innerHTML=xhrRec.responseText.substr(1, x);
				if (document.all) {
					_('select_country').style.display='none';
					_('select_language').style.display='none';
				}
				launch_popin('popin_coming_soon');									
			} else {
				window.location.replace(xhrRec.responseText);
			}
		}
	}
	xhrRec.open("POST",'/ajaxreturn.php',true);
	xhrRec.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhrRec.setRequestHeader("Accept-Charset","UTF-8");
	xhrRec.send("TYPE=valid_form_welcome&country="+country+"&lng="+lng);								
}

function do_redir_country_lng(spe) {
	if (_('select_country') && _('select_language')) {
		country=_('select_country').value.toLowerCase();
		lng=_('select_language').value.toLowerCase();
		if (lng!='' && lng!=' ') {
			if (p_choose_country) spe=2;
			if (typeof(spe)=='undefined') spe=1;
			var xhrRec = xhrRequest('html');
			xhrRec.onreadystatechange = function() {
				if (xhrRec.readyState == 4 && xhrRec.status == 200) {
					window.location.replace(xhrRec.responseText);	
				}
			}
			xhrRec.open("POST",'/ajaxreturn.php',true);
			xhrRec.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xhrRec.setRequestHeader("Accept-Charset","UTF-8");
			xhrRec.send("TYPE=swap_country_lng&country="+country+"&lng="+lng+"&id_page="+id_page+"&spe="+spe);
		}
	}
}

function valid_form_coming_soon() {
	email=_('email_coming').value;
	country=_('select_country').value;
	lng=_('select_language').value;
	if (country=='') {
		return false;
	}
	if (lng=='' && _('select_language').style.display=='block') {
		return false;
	}
	var xhrRec = xhrRequest('html');
	xhrRec.onreadystatechange = function() {
		if (xhrRec.readyState == 4 && xhrRec.status == 200) {
			if (parseInt(xhrRec.responseText)==1) {
				x = xhrRec.responseText.length;
				x--;
				_('content_coming_loc').innerHTML=xhrRec.responseText.substr(1, x);
			} else {
				alert(xhrRec.responseText);
			}
		}
	}
	xhrRec.open("POST",'/ajaxreturn.php',true);
	xhrRec.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhrRec.setRequestHeader("Accept-Charset","UTF-8");
	xhrRec.send("TYPE=valid_form_coming_soon&country="+country+"&lng="+lng+"&email="+email);								
}

function affiDiv(mydiv) {		
	if (_(mydiv)) {
		_(mydiv).style.display="block";
	} else if (mydiv.style.display=='none') {
		mydiv.style.display="block";
	}	
}

function classRepl(whatReplace,style) {
	for(var i=0;i<whatReplace.length;i++) {	
   		whatReplace[i].style.display=style;
     }
}

function getElementsByClassName(needle) {
	var my_array = document.getElementsByTagName("*");
	var retvalue = new Array();
	var i;
	var j;
	for (i=0,j=0;i<my_array.length;i++) {
		var c = " " + my_array[i].className + " ";
		if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i];
	}
	return retvalue;
}

function send_mail(personne, domaine, tld) {
	ret = personne+'@'+domaine+'.'+tld;
	return location.href='mailto:'+ret;
}

function getnextnode(source,o) {
	if (!o) return false;
	oo=false;
	if (o.firstChild) return o.firstChild;
	if (o.nextSibling) return o.nextSibling;
	o=o.parentNode;
	while (!oo && o && (o!=source)) {
		oo=o.nextSibling;
		o=o.parentNode;
	}
	return oo;
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity; 
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100; 
	// Vieux Mozilla & Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, Firefox and Mozilla recents, CSS3
	obj.style.opacity = opacity/100;
}

function start_video() {
	launch_popin('popin_video');
	setTimeout("launch_video()", 1500);
}

function stop_video() {
	if (_('player_video')) {
		_('player_video').style.display='none';
		_('player_video').style.visibility='hidden';
		_('content_player_video').innerHTML='<div id="player_video"></div>';
	}
	setTimeout("close_popin('popin_video')", 400);
}

function cache_select(on) {
	fs=self.document.forms;
	for (fff in fs) {
		if (fs[fff]) {
			if (fs[fff].elements) {
				for (ee in fs[fff].elements) {
					if (fs[fff].elements[ee]) if (fs[fff].elements[ee].options) {
						fs[fff].elements[ee].style.visibility=(on) ? "hidden":"visible";
					}
				}
			}
		} 
	}
	o=_("diapo");
	if (o) o.style.visibility=(on) ? "hidden":"visible";
	if (yaduflash!="") {
		t=yaduflash.split(",");
		for (i=0;i<t.length;i++) {
			if (t[i]!="") {
				o=_(t[i]);
				if (o) o.style.visibility=(on) ? "hidden":"visible";
			}
		}
	}
}

function popin_promo() {
	if (_('OPTIN_0').checked) {
	launch_popin2('popin');
	cache_select('LANGUAGE');
	}
}

function close_popin_promo() {
	close_popin2('popin');
	cache_select(false);
}

function launch_popin(myPopin, coef) {
	myDiv=_(myPopin);
	myWrap=_('wrapper');
	if (!myDiv || !myWrap) return false;
	if (!coef) {
		coef=parseInt(v_coef);
		screenW=getWidth();
		screenH=getHeight();
		affiDiv(myWrap);
		myWrap.style.height=screenH+'px';
		myWrap.style.width=screenW+'px';
		affiDiv(myDiv);
		myDivW=parseInt(myDiv.offsetWidth);
		myDivH=parseInt(myDiv.offsetHeight);
		myDivT=((screenH-myDivH)/2)-(((screenH-myDivH)/2)/2);
		if (myDivT <0) myDivT=0;
		myDivL=(997-myDivW)/2;
		if (myDivL <0) myDivL=0;
		myDiv.style.top=myDivT+'px';
		myDiv.style.left=myDivL+'px';
	}
	coef=coef+10;
	if (coef < 70) {
		setOpacity(myWrap, coef);
	}
	if (coef < 101) {
		setOpacity(myDiv, coef);
		setTimeout("launch_popin('"+myPopin+"',"+coef+");", 100);
	}	
}

function launch_popin2(myPopin, coef) {
	myDiv=_(myPopin);
	myWrap=_('wrapper2');
	if (!myDiv || !myWrap) return false;
	if (!coef) {
		coef=parseInt(v_coef);
		screenW=getWidth();
		screenH=getHeight();
		affiDiv(myWrap);
		myWrap.style.height=screenH+'px';
		myWrap.style.width=screenW+'px';
		affiDiv(myDiv);
		myDivW=parseInt(myDiv.offsetWidth);
		myDivH=parseInt(myDiv.offsetHeight);
		myDivT=((screenH-myDivH)/2)-(((screenH-myDivH)/2)/2)+150;
		if (myDivT <0) myDivT=0;
		myDivL=(997-myDivW)/2;
		if (myDivL <0) myDivL=0;
		myDiv.style.bottom=myDivT+'px';
		myDiv.style.left=myDivL+'px';
	}
	coef=coef+10;
	if (coef < 70) {
		setOpacity(myWrap, coef);
	}
	if (coef < 101) {
		setOpacity(myDiv, coef);
		setTimeout("launch_popin2('"+myPopin+"',"+coef+");", 100);
	}	
}

function close_popin(myPopin, coef) {
	myDiv=_(myPopin);
	myWrap=_('wrapper');
	if (myPopin=='popin_coming_soon' && _('select_country').style.display=='none') {
		_('select_country').style.display='block';
		if (_('select_country').value!='UKD') _('select_language').style.display='block';		
	}	
	if (!myDiv || !myWrap) return false;
	if (!coef) coef=parseInt(v_coef_full);
	coef=coef-10;
	if (coef < v_coef_wrap) setOpacity(myWrap, coef);
	setOpacity(myDiv, coef);
	if (coef > 0) {
		setTimeout("close_popin('"+myPopin+"',"+coef+");", 100);
	} else {
		setOpacity(myDiv, v_coef);
		setOpacity(myWrap, v_coef);
		myDiv.style.display='none';
		myWrap.style.display='none';
		myWrap.style.height='1px';
		myWrap.style.width='1px';
	}	
}

function close_popin2(myPopin, coef) {
	myDiv=_(myPopin);
	myWrap=_('wrapper2');
	if (myPopin=='popin_coming_soon' && _('select_country').style.display=='none') {
		_('select_country').style.display='block';
		if (_('select_country').value!='UKD') _('select_language').style.display='block';		
	}	
	if (!myDiv || !myWrap) return false;
	if (!coef) coef=parseInt(v_coef_full);
	coef=coef-10;
	if (coef < v_coef_wrap) setOpacity(myWrap, coef);
	setOpacity(myDiv, coef);
	if (coef > 0) {
		setTimeout("close_popin2('"+myPopin+"',"+coef+");", 100);
	} else {
		setOpacity(myDiv, v_coef);
		setOpacity(myWrap, v_coef);
		myDiv.style.display='none';
		myWrap.style.display='none';
		myWrap.style.height='1px';
		myWrap.style.width='1px';
	}	
}

function email_check(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true					
}

function check_textarea(mytxt, sens, obj) {
	switch (sens) {
		case 0:	
			if (obj.value==mytxt) obj.value='';
		break;
		case 1:
			if (obj.value=='') obj.value=mytxt;
		break;
		default:
		break;
	}
}

function AppelPopin(myPopin, coef) {
	myDiv=_(myPopin);
	if (!myDiv) return false;
	if (!coef) {
		coef=parseInt(v_coef);
		screenW=getWidth();
		screenH=getHeight();
		affiDiv(myDiv);
		myDivW=parseInt(myDiv.offsetWidth);
		myDivH=parseInt(myDiv.offsetHeight);
		myDivT=((screenH-myDivH)/2)-(((screenH-myDivH)/2)/2)+100;
		if (myDivT <0) myDivT=0;
		myDivL=(897-myDivW)/2;
		if (myDivL <0) myDivL=0;
		myDiv.style.top=myDivT+'px';
		myDiv.style.left=myDivL+'px';
	}
	coef=coef+10;
}

function AppelPopin2(myPopin, coef) {
	cache_select('LANGUAGE');
	myDiv=_(myPopin);
	if (!myDiv) return false;
	if (!coef) {
		coef=parseInt(v_coef);
		screenW=getWidth();
		screenH=getHeight();
		affiDiv(myDiv);
		myDivW=parseInt(myDiv.offsetWidth);
		myDivH=parseInt(myDiv.offsetHeight);
		myDivT=((screenH-myDivH)/2)-(((screenH-myDivH)/2)/2)+100;
		if (myDivT <0) myDivT=0;
		myDivL=(997-myDivW)/2;
		if (myDivL <0) myDivL=0;
		myDiv.style.bottom=myDivT+'px';
		myDiv.style.left=myDivL+'px';
	}
	coef=coef+10;
}

function ClosePopin() {
	_('popin_exchange').style.display='none';
}
function ClosePopin2() {
	_('popin_exchange2').style.display='none';
	cache_select(false);
}