/* basic mouseover code */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
   	if(a[1]!= ''){x.onclick=function(){location.href=a[1]}}
   }
}

function validateEmail(email)
{
	if (email == undefined)
		email = document.getElementById('email');

	if (email.value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) == null)
	{
		alert("Please enter a valid email address!");
		return false;
	}
	
	return true;
}

function validateCompanyName()
{
	var companyName = document.getElementById('company_name');
	if (companyName.value.match(/[a-z]{3}/i) == null)
	{
		alert('Please enter a company name.');
		return false;
	}
	return true;
}
function validateName()
{
	if (document.getElementById('name').value.match(/[a-z]{3}/i) == null)
	{
		alert('Please enter your name.');
		return false;
	}

	return true;
}
function validatePhone()
{
	if (document.getElementById('phone').value.replace(/[^0-9]/g, '').match(/[0-9]{10,}/i) == null)
	{
		alert('Please enter your phone number.');
		return false;
	}

	return true;
}
function validateComment() 
{
	if (document.getElementById('comments').value.match(/[a-z]{3}/i) == null)
	{
		alert('Please enter a comment.');
		return false;
	}

	return true;
}

function validateContactForm()
{
	document.getElementById('emailMsg').className = 'hide';
	document.getElementById('errMsg').className = 'hide';
	var fields = ['name', 'company', 'phone'];
	var errorFound = false;
	for (var x=0; x < fields.length; x++)
	{
		var field = document.getElementById(fields[x]);
		field.className = field.className.replace(/[ ]?error/g, '');
		if (field.value.length == 0)
		{
			field.className += ' error';
			errorFound = true;
		}
	}

	var email = document.getElementById('email');
	email.className = email.className.replace(/[ ]?error/g, '');
	if (email.value.match(/[^@]+[@][^.]+\.[^.]+/) == null)
	{
		email.className += ' error';
		errorFound = true;
		document.getElementById('emailMsg').className = '';
	}

	if (errorFound)
	{
		document.getElementById('errMsg').className = '';
	}

	return !errorFound;
}

function validateMoreInfoForm()
{
	document.getElementById('emailMsg').className = 'hide';
	document.getElementById('errMsg').className = 'hide';
	var fields = ['name', 'company_name', 'comments'];
	var errorFound = false;
	for (var x=0; x < fields.length; x++)
	{
		var field = document.getElementById(fields[x]);
		field.className = field.className.replace(/[ ]?error/g, '');
		if (field.value.length == 0)
		{
			field.className += ' error';
			errorFound = true;
		}
	}

	var email = document.getElementById('email');
	email.className = email.className.replace(/[ ]?error/g, '');
	if (email.value.match(/[^@]+[@][^.]+\.[^.]+/) == null)
	{
		email.className += ' error';
		errorFound = true;
		document.getElementById('emailMsg').className = '';
	}

	if (errorFound)
	{
		document.getElementById('errMsg').className = '';
	}

	return !errorFound;
}

function displayHomepageImage(num)
{
	var settings = [
		null,
		// Vanguard
		{href: 'about.php', coords:{space:'401,234,447,256', defense:'472,234,542,256', industrial:'567,234,662,256', learnmore:'604,259,665,281'}},
		// Power Magnetics
		{href: 'step2.php?cat=5', coords:{space:'405,222,451,244', defense:'476,222,546,244', industrial:'573,222,668,244', learnmore:'606,247,663,269'}},
		// RF & Microwave
		{href: 'step2.php?cat=1', coords:{space:'399,241,449,263', defense:'474,241,544,263', industrial:'569,241,664,263', learnmore:'602,271,663,293'}},
		// Pulse & Data Bus
		{href: 'step2.php?cat=21', coords:{space:'401,216,447,238', defense:'472,216,542,238', industrial:'567,216,662,238', learnmore:'604,241,665,263'}},
		// Custom Products
		{href: 'custom.php', coords:{space:'399,242,449,264', defense:'474,242,544,264', industrial:'569,242,664,264', learnmore:'602,267,663,289'}}
	];
	
	MM_swapImage('switchingImage','','images/homepage'+num+'.jpg','switchingImage');
	
	
	document.getElementById('learnmorecoords').href=settings[num].href;
	for (id in settings[num]['coords'])
		document.getElementById(id+'coords').coords=settings[num]['coords'][id];
}