window.onerror = new Function("return true")

function getLang(){
    var h=document.getElementById("langID")
    if(!h)return 2
    var i=parseInt(h.value)
    if(isNaN(i))return 3
    else return i
}

//////// SET FOCUS ////////
function setFocus(){
	try{
		var zp = document.getElementById("zip")
		zp.focus()
	}catch(e){}
}
//////  PHONE AUTO TAB //////
var phone_field_length = 0;

function TabNext( obj, event, len, next_field ){
	phNz(obj)
	if( event == "down" )
		{ phone_field_length = obj.value.length; }
	else if( event == "up" ){		
		if( obj.value.length != phone_field_length )
		{ 
				phone_field_length = obj.value.length; 
				if( phone_field_length == len)
					{next_field.focus();}
		}
	}
}

function phNz(obj){	// replace value remove and any non numeric values
	var number = ""
		if( obj.value.length > 0 ){	
			for ( var z = 0; z<= obj.value.length; z ++ ){
				var ch = obj.value.substr(z, 1 )
					if( ! isNaN(ch) && ch != "" && ch != " " && ch != "  " )
						{ number += ch }			
			}
			obj.value = number
		}
}
/////// MULTIPLE ACTION FORM SUBMISSION ///
function submitForm(val){
	document.forms[0].action.value = val;					
	document.forms[0].submit();
}
///// OPEN WINDOW /////////////////////
function newWindow( wPath, wName, w, h, scroll ){
	var leftPosition = ( screen.width ) ? ( screen.width - w ) / 2 : 0;
	var topPosition = ( screen.height ) ? ( screen.height - h ) / 2 : 0;
	var settings = "height=" + h + ", width=" + w + ", top=" + topPosition + ", left=" + leftPosition + " , scrollbars=" + scroll + ", resizable"
	var win = window.open( wPath, wName, settings )
		if( win.window.focus )
			{ win.window.focus(); }
}
///////// REFRESH SCHEDULE ////////////
function refreshBase(el, jobDate){
	window.location = window.location.pathname  + "?jobDate=" + jobDate + "&jobDurationID=" + el.value
}
//////// LEFT MENU NAVIGATION /////////
function leftMenu(url, md, yn, zid ){
	if( yn == 1 && zid == 0 ){
	    if( getLang() == 12 )
	        alert("Veuillez inscrire votre code postal /ZIP au pr\xE9alable, pour qu’on puisse rep\xE9rer la grille de prix pour votre ville.");
	    else
	        alert("Please enter your ZIP (Postal) Code first so that we may pull up the correct price list for your city."); 
	    return
	}
	if( md == 1 ){
		var hgt = screen.height - 30
		var win
		window.open( url, "N", "width=700, height=" + hgt + ", top=0, left=0, resizable=yes, scrollbars=yes " ) 
	}
	else
		{ window.location = url }
}
//////// GET HAZMAT ////////
function getHazMat(url){
	window.open( url, "HZ", "width=700, height=550, resizable=yes, scrollbars=yes " ) 
}
//////// CANCEL JOB ////////
function cancelJob(path, region){
	var vText = ""
	
	if( getLang() == 12 )
		vText = "\xCAtes-vous s\xFBr vous voulez-vous annuler le rendez-vous?"//Êtes-vous sûr vous voulez-vous annuler le rendez-vous?
	else
		vText = "Are you sure you want to cancel?"
	var conf = confirm(vText)
	if( conf )
		{ window.location = path }
}
//////// MOVE JOB /////////////
function moveDur(path, dur){
	var dr = document.all.jobDurationID
	if( dr.value > 0 )
		{ window.location = path + dr.value }
	else { 
	    if( getLang() == 12 )
	        alert("Veuillez choisir une estimation de la dur\xE9e de votre rendez-vous.");
	    else
	        alert("Please select an Estimated Job Duration."); 
	}
}
//////////// FORGOT PASSWORD //////
function forgotPassword(url){
	window.location = url + "?eMail=" + document.getElementById("userName").value
}
function forgotPasswordInline(eMail, url){
	window.location = url + "&eMail=" + eMail
}
//////// CREDIT CARD CHECK ///////////////

function ccNz(){ 	// replace value remove " ", "-", "_" and any non numeric values
	var ccNumber = document.all.cardNo
	var number = ""
	var digitPosRight  = 0
		for ( var z = 0; z<= ccNumber.value.length; z ++ ) 
		{
			var ccEl = ccNumber.value.substr(z, 1 )
			if( ! isNaN(ccEl) && ccEl != "" && ccEl != " " && ccEl != "  ")
				{ number += ccEl }			
		}
		ccNumber.value = number
}

function ccValidate(ccNumber, ynValidate, mode){	
	var digits = '';
	var number = ccNumber;
	var digitPosRight=0;
		ccNz()
		for ( var ccDigit = 1; ccDigit<= number.length; ccDigit ++ )	{
			digitPosRight ++;
			var digitPos = number.length - ccDigit;
			digits = (digitPosRight % 2 == 0) ? (( number.charAt(digitPos) / 1) * 2 ) + digits : number.charAt( digitPos ) + digits;
		}
		digitPosRight = 0;
		for (var ccDigit = 0; ccDigit < digits.length; ccDigit ++ ){
			digitPosRight += (digits.charAt(ccDigit)/1);
		}
	if(ynValidate == false ){ 
		var ret = ((digitPosRight % 10 == 0) || ((number.length == 15) && ((number.substr(0, 4) == '2014') || (number.substr(0, 4) == '2149')))); 
		if( ret == false )
			{
				if( mode != true ){ 
				    if ( getLang() == 12 )
				        alert("Le num\xE9ro de la carte de cr\xE9dit ne correspond pas au type de carte s\xE9lectionn\xE9.\nVeuillez v\xE9rifier le num\xE9ro de carte de cr\xE9dit et choisir du menu d\xE9roulant le genre appropri\xE9 de carte de cr\xE9dit.");
				    else
				        alert("The credit card number did not match the card type that you selected.\nPlease check the credit card number and select the proper credit card type from the dropdown menu.");  
				}
			}
		return ret
	}
	else
		{ return true }
}

