function show_hide_switch(clq)
{
	if ( (document.getElementById(clq).style.display)==("block") )
	{
		document.getElementById(clq).style.display="none";
	}
	else
	{
		document.getElementById(clq).style.display="block";
	}
}

function show(clq)
{
	document.getElementById(clq).style.display="block";
}
function hide(clq)
{
	document.getElementById(clq).style.display="none";
}

function switchChecked(id)
{
    if(document.getElementById(id).checked == true)
        document.getElementById(id).checked = false;
        else document.getElementById(id).checked = true;
}

function goToUrl(url)
{
	document.location.href=url;
}

function confirm_delete(msg,id,table,retp,retId,params) {
	
	if(params == undefined) {
		params = '';
	}		
	
    if(confirm(msg)) {
//		alert('v='+ id +'~'+ table +'~'+ retp +'~'+ retId + params);
        window.location.href = '/com_delete.php?v='+ id +'~'+ table +'~'+ retp +'~'+ retId + params;	
    }else{
        //return false;
    }
}

function confirm_delete_tag(msg,idtag,table,page,idfile)
{
    if(confirm(msg))
    {
        window.location.href= '/com_delete.php?v='+idtag+'~'+table+'~'+page+'~'.idfile;
    }else{
        //return false;
    }
}

var i=1 // count amount of formfields
function createNewUpload(clqId)
{
    i++
    document.getElementById(clqId).innerHTML+='<br />File ' + i + ' : <input type="file" name="uploadedfile'+i+'" value="" />'
    MM_findObj('nbrFileUpload').value = i
}

/////////////////////////////////////////////////////////////
//// Resize de fenetre ////
/////////////////////////////////////////////////////////////
	function size(L,H){
		window.resizeTo(L,H);
	}

/////////////////////////////////////////////////////////////
//// function TRIM() ///// supprime les espaces en debut et fin de String
/////////////////////////////////////////////////////////////

	function trim(s) {
	  while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	  }
	  while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	  }
	  return s;
	}

/////////////////////////////////////////////////////////////
///// function de mise en page HTML //////////
/////////////////////////////////////////////////////////////

	function insertTags(chp, tagOpen, tagClose, sampleText) {

	    //var txtarea = MM_findObj(chp);
	    var txtarea = MM_findObj(chp);
	    /*
	    alert('chp : '+chp);
	    alert('textarea : '+txtarea);
	    alert('tagOpen : '+tagOpen);
	    alert('tagClose : '+tagClose);
	    alert('sampleText : '+sampleText);
	    */
	    if(!sampleText || sampleText == 'undefined' ){
	    	sampleText = "";
	    }

		// IE
		if(document.selection) {
			var theSelection = document.selection.createRange().text;
			if(!theSelection) { theSelection=sampleText;}
			txtarea.focus();
			if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
				theSelection = theSelection.substring(0, theSelection.length - 1);
				document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
			} else {
				document.selection.createRange().text = tagOpen + theSelection + tagClose;
			}
		// Mozilla
		} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
	 		var startPos = txtarea.selectionStart;
			var endPos = txtarea.selectionEnd;
			var myText = (txtarea.value).substring(startPos, endPos);
			if(!myText) { myText=sampleText;}
			if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
				subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
			} else {
				subst = tagOpen + myText + tagClose;
			}
			txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
			txtarea.focus();
			var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
			txtarea.selectionStart=cPos;
			txtarea.selectionEnd=cPos;
		// All others
		//*
		} else {
			// Append at the end: Some people find that annoying
			//txtarea.value += tagOpen + sampleText + tagClose;
			//txtarea.focus();
			tagOpen=tagOpen.replace(/\n/g,"");
			tagClose=tagClose.replace(/\n/g,"");
			document.infoform.infobox.value=tagOpen+sampleText+tagClose;
			txtarea.focus();
			//*/
		}
		// reposition cursor if possible
		if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
	}

	function do_headerHTML(chp, sampleText) {
		var tagOpen = "";
		var tagClose = "";
		var titre = "";
		titre = prompt("titre de la page :", "");

		tagOpen +=  '<html>\r\n';
		tagOpen += '<head>\r\n';
		tagOpen += '<title>.:: '+ titre +' ::.</title>\r\n';
		tagOpen += '</header>\r\n';
		tagOpen += '<body>\r\n';
		tagClose += '\r\n</body>\r\n';
		tagClose += '</html>\r\n';

		insertTags(chp, tagOpen, tagClose, sampleText);
	}

	function do_table(chp, sampleText) {
		var tagOpen = "";
		var tagClose = "";

		tagOpen +=  '<table cellpadding="0" cellspacing="0" border="0" width="480">\r\n';
		tagOpen += '<tr>\r\n';
		tagOpen += '<td align="left" valign="top" class="verd10gris">';
		tagClose += '</td>\r\n';
		tagClose += '</tr>\r\n';
		tagClose += '</table>\r\n';

		insertTags(chp, tagOpen, tagClose, sampleText);
	}

	function do_casse(chp,lettre,sampleText) {
		var tagOpen = '<'+ lettre +'>';
		var tagClose = '</'+ lettre +'>';

		insertTags(chp, tagOpen, tagClose, sampleText);
	}
	function do_link(chp,sampleText) {
		sampleText = prompt("entrer une URL :", "http://");

		var tagOpen = '<a href="'+sampleText+'" target="_blank">';
		var tagClose = '</a>\r\n';

		insertTags(chp, tagOpen, tagClose, sampleText);
		//alert(chp);
	}
	function do_img(chp,sampleText) {
		var img = "images/shim.gif";
		img = prompt("nom de l'image (avec extension) :", "images/");

		if(img == "images/shim.gif" || img == "images/" || img == ""){
			var tagOpen = '<img src="images/shim.gif" width="1" height="1" border="0">\r\n';
		}else{
			var tagOpen = '<img src="'+img+'" border="0">\r\n';
		}
		var tagClose = "";

		insertTags(chp, tagOpen, tagClose, sampleText);
	}

