/*
# copyright : Copyright (C) 2007 Squirnet.com. All rights reserved.
# url : http://www.squirnet.com
# mail : copyright@squirnet.com
# update : 2009-08-31
*/

function putFrame(id){
	var d = document.getElementById(id);
	var f = document.createElement("iframe");
	f.id = id+"_iframe";
	
	with(f.style){
		position= "absolute";
		width    = d.offsetWidth+"px";
		height= d.offsetHeight+"px";;
		top= d.offsetTop+"px";
		left= d.offsetLeft+"px";
		zIndex= "1";
		filter='alpha\(opacity=0\)';
	}
	document.body.appendChild(f);
}
function getChk(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function switch_chk_class(id) {
	var id_class = getObj.Id('gift_tr_'+id).className;
	if (id_class == "gift_list_tr1") {
		getObj.Id('gift_tr_'+id).className = "gift_list_tr3";
	}
	else if (id_class == "gift_list_tr2") {
		getObj.Id('gift_tr_'+id).className = "gift_list_tr4";
	}
	else if (id_class == "gift_list_tr3") {
		getObj.Id('gift_tr_'+id).className = "gift_list_tr1";
	}
	else if (id_class == "gift_list_tr4") {
		getObj.Id('gift_tr_'+id).className = "gift_list_tr2";
	}
}

function generate_pass(id) {
	var pass_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var pass_length = 5;
	var pass = "";
	for( i = 0 ; i < pass_length ; i++){
		pass_chars_select = Math.round(Math.random() * pass_chars.length);
		pass += pass_chars.substring(pass_chars_select , pass_chars_select + 1);
	}
	getId(id).value = pass;
}

function crop_head(data) {
	var regex_head = new RegExp("<body>|</body>" , "g");
	var html = data.split(regex_head);
	return(html[1]);
}

/*
      function getElementsByClassName(classname, node) {
      if(!node) node = document.getElementsByTagName("body")[0];
      var a = [];
      var re = new RegExp('\\b' + classname + '\\b');
      var els = node.getElementsByTagName("*");
      for(var i=0,j=els.length; i<j; i++)
      if(re.test(els[i].className))a.push(els[i]);
      return a;
      }

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function getElementsByClass(node,searchClass,tag) {
    var classElements = new Array();
    var els = node.getElementsByTagName(tag); // use "*" for all elements
    var elsLen = els.length;
    var pattern = new RegExp("\b"+searchClass+"\b");
    for (i = 0, j = 0; i < elsLen; i++) {
         if ( pattern.test(els[i].className) ) {
             classElements[j] = els[i];
             j++;
         }
    }
    return classElements;
}

*/




function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Versão: 2.1 - 04/09/2007
* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}













/*#########################  GET  #########################*/
function getId(id) {
	return document.getElementById(id);
}

function getStyle(id , property) {
	var ele = document.getElementById(id);
		if (window.getComputedStyle) {
			var req = eval('window.getComputedStyle(ele,null).' + property);
		}
		else if (ele.currentStyle) {
			var req = eval('ele.currentStyle.' + property);
		}
	return req;
}

var getObj = {
	Id: function(Obj) {
		return document.getElementById(Obj);
	},
	Class: function(Obj) {
	},
	Style: function(Obj) {
	},
	nb_chk: function(Obj) {
		var nb_chk = 0;
		for (var i=0 ; i < Obj.length ; i++) {
			if (Obj[i].checked) {
				nb_chk = 1;
			}
		}
		return nb_chk;
	}
}
/*
document.body.scrollWidth taille du document

document.body.offsetWidth taille affichée
window.innerWidth FF

document.body.clientWidth taille du client IE

Au lieu de faire document.body.clientHeight, il faut faire document.documentElement.clientHeight.
window.innerWidth


document.body.offsetWidth
.


window.innerHeight FF visible
IE6 >> document.documentElement.clientHeight

window.innerHeight FF visible
document.body.clientHeight IE total


document.body.offsetWidth IE total body
document.body.scrollWidth IE total


window.pageXOffset FF position
pageX FF souris
*/

