
// ## version : 1.2 ## 29-06-05 ## lg ## B295 controle max carac
// ## version : 1.1 ## 07-06-05 ## lg ## B247

function verif_lng_field(target, max_lng)
{
	var lng_var = target.value.length;
	var lng_var_max_unicode = lng_var * 5; // determination brute de la longueur maximale de la chaine en Unicode
	var real_lenght = max_lng / 5;
	
	if (lng_var_max_unicode > max_lng)
	{
		target.value = target.value.slice(0, real_lenght);
		aff_msg("You reach the maximum length of characters<br> for the field : " + real_lenght);
	}
}

function verif_lng(target, max_lng)
{
	var lng_var = target.value.length;
	var lng_var_max_unicode = lng_var * 5; // determination brute de la longueur maximale de la chaine en Unicode
	
	if (lng_var_max_unicode >= max_lng)
	{
		aff_msg("You reach the maximum length of characters<br> for the title : "+max_lng/5);
		target.value = target.value.substring(0,(target.value.length-1));
	}
}

function verif_lng_textarea(target, max_lng)
{
	var lng_var = target.value.length;
	var lng_var_max_unicode = lng_var * 5; // determination brute de la longueur maximale de la chaine en Unicode
	
	if (lng_var_max_unicode >= max_lng)
	{
		aff_msg("You reach the maximum length of characters<br> for the text : "+max_lng/5);
		target.value = target.value.substring(0,(target.value.length-1));
	}
}		

function aff_msg(message)
{
	texte="<html><head>";
	texte+="<LINK rel='stylesheet' type='text/css' href='../css/style.css'>";
	texte+="<style>body{margin:0;padding:1em;text-align:center;font-weight:bold;}";
	texte+="p{margin-top:1em;font-size:medium;font-weight:bold;}";
	texte+="p input{margin:0 1em;padding:0 0.5em;}";
	texte+="h1{margin:-1em -1em .5em -1em;padding:.3em .5em 9px 1em;color:#fff;font-family=courrier;font-size:medium;text-transform:uppercase;";
	texte+="background:#161433 url('../img/liseret_popup.gif') repeat-x 0 100%;}";
	texte+="</style>";
	texte+="</head><title>Exceedeed Limit</title><body><div align='center'>";
	texte+="<h1>Warning</h1>";
	texte+=message;
	//texte+="<br><a href='javascript:void(0)' OnClick='window.close()'>Close this window</a></div></body></html>";
	texte+="<br><br><br><input type=reset value=OK onclick=self.close()></div></body></html>";
	fenetreNote=window.open("","","status=no, toolbar=no, menubar=no, width=300, height=150, top=200, left=200, resizable=yes");
	fenetreNote.document.write(texte); 
}

function popup_attach_file(url)
{
	win = window.open(url, '_blank', '');
	win.focus;
}


function popup_message(message)
{
	texte="<html><head>";
	texte+="<LINK rel='stylesheet' type='text/css' href='../css/style.css'>";
	texte+="<style>body{margin:0;padding:1em;text-align:center;font-weight:bold;}";
	texte+="p{margin-top:1em;font-size:medium;font-weight:bold;}";
	texte+="p input{margin:0 1em;padding:0 0.5em;}";
	texte+="h1{margin:-1em -1em .5em -1em;padding:.3em .5em 9px 1em;color:#fff;font-family=courrier;font-size:medium;text-transform:uppercase;";
	texte+="background:#161433 url('../img/liseret_popup.gif') repeat-x 0 100%;}";
	texte+="</style>";
	texte+="</head><title>Form</title><body><div align='center'>";
	texte+="<h1>Warning</h1>";
	texte+="<br>"+message;
	texte+="<br><br><br><input type=reset value=OK onclick=self.close()></div></body></html>";
	fenetreNote=window.open("","","status=no, toolbar=no, menubar=no, width=300, height=150, top=130, left=200, resizable=yes");
	fenetreNote.document.write(texte); 
}

function my_trim(string) 
{ 
	return string.replace(/(^\s*)|(\s*$)/g,''); 
} 

function my_get_point(url)
{
	temp=url.lastIndexOf(".");
	return temp;
}

function check_url(url)
{
	var continu=1;
    	URL=my_trim(url);
    	reg = new RegExp("^(http://|https://){0,1}[A-Za-z0-9][A-Za-z0-9\-\.]+[A-Za-z0-9]\.[A-Za-z]{2,}[\43-\176]*$")
	result = reg.test(url);

	if (result == true && my_get_point(url)!=-1)
	{
		//alert("L'url a un format correct\n"+url);
	}
	else
	{
		popup_message("Please insert a valid url.");
		continu=0;
	}
	
	return continu;
}

// Méthode testant l'Url pour le template Integration
function testUrlPageIntegration(urlpi){

	var continu = 1;
	URL = urlpi.substr(0, 7);
	
	if (URL != "http://"){
		
		popup_message("The URL must begin with http://");
		continu=0;
	}
	
	return continu;
	

}