// JavaScript Document
var mainWidth	= 778;
var mainHeight	= 469;

var homePage	= 'index.shtml';

window.onresize = setMainProp;

/**
 * Setting width / height of available window's space
 */
var viewPortWidth;
var viewPortHeight;

function setWindowProp() 
{
	if (typeof window.innerWidth != 'undefined') {	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		viewPortWidth	= window.innerWidth,
		viewPortHeight	= window.innerHeight
	} else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth !=
	'undefined' && document.documentElement.clientWidth != 0) { // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		viewPortWidth = document.documentElement.clientWidth,
		viewPortHeight = document.documentElement.clientHeight
	} else { // older versions of IE
		viewPortWidth = document.getElementsByTagName('body')[0].clientWidth,
		viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
	}
}

/**
 * Set main div border if resolution bigger than 800 x 600
 */
function setMainProp()
{
	//	Set dimensions
	setWindowProp();
	
	if (viewPortWidth > 800) {
		document.getElementById('hpMain').style.width	= (778 + 2 * 3) + 'px';
		document.getElementById('hpMain').style.border	= '3px solid white';

		if (viewPortHeight > mainHeight) {
			var marginTop = ((viewPortHeight - mainHeight) / 2) + 'px';
			
			//document.body.style.paddingTop		= marginTop;
			//document.body.style.paddingBottom	= marginTop;
		}
	}
	
	//	Added on 15/03/2008
	document.getElementById('hpMain').style.height	= viewPortHeight + 'px';
}

/**
 * Mailing list form validation
 */
function mListValid()
{
	null;
}

/**
 * Clear / populate field value on focus / blur
 */
function clearVal(id, initVal, flag)
{
	if ((document.getElementById(id).value == initVal) && (flag == 0)) {
		document.getElementById(id).value	= '';
	}
	
	if ((document.getElementById(id).value == '') && (flag == 1)) {
		document.getElementById(id).value	= initVal;
	}
}

/**
 * Show / Hide sub-navigation
 * All vMainNav related issues has been added by JBC on 2008-06-02 @ 08:40 AM
 */
var vMainNav	= '';

function showHideSubNav(mainNav)
{
	if ((vMainNav != '') && (vMainNav != mainNav)) {
		document.getElementById(vMainNav + 'Sub').style.display	= 'none';
		document.getElementById(vMainNav).className	= 'leftNav2';
	}
	
	if (document.getElementById(mainNav + 'Sub').style.display == 'none') {
		document.getElementById(mainNav + 'Sub').style.display	= '';
		document.getElementById(mainNav).className	= 'leftNav2On';
		
		vMainNav	= mainNav;
	} else {
		document.getElementById(mainNav + 'Sub').style.display	= 'none';
		document.getElementById(mainNav).className	= 'leftNav2';
		
		vMainNav	= '';
	}
}

/**
 * Highlight menu
 */
function highlightMenu()
{
	if (subId) {
		showHideSubNav(pageId);
		document.getElementById(subId).className	= 'leftNavSubOn';
	} else {
		document.getElementById(pageId).className	= 'leftNavOn';
	}
}

/**
 * Validate contact us form
 */
function validateContactForm()
{
	var oFrm	= document.getElementById('frmContact');
	
	if (oFrm.fname.value == '') {
		alert("Please enter your first name.");
		oFrm.fname.focus();
		return;
	} else if (oFrm.lname.value == '') {
		alert("Please enter your last name.");
		oFrm.lname.focus();
		return;
	} else if (oFrm.email.value.indexOf ('@', 0) == -1 || oFrm.email.value.indexOf ('.', 0) == -1 ) {
		alert("Please enter a valid email address.");
		oFrm.email.focus();
		return;
	} else if (oFrm.phone.value == '') {
		alert("Please enter your phone number.");
		oFrm.phone.focus();
		return;
	} else if (oFrm.message.value == '') {
		alert("Please enter your message / comment.");
		oFrm.message.focus();
		return;
	} else {
		oFrm.submit();
	} 
}

/**
 * Validate mailing list form
 */