var getSys = {
	navName: "",
	navVers: 0,
	mouseX: 0,
	mouseY: 0,
	scrollX: 0,
	scrollY: 0,
	innerW: 0,
	innerH: 0,
	
	nav: function() {
		if (navigator.appName == "Microsoft Internet Explorer") {
			getSys.navName = "IE";
			if (!window.XMLHttpRequest) {
				return "IE6";
			}
			else {
				return "IE7+";
			}
		}
	},

	mouse: function(evt) {
		if(!evt) {evt = window.event;}
		getSys.mouseX = evt.clientX;
		getSys.mouseY = evt.clientY;
		// pageX FF souris
	},
	
	scrollbar: function(evt) {
		getSys.scrollX = (document.documentElement.scrollLeft  || document.body.scrollLeft);
		getSys.scrollY = (document.documentElement.scrollTop  || document.body.scrollTop);
	},
	
	size: function(evt) {
		getSys.innerW = (window.innerWidth || document.documentElement.clientWidth);
		getSys.innerH = (window.innerHeight || document.documentElement.clientHeight);
	}
}
addEvent(document , 'mousemove' , getSys.mouse, true);
addEvent(document , 'mousemove' , getSys.scrollbar, true);
addEvent(document , 'mousemove' , getSys.size, true);


function addEvent(ele , evt , fn , bCapt) {
	
	if (ele.addEventListener) {
		return ele.addEventListener(evt , fn , bCapt);
	}
	else if (ele.attachEvent){
		return ele.attachEvent('on' + evt , fn);
	}
	else {
		return ele['on' + evt] = fn;
	}
}
/*#########################  /GET  #########################*/


function open_extlink() {
	var liens = document.getElementsByTagName('a');
	
	for (var i=0 ; i < liens.length ; ++i) {
		if (liens[i].className.search(/extlink/) > -1) {
			liens[i].onclick = function()  {
				window.open(this.href);
				return false;
			}
		}
	}
}
addEvent(window , 'load' , open_extlink , false);





var tooltip = {
	id: "tooltip",
	ttWidth: 0,
	ttHeight: 0,
	disp: false,
	trans: 0,
	debord: "none",
	
	loadBasic: function(content) {
		tooltip.getWH(content);
		tooltip.show(content);
	},
	
	getWH: function(content) {
		getId(tooltip.id).style.display="block";
		getId(tooltip.id).style.left = 0 + "px";
		getId(tooltip.id).style.top  = 0 + "px";
		getId(tooltip.id).style.MozOpacity = 0;
		getId(tooltip.id).style.KhtmlOpacity = 0;
		getId(tooltip.id).style.filter='alpha\(opacity=0\)';
		getId(tooltip.id).style.opacity = 0;
		getId(tooltip.id + "_content").innerHTML = content;
		tooltip.ttWidth = getId(tooltip.id).offsetWidth;
	},
	
	show: function(content) {
		if(tooltip.disp==false) {
			tooltip.disp=true;
			if (getSys.nav() == "IE6") {putFrame("tooltip");}
			tooltipTrans = setInterval("tooltip.fading()",50);
		}
	},
	
	fading: function() {
		tooltip.trans = +tooltip.trans + 15;
		var newOpacity = tooltip.trans / 100;
		if (newOpacity > 1) {newOpacity = 1;}
		
		getId(tooltip.id).style.MozOpacity = newOpacity;
		getId(tooltip.id).style.KhtmlOpacity = newOpacity;
		getId(tooltip.id).style.filter='alpha\(opacity=' + newOpacity * 100 + '\)';
		getId(tooltip.id).style.opacity = newOpacity;
		
		if (tooltip.trans >= 100) {tooltip.trans = "0"; clearInterval(tooltipTrans);}
	},
	
	update: function(evt) {
		if(tooltip.disp) {
			if(!evt) {evt = window.event;}
			
			if (evt.clientX + tooltip.ttWidth + 40 > document.body.offsetWidth) {
				tooltip.debord = "right";
			}
			else {
				tooltip.debord = "none";
			}
			var ttplainW = tooltip.ttWidth + "px";
			getId(tooltip.id).style.width = tooltip.ttWidth;
			if (tooltip.debord == "right") {
				getId(tooltip.id).style.left = 0 -getId(tooltip.id).offsetWidth + evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) + "px";
				getId(tooltip.id).style.top  = 20 + evt.clientY + (document.documentElement.scrollTop  || document.body.scrollTop) + "px";
			}
			else {
				getId(tooltip.id).style.left = 10 + evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) + "px";
				getId(tooltip.id).style.top  = 20 + evt.clientY + (document.documentElement.scrollTop  || document.body.scrollTop) + "px";
			}
		}
	},
	
	hide: function() {
		if(tooltip.disp==true) {
			getId(tooltip.id).style.MozOpacity = 0;
			getId(tooltip.id).style.KhtmlOpacity = 0;
			getId(tooltip.id).style.filter='alpha\(opacity=0\)';
			getId(tooltip.id).style.opacity = 0;
			getId(tooltip.id).style.display="none";
			tooltip.disp=false;
			tooltip.trans=0;
			tooltip.debord = "none";
			if (getSys.nav() == "IE6") {document.body.removeChild(getId("tooltip_iframe"));}
			clearInterval(tooltipTrans);
		}
	}
}
addEvent(document , 'mousemove' , tooltip.update , true);