/////////////////////////////////////////////////////////////
////////////// POPUP Exemple /////////////////////////
/////////////////////////////////////////////////////////////

/*
function popup() {
	var pTrad = window.open("../traduction.php", "trad", "width=420,height=420,scrollbars=no,toolbar=no,menubar=no,statusbar=yes,resizable=no,left=100,top=100");
	pTrad.focus();
}
*/

function popHelp(W,H) {
	var pHelp = window.open("help.htm", "help", "width="+W+",height="+H+",scrollbars=auto,toolbar=no,menubar=no,statusbar=no,resizable=no,left=100,top=100");
	pHelp.focus();
}

function popFile(file,W,H) {
	/*alert(file);
	alert(W);
	alert(H);*/
	var pFile = window.open(file, "file", "width="+W+",height="+H+",scrollbars=auto,toolbar=no,menubar=no,statusbar=no,resizable=yes,left=100,top=100");
	pFile.focus();
}

function popTerms() {
	var pTerms = window.open("/terms", "terms", "width=600,height=500,scrollbars=1,toolbar=0,menubar=0,status=0,resizable=1,left=100,top=100");
	pTerms.focus();
}

/////////////////////////////////////////////////////////////
////////////// VERIFICATION DE FORMULAIRE ///////////////////
/////////////////////////////////////////////////////////////
function IsNumber(chaine)
{
	Etat=true;
	for (var i=0;i<chaine.length;i++)
	{
		if (chaine.charCodeAt(i)<48 || chaine.charCodeAt(i)>57)
		{
			Etat=false;
			break;
		}
	}
	return Etat;
}

function IsAlpha(chaine)
{
	Etat=true;
	for (var i=0;i<chaine.length;i++)
	{
		if (chaine.charCodeAt(i)!=224 && chaine.charCodeAt(i)!=228 && chaine.charCodeAt(i)!=226 && chaine.charCodeAt(i)!=233
		    && chaine.charCodeAt(i)!=232 && chaine.charCodeAt(i)!=235 && chaine.charCodeAt(i)!=234 && chaine.charCodeAt(i)!=249
		    && chaine.charCodeAt(i)!=252 && chaine.charCodeAt(i)!=251 && chaine.charCodeAt(i)!=239 && chaine.charCodeAt(i)!=238
		    && chaine.charCodeAt(i)!=246 && chaine.charCodeAt(i)!=244 && chaine.charCodeAt(i)!=231 && chaine.charAt(i)!=" " && chaine.charAt(i)!='\t')
		    {
			if ((chaine.charCodeAt(i)<65 || chaine.charCodeAt(i) >90) & (chaine.charCodeAt(i)<97 || chaine.charCodeAt(i) >122))
			{
				Etat=false;
				break;
			}
	 	    }
	}
	return Etat;
}


function IsAlphaNum(chaine)
{
	Etat=true;
	for (var i=0;i<chaine.length;i++)
	{
		if (!IsNumber(chaine.charAt(i)) && !IsAlpha(chaine.charAt(i)))
		{
			Etat=false;
			break;
		}
	}
	return Etat;
}


/** VALIDATIONS **/
//// VERIF 'SHARE IT' FORM ////
function chkFormSendTo() {
	var error 		= '';
	var zeForm 		= document.forms.fSendTo;


	if(trim(zeForm.email_send_to.value) == '') {
		error += '- email\n';
	}else if(zeForm.email_send_to.length < 8 || zeForm.email_send_to.value.indexOf("@") == "-1" || zeForm.email_send_to.value.indexOf(".") == "-1") {
		error += '- need an email into email field\n';
	}
	if(trim(zeForm.name_send_to.value) == '') {
		error += '- name\n';
	}
	if(trim(zeForm.ls_email_send_to.value) == '') {
		error += '- friend\'s email\n';
	}
	
	if(error == '') {
		zeForm.submit();
	}else{
		var msg = 'Please can you fill all required fields\n';
		msg += error;
		alert(msg);
		return false;
	}
}
//// VERIF Search FORM ////
function chkFormSearch() {
	var error 		= '';
	var zeForm 		= document.forms.fSearch;


	if(trim(zeForm.search_text.value) == '' || trim(zeForm.search_text.value) == 'search') {
		error += '- search\n';
	}
	
	if(error == '') {
		zeForm.submit();
	}else{
		var msg = 'Please can you fill search field\n';
		//msg += error;
		alert(msg);
		return false;
	}
}
//// VERIF Full Search  FORM ////
function chkFormSearchFull() {
	var error 		= '';
	var zeForm 		= document.forms.fSearchFull;


	if(trim(zeForm.search_text.value) == '' || trim(zeForm.search_text.value) == 'search') {
		error += '- search\n';
	}
	
	if(error == '') {
		zeForm.submit();
	}else{
		var msg = 'Please can you fill search field\n';
		//msg += error;
		alert(msg);
		return false;
	}
}