function ccFindType(ccNumber){	
	var arrCCNames = new Array ('MasterCard' , 'Visa' , 'Amex' , 'Diners Club' , 'Discover' , 'enRoute', 'JCB' );
		switch (ccNumber.length){
			case 13 : 
				switch (ccNumber.charAt(0)){
					case '4' : return arrCCNames[1]; break;
				}
			case 14 : 
				switch (ccNumber.substr(0, 2)) {
					case '36' :
					case '38' : return arrCCNames[3]; break;
				}
				switch (ccNumber.substr(0, 3)){
					case '300' :
					case '301' :
					case '302' :
					case '303' :
					case '304' :
					case '305' : return arrCCNames[3];break;
				} 
			break;
			case 15 : 
				switch (ccNumber.substr(0, 2)) {
					case '34' :
					case '37' : return arrCCNames[2]; break;
				}
				switch (ccNumber.substr(0, 4)){
					case '2014' :
					case '2149' : return arrCCNames[5]; break;
					case '2131' :
					case '1800' : return arrCCNames[6]; break;
				} 
			break;
			case 16 : 
				switch (ccNumber.charAt(0)){
					case '3' : return arrCCNames[6]; break;
					case '4' : return arrCCNames[1]; break;
				}
				switch (ccNumber.substr(0, 2)){
					case '51' :
					case '52' :
					case '53' :
					case '54' :
					case '55' : return arrCCNames[0]; break;
				}
				switch (ccNumber.substr(0, 4)){
						case '6011' : return arrCCNames[4];break;
				}
			break;
	}
	return '';
}

function changeLanguage(reg){
	window.location = self.location.pathname + "?c=CA&r=" + reg 
}

function navigateEdit(vUrl){
	window.location = vUrl
}

/* new scripts */
// change country function 

function show_change_country() {
	div = document.getElementById('change_country');
	div.style.display = 'block';
	return false;
}

function close_change_country() {
	div = document.getElementById('change_country');
	div.style.display = 'none';
	return false;	
}

function show_haz_mat(sectionId) {
    div = document.getElementById(sectionId);
	div.style.display = 'block';
}

function close_haz_mat(sectionId) {
    div = document.getElementById(sectionId);
	div.style.display = 'none';
}

function show_help(sectionId) {
	div = document.getElementById(sectionId);
	div.style.display = 'block';
	divB = document.getElementById('help_' + sectionId);
	divB.style.display = 'none';
	return false;
}

function close_help(sectionId,helpId) {
	div = document.getElementById(sectionId);
	div.style.display = 'none';
	divB = document.getElementById('help_' + sectionId);
	divB.style.display = 'block';
	return false;	
}

function close_profile(){
	div = document.getElementById("divFranchiseProfile");
	div.style.display = 'none';
	//divB = document.getElementById("divFranchiseProfileClose");
	//divB.style.display = 'block';
	return false;
}

function show_profile(){
	div = document.getElementById("divFranchiseProfile");
	div.style.display = 'block';
	divB = document.getElementById("divFranchiseProfileClose");
	divB.style.display = 'none';
	return false;
}


function showCountryPicker() {
	div = document.getElementById('countryPicker');
	div.style.display = 'block';
	return false;
}


function checkCountryPicker(){
	if(event.keyCode == 27 || event.srcElement.className.toUpperCase() != "COUNTRYPICKER")
		closeCountryPicker() 	
}


function closeCountryPicker() {
	div = document.getElementById('countryPicker');
	div.style.display = 'none';
	return false;	
}

/*
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;
*/

window.onload = setTimeout("checkForCurrentPage()", 50)


function checkForCurrentPage(){
	try{
		var a = document.all("leftMenuItem")
		var u = window.location.pathname.toUpperCase()
		for (var i = 0; i < a.length; i++){
			if(a[i].url.toUpperCase() == u){
				a[i].className = "active"
			}		
		}
	}
	catch(e){}
}

var m_oTimeout,m_oMenu,m_oSpan;
function showCC(){ks();m_oMenu=document.getElementById("countryPicker");m_oMenu.style.display="block";}
function hideCC(){m_oTimeout=window.setTimeout("hCC()",500);}
function hCC(){m_oMenu.style.display="none";m_oMenu=null;}     
function ks(){clearTimeout(m_oTimeout);}


function changeTime(el){
	el.style.color = "#0E2B8D";
	alert(document.all.availSpace);
}


function openDivZip(){

	var dTextZip = document.getElementById("divTextZip");
	dTextZip.style.display = "none";
	
	var dZip =  document.getElementById("divZip");
	dZip.style.display="block";
}

function show_posting(z){
	document.getElementById("divJobInfo_" + z).style.display = "block";
	document.getElementById("spanJobPosting_" + z).style.display = "none";
	return false;
}

					
function reloadBook1(value,url){
    document.getElementById("action").innerHTML = "Loading...";
    document.getElementById("action").disabled = "true";
	window.location = url + "?jobDurationID=" + value;
}