var notification = {
	id: "notification",
	disp: false,
	trans: 0,
	
	load: function(content , auto_close) {
		notification.show(content);
		if (auto_close == true) {
			setTimeout("notification.unshow()",2000);
		}
		else if (auto_close != false) {
			setTimeout("notification.unshow()",auto_close);
		}
	},
	
	show: function(content) {
		if(notification.disp==false) {
			notification.disp=true;
			getId(notification.id).style.display="block";
			getId(notification.id).style.top  = ((getSys.innerH / 2) + getSys.scrollY) + "px";
			getId(notification.id + "_content").innerHTML = content;
			if (getSys.nav() == "IE6") {putFrame("notification");}
			notificationTrans = setInterval("notification.fading()",50);
		}
	},
	
	unshow: function() {
		notificationUntrans = setInterval("notification.unfading()",50);
	},
	
	fading: function() {
		notification.trans = +notification.trans + 15;
		var newOpacity = notification.trans / 100;
		if (newOpacity > 1) {newOpacity = 1;}
		
		getId(notification.id).style.MozOpacity = newOpacity;
		getId(notification.id).style.KhtmlOpacity = newOpacity;
		getId(notification.id).style.filter='alpha\(opacity=' + newOpacity * 100 + '\)';
		getId(notification.id).style.opacity = newOpacity;
		
		if (notification.trans >= 100) {notification.trans = "100"; clearInterval(notificationTrans);}
	},
	
	unfading: function() {
		notification.trans = +notification.trans - 15;
		var newOpacity = notification.trans / 100;
		if (newOpacity < 0) {newOpacity = 0;}
		
		getId(notification.id).style.MozOpacity = newOpacity;
		getId(notification.id).style.KhtmlOpacity = newOpacity;
		getId(notification.id).style.filter='alpha\(opacity=' + newOpacity * 100 + '\)';
		getId(notification.id).style.opacity = newOpacity;
		
		if (notification.trans <= 0) {
			notification.trans = "0"; clearInterval(notificationUntrans);
		if (getSys.nav() == "IE6") {document.body.removeChild(getId("notification_iframe"));}
			getId(notification.id).style.display="none";
			notification.disp=false;
			}
	},
	
	hide: function() {
		if(notification.disp==true) {
			getId(notification.id).style.MozOpacity = 0;
			getId(notification.id).style.KhtmlOpacity = 0;
			getId(notification.id).style.filter='alpha\(opacity=0\)';
			getId(notification.id).style.opacity = 0;
			getId(notification.id).style.display="none";
			notification.disp=false;
			notification.trans=0;
			if (getSys.nav() == "IE6") {document.body.removeChild(getId("notification_iframe"));}
			clearInterval(notificationTrans);
		}
	}
}



