/********************************************************************
 *                   WEBDOMAINE Version 2.0                     	*
 ********************************************************************
 *  Programmeur: 		Sébastien Guay								*
 *  Projet: 			Webdomaine									*
 *  Numéro Projet:  	20020040									*        
 *  Date création:		2002-06-03									*
 *  Date modification:	2002-06-03									*
 ********************************************************************
 Description:
 
 Librairies de fonctions javascript pour le site de webdomaine
  
 --------------------------------------------------------------------
*/


// Cette fonction vérifie les champs du client, et change l'image pour un crochet
// vert si le champ est remplis ou un x rouge si le champ est vide
function CheckField(img,field)
{
	if (field.value !="#" && field.value !="")
	{
		img.src="../img/check-xs.gif";
		return 1;
	}else{
		img.src="../img/x-xs.gif";
		return 0;
	}
}

// Cette fonction vérifie les champs des contacts techniques et administratifs, si
// les deux sont remplis, un crochet vert sinon un x rouge
function CheckFields(img,field1,field2)
{
	if (field1.value !="#" && field1.value !="" && field2.value !="#" && field2.value !="")
	{
		img.src="../img/check-xs.gif";
		return 1;
	}else{
		img.src="../img/x-xs.gif";
		return 0;
	}
}

// fonction qui valide si le code postal entrée est valide. format : a1a 1a1  ou  A1A 1A1
function CheckPostalCode(pcode)
{
	var pcodecheck = /^([a-zA-Z])+\d+([a-zA-Z])+\s+\d+([a-zA-Z])+\d+$/;
	if(pcode.match(pcodecheck))
	{
		return 0;
	}else{
		return 1;
	}
}
		
// cette fonction vérifie si le courriel entrée est valide ou non.  Si oui elle retourne 0
// sinon elle retourne 1
function CheckEmail(email)
{
	var x = email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (filter.test(x)) return 0;
	else return 1;
}

// fonction qui verifie le format du téléphone puisque l'acei accepte le format
// 418-123-4567 et pas 4181234567
function CheckPhoneNumber(phoneNo)
{ 
	//var phoneRE = /^\d\d\d-\d\d\d-\d\d\d\d$/;
	//if (phoneNo.match(phoneRE))
	//{
		return 0;
	//}else{
	//	return 1;
	//}
}
		
// fonction qui est appelée juste avant l'envoie du formulaire du client et qui
// vérifie que le champs passé en parametre est bien rempli
function ValidateField(field)
{
	if(field.value=="" || field.value=="#" || CheckBlankString(field.value)!=0){
		field.focus();
		return 1;
	}else return 0;
}

// fonction qui sélectionne le bon élément d'un select
function FindSelect(select,val)
{
	
	if(val=="")
		return;
	var compt=0;
	while(compt<select.length)
	{
		if(select.options[compt].value==val)
		{
			select.options[compt].selected=true;
			break;
		}
		compt++;
	}
	return;
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function OpenDetails(strDomain,IDLang)
{
	var location="/whoisdetail.php?txtDomainName="+strDomain+"&IDLang="+IDLang;
	Details=window.open(location,"","width=800,height=600,scrollbars=yes,screenX=0,screenY=0,top=0,left=0,resizable=1");
}

function trim(inputString)
{

	if (typeof inputString != "string") { return inputString; }
   	var retValue = inputString;
   	var ch = retValue.substring(0, 1);
   	
   	while (ch == " ") { // Check for spaces at the beginning of the string
   		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	
	ch = retValue.substring(retValue.length-1, retValue.length);
	
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}

	return retValue;
}

function CheckBlankString(strInput)
{
	//Fonction qui vérifie si la chaine est en blanc, i-e seulement espaces
	var tmpString = trim(strInput);

	if(tmpString!=null)
	{
		if (tmpString.length==0)
		{
			return 1;
		}else{
			return 0;
		}
	}else
		return 0;
}