function validateMailingListForm()
{
	var oFrm	= document.getElementById('frmContact');
	
	if (oFrm.fname.value == '') {
		alert("Please enter your full name.");
		oFrm.fname.focus();
		return;
	} else if (oFrm.email.value.indexOf ('@', 0) == -1 || oFrm.email.value.indexOf ('.', 0) == -1 ) {
		alert("Please enter a valid email address.");
		oFrm.email.focus();
		return;
	} else if (oFrm.country.value == '') {
		alert("Please select country.");
		oFrm.country.focus();
		return;
	} else if (oFrm.phone.value == '') {
		alert("Please enter your phone number.");
		oFrm.phone.focus();
		return;
	} else if (oFrm.occupation.value == '') {
		alert("Please enter your occupation.");
		oFrm.occupation.focus();
		return;
	} else {
		oFrm.submit();
	} 
}

/**
 * JustSoPicWindow function for image popups
 */
function JustSoPicWindow(imageName, imageWidth, imageHeight, alt, bgcolor, hugger, hugMargin)
{
	if (bgcolor == "") {
		bgcolor="#FFFFFF";
	}

	var adj        = 10;
	var lift;
	var w          = screen.width;
	var h          = screen.height;
	var byFactor   = 1;
	var scrollbars	= '';

	if (w < 740) {
        lift = 0.90;
	}

	if (w >= 740 & w < 835){
        lift = 0.91;
	}

	if (w >= 835) {
        lift = 0.93;
	}

	if (imageWidth > w) {
        byFactor    = w / imageWidth;
        imageWidth  = w;
        imageHeight = imageHeight * byFactor;
	}

	if (imageHeight > h - adj){
        byFactor    = h / imageHeight;
        imageWidth  = (imageWidth * byFactor);
        imageHeight = h;
	}

	var scrWidth   = w-adj;
	var scrHeight  = (h * lift) - adj;

	if (imageHeight > scrHeight){
        imageHeight = imageHeight*lift;
        imageWidth  = imageWidth*lift;
		scrollbars	= 'scrollbars=1,';
	}

	var posLeft    = 0;
	var posTop     = 0;

	if (hugger == "hug image") {
        if (hugMargin == "") {
            hugMargin = 0;
        }

        var scrHeightTemp = imageHeight - 0 + 2 * hugMargin;

        if (scrHeightTemp < scrHeight) {
            scrHeight = scrHeightTemp;
        }

        var scrWidthTemp = imageWidth - 0 + 2 * hugMargin;

        if (scrWidthTemp < scrWidth) {
            scrWidth = scrWidthTemp;
        }

        if (scrHeight < 100) {
            scrHeight = 100;
        }

        if (scrWidth < 100) {
            scrWidth = 100;
        }

        posTop  = ((h - (scrHeight / lift) - adj) / 2);
        posLeft = ((w - (scrWidth) - adj) / 2);
 	}

	if (imageHeight > (h * lift) - adj || imageWidth > w - adj) {
		imageHeight   = imageHeight-adj;
		imageWidth    = imageWidth-adj;
	}

	var agt = navigator.userAgent.toLowerCase();

	if (agt.indexOf("opera") != -1) {
        var args    = new Array();

        args[0] = 'parent';
        args[1] = imageName;

        var i ;

        document.MM_returnValue = false;

        for (i = 0; i < (args.length - 1); i += 2) {
            eval(args[i] + ".location='" + args[i + 1] + "'");
        }
	} else {
    	newWindow = window.open("", "newWindow", scrollbars + "width = " + scrWidth + ", height = " + scrHeight + ", left = " + posLeft + ",top = " + posTop);

    	newWindow.document.open();
    	newWindow.document.write('<html><title>' + alt + '</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor=' + bgcolor + ' onBlur="self.close()" onClick="self.close()">');
    	newWindow.document.write('<table width=' + imageWidth + ' border="0" cellspacing="0" cellpadding="0" align="center" height=' + scrHeight + ' ><tr><td>');
    	newWindow.document.write('<center><img SRC="' + imageName + '" align="center"  alt="Click screen to close" >');
    	newWindow.document.write('</td></tr></table></body></html>');
    	newWindow.document.close();
    	newWindow.focus();
	}
}