var dialog = {
	id: "dialog",
	disp: false,
	trans: 0,
	
	alert: function(content) {
		dialog.show(content);
	},
	
	show: function(content) {
		if(dialog.disp==false) {
			dialog.disp=true;
			getId(dialog.id).style.display="block";
			getId(dialog.id + "_content").innerHTML = content;
			getId(dialog.id + "_action").innerHTML = "<a href=\"#\" onClick=\"dialog.hide(); return false;\">OK</a>";
			getId(dialog.id).style.top  = ((getSys.innerH / 2) + getSys.scrollY) + "px";
			getId(dialog.id).style.marginTop = "-" + (getId(dialog.id).offsetHeight / 2) + "px";
			if (getSys.nav() == "IE6") {putFrame("dialog");}
			dialogTrans = setInterval("dialog.flash()",50);
		}
	},
	
	flash: function() {
		dialog.trans = +dialog.trans + 10;
		
		if ((dialog.trans == 30) || (dialog.trans == 70) || (dialog.trans >= 100)) {
			getId(dialog.id).style.MozOpacity = 1;
			getId(dialog.id).style.KhtmlOpacity = 1;
			getId(dialog.id).style.filter='alpha\(opacity=100\)';
			getId(dialog.id).style.opacity = 1;
		}
		else if ((dialog.trans == 10) || (dialog.trans == 50)) {
			getId(dialog.id).style.MozOpacity = 0;
			getId(dialog.id).style.KhtmlOpacity = 0;
			getId(dialog.id).style.filter='alpha\(opacity=0\)';
			getId(dialog.id).style.opacity = 0.3;
		}
		
		if (dialog.trans >= 100) {dialog.trans = "100"; clearInterval(dialogTrans);}
	},
	
	update: function(evt) {
		if(dialog.disp) {
			if(!evt) {evt = window.event;}
			
			getId(dialog.id).style.left = 10 + evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) + "px";
			getId(dialog.id).style.top  = 20 + evt.clientY + (document.documentElement.scrollTop  || document.body.scrollTop) + "px";
		}
	},
	
	hide: function() {
		if(dialog.disp==true) {
			getId(dialog.id).style.MozOpacity = 0;
			getId(dialog.id).style.KhtmlOpacity = 0;
			getId(dialog.id).style.filter='alpha\(opacity=0\)';
			getId(dialog.id).style.opacity = 0;
			getId(dialog.id).style.display="none";
			if (getSys.nav() == "IE6") {document.body.removeChild(getId("dialog_iframe"));}
			dialog.disp=false;
			dialog.trans=0;
			clearInterval(dialogTrans);
		}
	}
}



