String.prototype.isempty = isempty;
String.prototype.isemailid = isemailid;
String.prototype.istelephone = istelephone;
String.prototype.isdate = isdate;
String.prototype.isnumber = isnumber;
String.prototype.trim = trim;
String.prototype.replicateatstart = replicateatstart;
String.prototype.replicateatend = replicateatend;
Date.prototype.getDateTime = getDateTime;	


function trim()
{
	var i = new Number();
	var pSpace = new Boolean();
	var pStart = new Number();
	var pEnd = new Number();
	
	for(i = 0; i <= this.length - 1; i++)
	{
		if(this.charAt(i)!=" ")
		{
			pStart = i;
			pSpace = true;
			break;
		}
	}
	for(i = (this.length - 1); i >= 0; i--)
	{
		if(this.charAt(i) != " ")
		{
			pEnd = i + 1;
			pSpace = true;
			break;
		}
	}
	if(pStart == 0 && pEnd == 0 && pSpace == true)
	{
		return this;
	} else
	{
		return this.substring(pStart,pEnd);
	}
}

function isempty(pmessage)
{
	if(this.trim() == "")
	{
		if(pmessage.trim() != "")
		{
			alert(pmessage);
		}
		return true;
	}
	return false;
}

function isselected(pobj, pmessage)
{
	if(pobj.selectedIndex <= 0)
	{
		if(pmessage.trim() != "")
		{
			alert(pmessage);
		}
		return false;
	}
	return true;
}

function isemailid(pmessage)
{
	if(this.trim() != "")
	{
		if((this.indexOf("@",0) == -1) || (this.indexOf(".",0) == -1) || (this.indexOf("@",0) == 0) || (this.indexOf(".",0) == 0) || (this.indexOf(".",0) == (this.length - 1)))
		{
			if(pmessage.trim() != "")
			{
				alert(pmessage);
			}
			return false;
		}
	}
	return true;
}	

function isexisting(pobj, pval, pmessage)
{
	var i = Number();
	var x = new String();
	
	for(i = 0; i <= (pobj.options.length - 1); i++)
	{
		if(pobj.options[i].value.split("|")[0] == pval.split("|")[0])
		{
			if(pmessage.trim() != "")
			{
				alert("'" + pmessage + "'");
			}
			return true;
		}
	}
	return false;
}

function istelephone(pmessage)
{
	var i = new Number();
	
	for(i = 0; i <= (this.trim().length - 1); i++)
	{
		if((this.trim().charCodeAt(i) < 48 || this.trim().charCodeAt(i) > 57) && (this.trim().charAt(i) != " " && this.trim().charAt(i) != "+" && this.trim().charAt(i) != "-" && this.trim().charAt(i) != "/"))
		{
			alert(pmessage);
			return false;
		}
	}
	return true;
}

function isdate()
{
	if(this == "//" || this == "")
	{
		return true;
	}
	/* Checks for the following valid date formats:
	MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	Also separates date into month, day, and year variables
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/; */
	
	/* To require a 4 digit year entry, use this line instead: */
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = this.match(datePat); // is the format ok?
	
	if(matchArray == null)
	{
		alert("La date saisie n'est pas correcte !(jour/Mois/Année)");
		return false;
	}
	mois = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if(mois < 1 || mois > 12)
	{
		alert("Le mois saisi doit être compris entre 1 et 12 !");
		return false;
	}
	if(day < 1 || day > 31)
	{
		alert("Le jour saisi doit être compris entre 1 et 31 !");
		return false;
	}
	if((mois == 4 || mois == 6 || mois == 9 || mois == 11) && day == 31)
	{
		alert("Le mois " + mois + " ne comprend pas 31 jours !");
		return false;
	}
	if(mois == 2)
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		
		if (day > 29 || (day == 29 && !isleap)) 
		{
			alert("Le mois de février de l'année " + year + " ne comprend pas " + day + " jours !");
			return false;
		}
	}
	if(year <= 1752)
	{
		alert("Vérifiez la date saisie");
		return false;
	}
	return true;
}

function isnumber(pmessage)
{
	var i = new Number();
	
	for(i = 0; i <= (this.trim().length - 1); i++)
	{
		if(this.trim().charCodeAt(i) < 48 || this.trim().charCodeAt(i) > 57)
		{
			alert(pmessage);
			return false;
		}
	}
	return true;
}

function DeleteOptions(pObj)
{
	var pI = new Number();
	
	if(pObj.selectedIndex >= 0)
	{
		for(pI = (pObj.options.length - 1); pI >= 0; pI--)
		{
			if(pObj.options[pI].selected == true)
			{
				if(pI != 0)
				{
					pObj.options[pI] = null;
				}
			}
		}
	}
	return false;
}

function DeleteOptions1(pObj)
{
	var pI = new Number();
	
	if(pObj.selectedIndex >= 0)
	{
		for(pI = pObj.options.length - 1; pI >= 0; pI--)
		{
			if(pObj.options[pI].selected == true)
			{
				pObj.options[pI] = null;
			}
		}
	}
	return false;
}

function getDateTime(pFormat)
{
	var pVal = new String();
	
	if(pFormat == "dmy")
	{
		pVal = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
	} else
	{
		pVal = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
	}
	return pVal;
}

