function D(id){
	return document.getElementById(id);
}

function showZip(objFrm,txtZip,fromPress){
	LeftPosition = (screen.width) ? (screen.width-630)/2 : 0; TopPosition = (screen.height) ? (screen.height-270)/2 : 0; window.open('zipFindMovingFrom.php?frm='+objFrm +'&part='+fromPress+ '&txtZip='+txtZip,'ZipCodes','height='+400+',width='+586+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes');
}

function openWindow(parReDir){
	window.open(parReDir);
}

function custPage(todo){
	if (todo=='com'){
		D('ih').innerHTML="Company Information";
		D('com_name').innerHTML ="<table width='100%'  border='0' cellspacing='0'><tr><td valign='top' class='form_label' width='4'>&nbsp;</td><td valign='top' class='form_label' style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' width='22%'>Company Name </td><td valign='top' class='form_label' style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' width='1%'>:</td><td colspan='4' style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' width='5%'><input type='text' class='textInput' name='company_name' size='20'></td><td>&nbsp;</td><td>&nbsp;</td><td style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>&nbsp;</td></tr></table>";
		D('postal').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='7'>&nbsp;</td><td width='23%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Postal Code</td><td width='2%'>:</td><td><input name='postal_code' style='font-weight: 700' size='20' class='textInput'></td></tr></table>";
		D('city').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='1' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>&nbsp;</td><td width='21%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >City</td><td width='2%' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>:</td><td style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'><input name='city_name' class='textInput' size='20'></td></tr></table>";
		D('homePhone').innerHTML ="";
		D('cellPhone').innerHTML ="";
		D('officePhone').innerHTML ="Business Phone";
		D('empData').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='1' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>&nbsp;</td><td width='21%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Employee No</td><td width='2%' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>:</td><td style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'><input name='employee_no' class='textInput' size='20'></td></tr></table>";
		D('companyIs').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='1' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>&nbsp;</td><td width='21%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Company Location is</td><td width='2%' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>:</td><td style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'><input type='checkbox' name='isHQ' value='1'  checked></font><b><font size='1' face='Verdana' class='form_label_normal'>Corp. Headquarters</font></b><font face='Verdana' size='1'><input type='checkbox' name='isBranch' value='1'></font><b><font size='1' face='Verdana' class='form_label_normal'>Branch</font></b><font face='Verdana' size='1'><input type='checkbox' name='isSub' value='1'  ></font><b><font size='1' face='Verdana' class='form_label_normal'>Subsidiary</font></b><font face='Verdana' size='1'><input type='checkbox' name='isOther' value='1'></font><b><font size='1' face='Verdana' class='form_label_normal'>Other * </font></td></tr></table>";
		D('com_url').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='1' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>&nbsp;</td><td width='21%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Company Web URL</td><td width='2%' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>:</td><td style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'><input name='com_url' class='textInput' size='20'></td></tr></table>";
		D('ind_type').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='1' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>&nbsp;</td><td width='21%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Branch of industry</td><td width='2%' style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'>:</td><td style='border-bottom: 1px solid #F5F5F5; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px'><select name='industry_type' class='form_label_normal' ><option selected value='0'> Click below</option><option value='Agroalimentaire'>Agroalimentary</option><option value='Assurance'>Insurance</option><option value='Banque Finance'>Bank Finance</option><option value='Automobile'>Car</option><option value='Bien de consommation'>Consumer good</option><option value='Communication Marketing Publicité'>Comm Marketing Pub</option><option value='Distribution'>Distribution</option><option value='Hôtellerie'>Hotel trade</option><option value='Informatique'>Data processing</option><option value='Restauration'>Restoration</option><option value='Santé'>Health</option><option value='Service Public'>Public utility</option><option value='Autres secteurs'>Other sectors</option></select></td></tr></table>";
		D('com_inf_header').innerHTML ="<table width='100%' cellpadding='0' cellspacing='0'><tr><td width='3%' class='c'><img src='images/Linkblue1.bmp'></td><td width='97%' class='marked_label'>  Company's Other Information</td></tr></table>";
	}

	if (todo=='ind'){
		D('ih').innerHTML="Personal (Individual) Information";
		D('com_name').innerHTML ="";
		D('postal').innerHTML ="";
		D('city').innerHTML ="";
		D('homePhone').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='7'>&nbsp;</td><td width='23%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Home Phone</td><td width='2%'>:</td><td><input name='phone_num' class='textInput' size='20'></td></tr></table>";
		D('cellPhone').innerHTML ="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr class='form_label_normal'><td width='7'>&nbsp;</td><td width='23%' class='form_label'  style='border-bottom: 1px solid #F7F7F7; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px' >Cell Phone</td><td width='2%'>:</td><td><input name='cell_num' class='textInput' size='20'></td></tr></table>";
		D('officePhone').innerHTML ="Work Phone";
		D('empData').innerHTML ="";
		D('companyIs').innerHTML ="";
		D('com_url').innerHTML ="";
		D('ind_type').innerHTML ="";
		D('com_inf_header').innerHTML ="";
	}
}

function is_numeric(num){
	var exp = new RegExp("^[0-9-.]*$","g");
	return exp.test(num);
}

function testemail() {
	myForm=document.estimate_1;
	var email = myForm.email_address.value;
	if ((email.indexOf('@',0)==-1) || (email.indexOf('.',0)==-1)) {
		alert("adresse email incorrecte");
		return false;
	}else{
		return true;
	}
}

function isEmail(mail) {
	var regex = new RegExp("^[a-z0-9_]([.-]?[a-z0-9_]+)+@[a-z0-9_]([.-]?[a-z0-9_]+)+\.([a-z]{2,4}|[a-z]{6})$", "gi");
	return regex.exec(mail);
}

function checkForm(){
	myForm=document.estimate_1;
		if(myForm.first_name.value==""){
		alert ("Veuillez saisir votre Nom.");
		myForm.first_name.focus();
		return false;
	}

	if(myForm.last_name.value==""){
		alert ("Veuillez saisir votre Prénom.");
		myForm.last_name.focus();
		return false;
	}

	if(myForm.email_address.value==""){
		alert ("Veuillez saisir votre Adresse E-mail.");
		myForm.email_address.focus();
		return false;
	}

	if(myForm.email_address.value!=""){
		valid = testemail();
		if (valid==false){
			myForm.email_address.focus();
			return false;
		}
	}

	if (myForm.home_phone.value==""){
		alert ("Veuillez saisir votre N° de Téléphone du domicile");
		myForm.home_phone.focus();
		return false;
	}

	if (myForm.home_phone.value!=""){
		var tmp=myForm.home_phone.value;
		tmp=tmp.replace(/\W|_/gi,"");
		tmp=tmp.replace(/\s+/g,"");
		if (((tmp.length <10)|| !is_numeric(tmp))||((tmp.length > 13)|| !is_numeric(tmp))){
			alert("Veuillez vérifier le N° Tél.");
			myForm.home_phone.focus();
			return false;
		}
	}

	if (myForm.work_phone.value!=""){
		var tmp=myForm.work_phone.value;
		tmp=tmp.replace(/\W|_/gi,"");
		tmp=tmp.replace(/\s+/g,"");
		if (((tmp.length <10)|| !is_numeric(tmp))||((tmp.length > 13)|| !is_numeric(tmp)))
		{
			alert("Veuillez vérifier le N° Tél.");
			myForm.work_phone.focus();
			return false;
		}
	}

	if (myForm.mobile.value!=""){
		var tmp=myForm.mobile.value;
		tmp=tmp.replace(/\W|_/gi,"");
		tmp=tmp.replace(/\s+/g,"");
		if (((tmp.length <10)|| !is_numeric(tmp))||((tmp.length > 13)|| !is_numeric(tmp)))
		{
			alert("Veuillez vérifier le N° Tél.");
			myForm.mobile.focus();
			return false;
		}
	}
	
	if (myForm.fax.value!=""){
		var tmp=myForm.fax.value;
		tmp=tmp.replace(/\W|_/gi,"");
		tmp=tmp.replace(/\s+/g,"");
		if (((tmp.length <10)|| !is_numeric(tmp))||((tmp.length > 13)|| !is_numeric(tmp)))
		{
			alert("Veuillez vérifier le N° Tél.");
			myForm.fax.focus();
			return false;
		}
	}

	if(myForm.moving_from_address.value==""){
		alert ("Veuillez saisir votre Adresse de départ.");
		myForm.moving_from_address.focus();
		return false;
	}

	if(myForm.moving_from_zip_code.value==""){
		alert ("Veuillez saisir votre Code postal de départ");
		myForm.moving_from_zip_code.focus();
		return false;
	}
	
	if(myForm.moving_from_zip_code.value!=""){
		if(is_numeric(myForm.moving_from_zip_code.value)==false){
			alert ("Veuillez vérifier votre Code postal de départ");
			myForm.moving_from_zip_code.focus();
			return false;
		}
	}

	if(myForm.moving_from_city.value==""){
		alert ("Veuillez saisir votre Ville de départ");
		myForm.moving_from_city.focus();
		return false;
	}
	
	if(myForm.moving_to_address.value==""){
		alert ("Veuillez saisir votre Adresse d' arrivée");
		myForm.moving_to_address.focus();
		return false;
	}

	if(myForm.moving_to_zip_code.value==""){
		alert ("Veuillez saisir votre Code postal d' arrivée");
		myForm.moving_to_zip_code.focus();
		return false;
	}
	
	if(myForm.moving_to_zip_code.value!=""){
		if(is_numeric(myForm.moving_to_zip_code.value)==false){
			alert ("Veuillez vérifier votre Code postal de départ");
			myForm.moving_to_zip_code.focus();
			return false;
		}
	}

	if(myForm.moving_to_city.value==""){
		alert ("Veuillez saisir votre Ville d'arrivée");
		myForm.moving_to_city.focus();
		return false;
	}

	// Formulaire de devis 2
	makeSubmit=0;
	submitErrMsg="";
	var mofd = myForm.moveOnFixedDate;
	for (i=0;i<mofd.length;i++){
		if (mofd[i].checked){
			if (mofd[i].value==1){
				if(myForm.move_date.value==""){
					submitErrMsg="Déménagement prévu le n’est pas sélectionné QUOI ???";
					alert(submitErrMsg);
					myForm.move_date.focus();
					return false;
				}
			} 
			makeSubmit=1;//move_date
			submitErrMsg='';
		}
	}
	
	if(makeSubmit==0){
		submitErrMsg="Veuillez indiquer la période prévue pour votre déménagement";
		alert(submitErrMsg);
		return false;
	}	

	if(myForm.total_volume.value==""){
		alert("Vous n'avez saisi aucun meuble.");
		return false;
	}
	
	var request=window.confirm("Confirmez vous l’envoi de la demande ?");	  	   	   
	if (request) 
	return true;
	else 	
	return false;
}

function makeRequest(url) {
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {	
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = function() { alertContents(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);
}

function alertContents(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			alert(http_request.responseText);
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function checkEmailForm(){
	var myForm=D("campaign_form");
	if ((myForm.txtCampaignEmail.value=="") || (myForm.txtCampaignEmail.value=="Votre adresse email")){
		alert("Votre adresse email");
		myForm.txtCampaignEmail.focus();
		return false;
	}
	return true;
}

function submitCompaign(){
	var myForm=D("campaign_form");
	if (isEmail(myForm.txtCampaignEmail)){
		myForm.submit();
	}else{
		alert("Adresse email incorrecte");
		myForm.txtCampaignEmail.focus();
		return;
	}
}

function clearEmail(){
	myForm=document.campaign_form;
	myForm.txtCampaignEmail.value="";
}

function clearLoginId(){
	myForm=document.login_form;
	myForm.user_id.value="";
}

function clearPasswordValue(){
	myForm=document.login_form;
	myForm.password.value="";
}

function checkLoginForm(){
	myForm=document.login_form;
	var request=window.confirm("Êtes-vous sûr de confirmer?");
	if (request)
	return true;
	else
	return false;
}

// devis2
document.onkeypress = checkCR;
function checkDepartCR(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	alert(evt.keyCode);
	if ((evt.keyCode == 13)) {return false;}
}

function checkCR(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	//	alert(evt.keyCode);
	if ((evt.keyCode == 13)) {return false;}
}

function displayunicode(e){
	var unicode=e.keyCode? e.keyCode : e.charCode;
	//alert(unicode);
}

function FixedInfDisable(){
	myForm=document.estimate_1;
	for (i=0;i<myForm.moveOnFixedDate.length;i++){
		if (myForm.moveOnFixedDate[i].checked){
			if (myForm.moveOnFixedDate[i].value=='1'){
				myForm.move_date.disabled=false;
				myForm.week_start.disabled=true;
				myForm.week_end.disabled=true;
				myForm.a_week_pos.disabled=true;
				myForm.a_week_month.disabled=true;	 
				myForm.a_week_year.disabled=true;	 
				myForm.move_date.focus();
			}else if (myForm.moveOnFixedDate[i].value=='0'){
				myForm.move_date.disabled=true;
				myForm.week_start.disabled=false;
				myForm.week_end.disabled=false;
				myForm.a_week_pos.disabled=false;
				myForm.a_week_month.disabled=false;	 
				myForm.a_week_year.disabled=false;	 
				myForm.week_start.focus();
			}
		}
	} 
}
function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
	if (unicode<48||unicode>57) //if not a number
	return false //disable key press
	}
}