var calendar = {
	id: "",
	id_hidden: "",
	id_text: "",
	display_return: "",
	date: new Date(),
	disp: false,
	trans: 0,
	
	load: function(id_hidden , id_text , display_return) {
		calendar.id_hidden=id_hidden;
		calendar.id_text=id_text;
		calendar.display_return=display_return;
		calendar.show();
	},
	
	show: function() {
		if(calendar.disp==false) {
			calendar.disp=true;
			getId("calendar").style.display="block";
			getId("calendar").style.top = ((getSys.innerH / 2) + getSys.scrollY) + "px";
			if (getSys.nav() == "IE6") {putFrame("calendar");}
			calendarTrans = setInterval("calendar.fading()",50);
		}
	},
	
	return_date: function(value) {
		getId(calendar.id_hidden).value = value;
		
		if (calendar.display_return == "maxi") {
			var month = new Array("janvier","fevrier","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","decembre");
			calendar.date.setTime(value * 1000)
			getId(calendar.id_text).innerHTML = calendar.date.getDate() + " " + month[calendar.date.getMonth()];
		}
		else {
			calendar.date.setTime(value * 1000)
			getId(calendar.id_text).innerHTML = calendar.date.getDate() + "/" + (calendar.date.getMonth()+1);
		}
		
		calendar.hide();
	},
	
	fading: function() {
		calendar.trans = +calendar.trans + 15;
		var newOpacity = calendar.trans / 100;
		if (newOpacity > 1) {newOpacity = 1;}
		
		getId("calendar").style.MozOpacity = newOpacity;
		getId("calendar").style.KhtmlOpacity = newOpacity;
		getId("calendar").style.filter='alpha\(opacity=' + newOpacity * 100 + '\)';
		getId("calendar").style.opacity = newOpacity;
		
		if (calendar.trans >= 100) {calendar.trans = "0"; clearInterval(calendarTrans);}
	},
	
	hide: function() {
		if(calendar.disp==true) {
			getId("calendar").style.MozOpacity = 0;
			getId("calendar").style.KhtmlOpacity = 0;
			getId("calendar").style.filter='alpha\(opacity=0\)';
			getId("calendar").style.opacity = 0;
			getId("calendar").style.display="none";
			if (getSys.nav() == "IE6") {document.body.removeChild(getId("calendar_iframe"));}
			calendar.disp=false;
			calendar.trans=0;
			clearInterval(calendarTrans);
		}
	}
}


var quinzaine = {
	
	change_statut: function(id_hidden , id_text) {
		var statut = getId(id_hidden).value;
		if (statut == "true") {
			getId(id_hidden).value = false;
			getId(id_text).className = "quinzaine_active_text_false";
			getId(id_text).innerHTML = "Désactivée";
		}
		else {
			getId(id_hidden).value = true;
			getId(id_text).className = "quinzaine_active_text_true";
			getId(id_text).innerHTML = "Activée";
		}
	}
}



var popup = {
	id: "popup",
	disp: false,
	trans: 0,
	
	load: function(url) {
		popup.show(url);
	},
	
	show: function(url) {
		if(popup.disp==false) {
			popup.disp=true;
			getId(popup.id).style.display="block";
			switch_div('popup_content',url);
			getId(popup.id).style.top = ((getSys.innerH / 2) + getSys.scrollY) + "px";
			getId(popup.id).style.marginTop = "-" + (getId(popup.id).offsetHeight / 2) + "px";
			popupTrans = setInterval("popup.fading()",50);
		}
	},
	
	fading: function() {
		popup.trans = +popup.trans + 15;
		var newOpacity = popup.trans / 100;
		if (newOpacity > 1) {newOpacity = 1;}
		
		getId(popup.id).style.MozOpacity = newOpacity;
		getId(popup.id).style.KhtmlOpacity = newOpacity;
		getId(popup.id).style.filter='alpha\(opacity=' + newOpacity * 100 + '\)';
		getId(popup.id).style.opacity = newOpacity;
		
		if (popup.trans >= 100) {popup.trans = "100"; clearInterval(popupTrans);}
	},
	
	hide: function() {
		if(popup.disp==true) {
			getId(popup.id).style.MozOpacity = 0;
			getId(popup.id).style.KhtmlOpacity = 0;
			getId(popup.id).style.filter='alpha\(opacity=0\)';
			getId(popup.id).style.opacity = 0;
			getId(popup.id).style.display="none";
			popup.disp=false;
			popup.trans=0;
			clearInterval(popupTrans);
		}
	}
}










var check_value = {
	regex_mail: new RegExp('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$', 'i'),
	
	mail: function(data) {
		if(check_value.regex_mail.test(data)) {
			return true;
		}
		else {
			return false;
		}
	}
	
}
