/**
 *	Mitsubishi Distributors
 *	-------------------------
 */
 
 function openpic(sentlink,w,h)
{
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
new_window=open(sentlink,"",'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=no');
new_window.document.open();

// Text of the new document
// Replace your " with ' or \" or your document.write statements will fail
new_window.document.write("<html><head><title>Mitsubishi</title></head>");
new_window.document.write("<body bgcolor='#ffffff' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' >");
new_window.document.write("<img src='");
new_window.document.write(sentlink);
new_window.document.write("'></body></html>");
new_window.document.close();
}
 
function distopen(loc)
{
w = 420;
h = 300;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
setting = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=1,noresizable'
window.open(loc,"",setting);
}

function distopent(loc)
{
w = 420;
h = 500;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
setting = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=1,noresizable'
window.open(loc,"",setting);
}

function tableopen(loc,wdt,hgt)
{

LeftPosition = (screen.width) ? (screen.width-wdt)/2 : 0;
TopPosition = (screen.height) ? (screen.height-hgt)/2 : 0;
setting = 'height='+hgt+',width='+wdt+',top='+TopPosition+',left='+LeftPosition+',scrollbars=1,noresizable'
window.open(loc,"",setting);
}

window.onload = function() {
	initNavigationBar();
}

/**
 *	Forms
 *	--------------------------
 */

var FormExpressions = {
	email:'^[0-9a-z._-]*[@][0-9a-z._-]*[.][a-z]{2,4}$'
}

function submit(formName) {
	var frm = document.forms[formName];
	var elements = frm.elements, l = elements.length, name;
	for(var i=0; i<l; i++) {
		name = elements[i].name;
		if(!name || !FormExpressions[name]) continue;
		if(!validateField(FormExpressions[name], elements[i].value)) {
			alert('Please enter a valid E-mail address.');
			return;
		}
	}	frm.submit();
}
	function validateField(reg, value) {
		return (new RegExp(reg)).test(value);
	}

/**
 *	Mitsubishi navigation
 *	-------------------------
 */

function initNavigationBar() {
	if(!document.getElementsByTagName) return;
	var bOpera = navigator.userAgent.indexOf("Opera") > -1;
	var flash = document.getElementsByTagName('object');
	
	function setHoverEvent(li, ul) {
		var css = ul.style;
		li.onmouseover = function() { 
			css.visibility = 'visible';
			if(bOpera) toggleSplashFlash(flash, false);
		}

		li.onmouseout = function() { 
			css.visibility = 'hidden';	
			if(bOpera) toggleSplashFlash(flash, true);
		}

		if((li.offsetLeft + ul.offsetWidth) > 664) {
			css.left = 'auto';
			css.right = '0px';
		}
	}

	var nav = document.getElementById('navigation');
	if(!nav) return;
	var el, li, uls = nav.getElementsByTagName('ul');
	for(var i=0; i<uls.length; i++) {
		el = uls[i].parentNode;
		if(el.nodeName == 'LI') {
			setHoverEvent(el, uls[i]);
		}
	}
}
	function toggleSplashFlash(flash, toggle) {
		for(var i=0; i<flash.length; i++) {
			flash.item(i).style.display = toggle? 'block' : 'none';
		}
	}

/**
 *	Email obfuscator
 *	--------------------------
 */

function email(name, domain, ext, label) {
	var link = "<a href='mailto:"+name+"&#64;"+domain+"&#46;"+ext+"'>" + label + "</a>";
	document.write(link);
}

/**
 *	Popups
 *	-------------------------
 */

function popupImage(path) {
	window.open('/imageviewer.jsp?image=' + path, 
		'imageViewer', 'width=320,height=240,left=100,top=100');
}

function openCentered(url, width, height) {
        if (screen.width < width)
            width=screen.width
        if (screen.height< height)
            height=screen.height
	var left = (screen.width - parseInt(width))/2;
	var top = (screen.height - parseInt(height))/2;
	var settings = 'left='+left+',top='+top+',width='+width+',height='+height+'';
	window.open(url, '', settings);
}

/*
 *	Font sizer
 *	-------------------------
 */

function doFontSize(d) {
	var css = document.body.style;
	var size = parseInt(css.fontSize) || 12;
	if (size+d<16 && size+d>8) {css.fontSize = (size + d) + 'px';}
}


/**
 *	Model color chooser
 *	-------------------------
 */
 
function setModelVersion(version) {
	var img = document.getElementById('modelversion');
	img.src = version;
}

function setModelColor(color) {
	var img = document.getElementById('modelColor');
	img.src = color;
}
	function setColorLabel(link) {
		var title = link.title;
		var span = document.getElementById('colorTitle');
		span.innerHTML = title;
	}