function replicateatend(pChar, pLength)
{
	var pVal = new String();
	var pI = new Number();
	
	pVal = this;
	if (pLength >= 1)
	{
		for (pI = 1; pI <= pLength; pI++)
		{
			pVal = pVal + pChar;
		}
	}
	return pVal;
}

function replicateatstart(pChar, pLength)
{
	var pVal = new String();
	var pI = new Number();
	
	if (pLength >= 1)
	{
		for (pI = 1; pI <= pLength; pI++)
		{
			pVal = pVal + pChar;
		}
	}
	pVal = pVal + this;
	return pVal;
}

function afficher_adresse(arr)
{
	var ret = '', i = 0;
	
	arr = arr.split(',');
	for(i = 0; i < arr.length; i++)
	{
		ret = ret.concat(String.fromCharCode(arr[i]));
	}
	return  ret;
}

function login()
{
	pFormLogin.submit();
}

function validerForm()
{
	var pForm = window.document.moteur;
	
	if(pForm.txtOutline.value.isempty("Veuillez décrire la mission...")==true)
	{
		pForm.txtOutline.focus();
		return false;
	}
	if(pForm.txtOutline.value=="Descriptif de la mission")
	{
		alert("Veuillez décrire la mission...");
		pForm.txtOutline.focus();
		return false;
	}
	if(pForm.txtContactPerson.value.isempty("Saisissez votre nom...")==true)
	{
		pForm.txtContactPerson.focus();
		return false;
	}
	if(pForm.txtCompany.value.isempty("Saisissez le nom de votre société...")==true)
	{
		pForm.txtCompany.focus();
		return false;
	}
	if(pForm.txtTelephone.value.isempty("Saisissez votre numéro de téléphone...")==true)
	{
		pForm.txtTelephone.focus();
		return false;
	}
	if(pForm.txtEMail.value.isempty("Saisissez votre adresse E-mail...")==true)
	{
		pForm.txtEMail.focus();
		return false;
	}
	if(pForm.txtEMail.value.isemailid("Vérifiez votre adresse E-Mail...")==false)
	{
		pForm.txtEMail.focus();
		return false;
	}
	pForm.action = "enregistrement-offre.asp";
	pForm.submit();
	return false;
}

function JoindreCV()
{
	/*
		Function to validate the data entered on the form before submitting
		This function is called when user clicks on submit button
		If all the data is entered properly then it submits the form to send email to specified email id
	*/
	var pForm = window.document.frmCloRef //Variable to hold form object
	
	if(pForm.txtFirstName.value.isempty("Veuillez entrer votre Prénom.")==true)
	{
		pForm.txtFirstName.focus();
		return false;
	}
	if(pForm.txtLastName.value.isempty("Veuillez entrer votre Nom.")==true)
	{
		pForm.txtLastName.focus();
		return false;
	}
	if(pForm.txtEmail.value.isempty("Veuillez entrer votre E-mail.")==true)
	{
		pForm.txtEmail.focus();
		return false;
	}
	if(pForm.txtEmail.value.isemailid("Vérifiez votre adresse E-Mail.")==false)
	{
		pForm.txtEmail.focus();
		return false;
	}
	if(pForm.txtPhone1.value.isempty("Veuillez entrer votre Telephone.")==true)
	{
		pForm.txtPhone1.focus();
		return false;
	}
	dateOfB =pForm.txtDateOfBirthMM.value.trim() + "/" + pForm.txtDateOfBirthDD.value.trim() + "/" + pForm.txtDateOfBirthYY.value.trim();
	if(dateOfB=="//")
	{
		alert("Saisissez votre date de naissance !");
		pForm.txtDateOfBirthDD.focus();
		return false
	}
	if(dateOfB.isdate() == false)
	{
		pForm.txtDateOfBirthDD.focus();
		return false
	}
	/*pForm.action = location.href;*/
	pForm.submit();
	return false;
}

function validerFormDepotOffreParTelephone()
{
	var pForm = window.document.moteur;
	
	if(pForm.txtContactPerson.value.isempty("Saisissez votre nom...")==true)
	{
		pForm.txtContactPerson.focus();
		return false;
	}
	if(pForm.txtCompany.value.isempty("Saisissez le nom de votre société...")==true)
	{
		pForm.txtCompany.focus();
		return false;
	}
	if(pForm.txtTelephone.value.isempty("Saisissez votre numéro de téléphone...")==true)
	{
		pForm.txtTelephone.focus();
		return false;
	}
	if(pForm.txtEMail.value.isempty("Saisissez votre adresse E-mail...")==true)
	{
		pForm.txtEMail.focus();
		return false;
	}
	if(pForm.txtEMail.value.isemailid("Vérifiez votre adresse E-Mail...")==false)
	{
		pForm.txtEMail.focus();
		return false;
	}
	/*pForm.action = "depot-offre-par-telephone.asp";*/
	pForm.submit();
	return false;
}

function redirection(page, time)
{
	if(time != '')
	{
		setTimeout("redirection('" + page + "', '')", time);
	} else
	{
		window.location = page;
	}
	return true;
}
