var browser;
var ddFix = 0;

function tabAdjust() {
	browser = navigator.appName;
	version = navigator.appVersion;
	
	if (browser == "Netscape") {                                              
		if ((version.search(/Safari/) != -1)) {
			/*using Safari or Chrome*/ddFix = 6;
		} else {
			/*using Firefox*/ddFix = 0;
		}
	} else {
		/*using Opera or IE*/ddFix = 0;
	}              
}

tabAdjust()

function showDD(id) {
	var tmp = theme.replace(/#/,'');
	tmp = tmp.toUpperCase();
				
	tabID = id.substr(0, (id.length-2) );
	ddObj = getObj( id );
	tabObj = getObj( tabID );
	
	tabObj.style.background = "url('/canada/portal/smb/images/tabs/tab_background_"+tmp+".gif')";
	ddObj.style.left = (findPosX( tabObj ) - 1 ) + 'px';
	ddObj.style.top = (findPosY( tabObj ) + findHeight( tabObj ) )- ddFix + 'px';
	ddObj.style.display = "";
}

function hideDD(id) {
	tabID = id.substr(0, (id.length-2) );
	tabObj = getObj( tabID );
	tabObj.style.background = "url('/canada/portal/smb/images/tabs/tab_background_default.gif')";
	
	getObj(id).style.display = "none";
}

function findPosX( obj ) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if ( obj.x )
		curleft += obj.x;
	return curleft;
}

function findPosY( obj ) {
	var curtop = 0;
	if ( obj.offsetParent ) {
		while ( obj.offsetParent ) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if ( obj.y )
		curtop += obj.y;
	return curtop;
}

function findHeight( obj ) {
	var curHeight = 0;
	if ( obj.offsetHeight )
		curHeight = obj.offsetHeight;
	return curHeight;
}

function getObj( id ) {
	if ( document.getElementById ) {
		return document.getElementById(id);
	} else if ( document.all ) {
		return document.all[id];
	} else if ( document.layers ) {
		if ( document.layers[id] ) {
			return document.layers[id];
		} else {
			return null;
		}
	}
}


// Removes the instructional text from the email address box for newsletter signups
function removeInstructionalText(e) {
	if ( e.value.toLowerCase() == "e-mail address" ) { e.value = "" }
}

function removeInstructionalTextFR(e) {
	if ( e.value.toLowerCase() == "courriel" ) { e.value = "" }
}

function checkEmail(strVar) {
    var emailReg = /^(\w){1}[^\*\$\^\&\!\#\%\(\)\+\`\~\,\/\?\:\;\\\"\|\[\]\{\}\@]+\@(\w){1}(\w|-|\.)+\.[a-z]{2,4}$/i;
    var emOK = true;
    if(strVar.length > 1){
		if(!emailReg.test(strVar)){
			emOK = false;
		}
	} 
    return emOK;
}

function validateEmail() {
	if ((document.emailForm.EMAIL.value != "") && (document.emailForm.EMAIL.value != document.emailForm.EMAIL.defaultValue)) {
		if (!checkEmail(document.emailForm.EMAIL.value)) {
			alert("Invalid email address");
			return false;
		} // end if
	} else { //email is blank
		alert("Invalid email address");
		return false;
	}
	return true;
} // end function

function validateEmailFR() {
	if ((document.emailForm.EMAIL.value != "") && (document.emailForm.EMAIL.value != document.emailForm.EMAIL.defaultValue)) {
		if (!checkEmail(document.emailForm.EMAIL.value)) {
			alert("Adresse de courriel erronée");
			return false;
		} // end if
	} else { //email is blank
		alert("Adresse de courriel erronée");
		return false;
	}
	return true;
} // end function

//Procuct image switching for the index1 and index2 pages
if (document.images) {
	var tmp = theme.replace(/#/,'');
	tmp = tmp.toUpperCase();
	
	// Set width and height of all images
	var img_width=152;
	var img_height=72;

	 // SET DEFAULT IMAGES FOR EACH SEGMENT (onmouseout)    
	 ipg_off     = new Image(img_width,img_height);
	 ipg_off.src = "/canada/portal/smb/images/swap/printer.jpg";
	 
	 psg_off     = new Image(img_width,img_height);
	 psg_off.src = "/canada/portal/smb/images/swap/desktop.jpg";
	 
	 tsg_off     = new Image(img_width,img_height);
	 tsg_off.src = "/canada/portal/smb/images/swap/server.jpg";


	 // PSG IMAGES
	 psg_workstation     = new Image(img_width,img_height);
	 psg_workstation.src = "/canada/portal/smb/images/swap/desktop.jpg";

	 psg_notebook     = new Image(img_width,img_height);
	 psg_notebook.src = "/canada/portal/smb/images/swap/notebook.jpg";
	 
	 psg_handheld     = new Image(img_width,img_height);
	 psg_handheld.src = "/canada/portal/smb/images/swap/handheld.jpg";
	 
	 psg_monitor     = new Image(img_width,img_height);
	 psg_monitor.src = "/canada/portal/smb/images/swap/monitor.jpg";
	 
	 psg_pos     = new Image(img_width,img_height);
	 psg_pos.src = "/canada/portal/smb/images/swap/pos.jpg";
	 
	 psg_accessories     = new Image(img_width,img_height);
	 psg_accessories.src = "/canada/portal/smb/images/swap/accessories.jpg";
	 
	 	 psg_thin     = new Image(img_width,img_height);
	 psg_thin.src = "/canada/portal/smb/images/swap/thin.jpg";


	 // IPG IMAGES
	 ipg_multifunction     = new Image(img_width,img_height);
	 ipg_multifunction.src = "/canada/portal/smb/images/swap/printer.jpg";
	 
	 ipg_fax     = new Image(img_width,img_height); 
	 ipg_fax.src = "/canada/portal/smb/images/swap/scanner.jpg";
	 
	 ipg_digital     = new Image(img_width,img_height);
	 ipg_digital.src = "/canada/portal/smb/images/swap/photography.jpg";
	 
	 ipg_supplies     = new Image(img_width,img_height); 
	 ipg_supplies.src = "/canada/portal/smb/images/swap/ink.jpg";


	// SERVER
	 tsg_server     = new Image(img_width,img_height);
	 tsg_server.src = "/canada/portal/smb/images/swap/server.jpg";
	 
	 tsg_storage     = new Image(img_width,img_height);
	 tsg_storage.src = "/canada/portal/smb/images/swap/storage.jpg";
	 
	 tsg_network     = new Image(img_width,img_height);
	 tsg_network.src = "/canada/portal/smb/images/swap/networking.jpg";
	 
	 tsg_blade     = new Image(img_width,img_height);
	 tsg_blade.src = "/canada/portal/smb/images/swap/blades.jpg";
	 
	 // TABS
	 tab_background     = new Image(1,27);
	 tab_background.src = "/canada/portal/smb/images/tabs/tab_background_"+tmp+".gif";

	 tab_dd_background     = new Image(210,200);
	 tab_dd_background.src = "/canada/portal/smb/images/tabs/tab_dd_background_"+tmp+".jpg";
	 
}
		
// Change the image
function changeImage(imgName,picobj) {
	if (document.images) { 
		document.images[imgName].src= picobj.src;
	}
}