/*-----------------------------------------------------------
	Project:	Richelet
	Date : 	January 2008
	Last Update : 11/02/09
	Author:	C2iS - AFO			
-----------------------------------------------------------*/

try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}

/* ::::::: FONCTIONS ::::::::*/

/*Gestion details produit
function tabNav(){
	if($('.product_details_container').length) {
		initTabs();	
		$(".navTab li").removeClass("active");
		$(".product_details .layerTab").hide();
		
		$(".navTab li:first-child").addClass("active");
		$(".product_details .layerTab:first-child").show();
		
		$(".navTab li a").click(function(){
			
			$(".navTab li").removeClass("active");
			$(".product_details .layerTab").hide();
			
			var linkTab = $(this).attr("href").split("#");
			$("#"+linkTab[1]).show();
			
			$(this).parent("li").addClass("active");
			
			return false;
		});	
	}
}

function initTabs() {
	$('.product_details').before("<ul class='navTab'></ul>");
	$('.product_details h3').each(function(i){
		var idBlock = "#"+$(this).parent().attr("id");
		$('.navTab').append("<li><a href='"+idBlock+"'>"+$(this).html()+"</a></li>"); 	
		$(this).addClass("HideTitle");
	});
}
*/

/*Gestion Typo old*/
/*function changeTypoSize(oldClass, newClass) {
			    var elements = document.getElementsByTagName("body");
			    for( i = 0; i < elements.length; i++ ) {
			        if( elements[i].className == oldClass ) elements[i].className = newClass;
			    }
			}
*/

/*Gestion Typo*/
var min=12;
var max=17;
function increaseFontSize() {
   var body = document.getElementsByTagName('body');
   for(i=0;i<body.length;i++) {
      if(body[i].style.fontSize) {
         var s = parseInt(body[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      body[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var body = document.getElementsByTagName('body');
   for(i=0;i<body.length;i++) {
      if(body[i].style.fontSize) {
         var s = parseInt(body[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      body[i].style.fontSize = s+"px"
   }   
}

			
			
			
/*Menu*/
sfHover = function() {
	var sfEls = document.getElementById("mainMenu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/*tab Nav*/
function initTabBloc()  {
	if (document.getElementById && document.createTextNode) { 
		document.getElementById('onglet1').style.display = 'block';	
		document.getElementById('tab1').className='active';
	}
}

/*tab Nav au click*/
function showBloc(blocToShow , idTab) {
	if (document.getElementById && document.createTextNode) { 		
		if (document.getElementById('tab1'))
		{
			document.getElementById('tab1').className=' ';
		}
		if (document.getElementById('tab2'))
		{
			document.getElementById('tab2').className=' ';
		}
		if (document.getElementById('tab3'))
		{
			document.getElementById('tab3').className=' ';
		}
		if (document.getElementById('onglet1'))
		{
			document.getElementById('onglet1').style.display = 'none';	
		}
		if (document.getElementById('onglet2'))
		{
			document.getElementById('onglet2').style.display = 'none';	
		}
		if (document.getElementById('onglet3'))
		{
			document.getElementById('onglet3').style.display = 'none';	
		}
		document.getElementById(idTab).className='active' ;		
		document.getElementById(blocToShow).style.display = 'block';
		}

}


/*function loader*/
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

/*loads*/
addEvent(window, 'load', sfHover);

/* captcha */
function reloadCaptcha() { 
	document.getElementById("kaptchaImage").src='richelet-captcha.jpg?' + Math.floor(Math.random()*100);  
}

function checkCaptcha(myForm) {	
	// new XHR object
	getXhr();
	
	if(xhr != null)
	{	
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200)
			{	
				result = xhr.responseText;				
				if (parseInt(result) == 1) {
					document.getElementById(myForm).submit();
				} else {
					//use for translation
					alert(xhr.responseText);
					return false;					
				}
			}
		}	
		xhr.open("POST","../ajax/ajaxCheckCaptcha.jsp",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');				
		xhr.send("kaptcha="+document.getElementById('kaptcha').value);									
	}	
}

// form validation
function checkFormNews(myForm) {	
	if (!C2IS_ReqdFlds( 'nom',			'LabelForm.Nom')) return false;
	if (!C2IS_ReqdFlds( 'prenom',		'LabelForm.Prenom')) return false;
	if (!C2IS_ReqdFlds( 'email',			'LabelForm.Email')) return false;
	if (!C2IS_CheckEmail('email',			'LabelForm.Email')) return false;	
	if (!C2IS_TextCharset('journaissance',	1,'#','','LabelForm.JourNaissance') || !C2IS_CheckDay ('journaissance','LabelForm.JourNaissance') ) return false;
	if (!C2IS_TextCharset('moisnaissance',	1,'#','','LabelForm.MoisNaissance') || !C2IS_CheckMonth ('moisnaissance','LabelForm.MoisNaissance') ) return false;	
	if (!C2IS_TextCharset('anneenaissance',	4,'#','','LabelForm.AnneeNaissance')	|| !C2IS_CheckYear ('anneenaissance','LabelForm.AnneeNaissance') ) return false;

	checkCaptcha(myForm);	
	return false;
}

function checkFormContact(myForm) {	
	if (!C2IS_ReqdFlds( 'objet',		'LabelForm.Objet')) return false;
	if (!C2IS_ReqdFlds( 'nom',			'LabelForm.Nom')) return false;	
	if (!C2IS_ReqdFlds( 'prenom',		'LabelForm.Prenom')) return false;
	if (!C2IS_ReqdFlds( 'email',		'LabelForm.Email')) return false;
	if (!C2IS_CheckEmail('email',		'LabelForm.Email')) return false;	
	if (!C2IS_ReqdFlds( 'question',		'LabelForm.Question')) return false;

	checkCaptcha(myForm);	
	return false;
}


function checkFormSondage2(myForm) {	
	if (!C2IS_ReqdFlds( 'nom',			'LabelForm.Nom')) return false;
	if (!C2IS_ReqdFlds( 'prenom',		'LabelForm.Prenom')) return false;
	if (!C2IS_ReqdFlds( 'email',			'LabelForm.Email')) return false;
	if (!C2IS_CheckEmail('email',			'LabelForm.Email')) return false;	
	if (!C2IS_TextCharset('journaissance',	1,'#','','LabelForm.JourNaissance') || !C2IS_CheckDay ('journaissance','LabelForm.JourNaissance') ) return false;
	if (!C2IS_TextCharset('moisnaissance',	1,'#','','LabelForm.MoisNaissance') || !C2IS_CheckMonth ('moisnaissance','LabelForm.MoisNaissance') ) return false;	
	if (!C2IS_TextCharset('anneenaissance',	4,'#','','LabelForm.AnneeNaissance')	|| !C2IS_CheckYear ('anneenaissance','LabelForm.AnneeNaissance') ) return false;
	if (!C2IS_ReqdFlds( 'adresse',		'LabelForm.Adresse')) return false;
	if (!C2IS_ReqdFlds( 'code_postal',		'LabelForm.CodePostal')) return false;
	if (!C2IS_ReqdFlds( 'ville',		'LabelForm.Ville')) return false;
	if (document.getElementById('accep_reglt') && !C2IS_ReqdFlds( 'accep_reglt',		'LabelForm.Accept_reglement')) return false;
	
	checkCaptcha(myForm);	
	return false;
}
// Create AJAX object 
var xhr = null; 
	 
function getXhr(){
	if(window.XMLHttpRequest) // Firefox and others
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else { // XMLHttpRequest non available 
	   xhr = false; 
	} 
}

function trim (myString) 
{ 
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,''); 
} 

function openReglt(id_sondage)
{
	return window.open ('/richelet/popup_reglement.jsp?codeSondage='+id_sondage, '', 'width=600; height=500, resizable=no');
}
