//Global Functions
function Subscribe(emailAddress, isChecked) {
	if (isChecked) 
	{
		var myFrame		= document.getElementById('subscribeFrame');
		myFrame.src		= '/includes/subscribe_function.asp?email=' + emailAddress + '&sub=1';
	}
	
//	if (ValidateEmail_Global(emailAddress) == false)
	if (isValidEmail(emailAddress))
	{
		window.open('/contactus/subscription/thanks.asp?email='+ emailAddress + '','mywindow','width=370,height=180,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=yes,resizable=yes');
	}
	else
	{
		window.open('/contactus/subscription/emailnotvalid.asp?email='+ emailAddress + '','mywindow','width=370,height=180,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=yes,resizable=yes');
	}
}

function SubscribeNoMessage(emailAddress, isChecked) {
	if (isChecked) 
	{
		var myFrame		= document.getElementById('subscribeFrame');
		myFrame.src		= '/includes/subscribe_function.asp?email=' + emailAddress + '&sub=1';

	}
	
}

function isValidEmail(emailAddress) {
	var emailChk	= /^([^@\s]*)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return emailChk.test(emailAddress);
}
	
function ValidateEmail_Global(Email)
{
	var Pattern = /^(.+)@(.+)$/;
	var SpecialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    var ValidChars = "\[^\\s" + SpecialChars + "\]";
	var QuotedUser = "(\"[^\"]*\")";
	var Piece = ValidChars + '+';
	var Word = "(" + Piece + "|" + QuotedUser + ")";
	var UserPattern = new RegExp("^" + Word + "(\\." + Word + ")*$");
	var KnownDomains = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var IPDomain = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var NormalDomain = new RegExp("^" + Piece + "(\\." + Piece + ")*$");
	var MatchArray = Email.match(Pattern);
	var InvalidChars ="'#";
	var checkStr = Email;
	
	if (MatchArray == null) 
	{
		//"The e-mail address you entered does not follow the accepted pattern.");
		return true;
       }
	
	var User = MatchArray[1];
	var Domain = MatchArray[2];

	for (i = 0; i < User.length; i++) 
	{
		if (User.charCodeAt(i) > 127) 
		{
			//"The e-mail address you entered contains invalid characters in the username.");
			return true;
		}
	}

	if (User.match(UserPattern) == null) 
	{
		//"The e-mail address you entered contains an invalid username.");
		return true;
	}


	
	for (i = 0; i < Domain.length; i++) 
	{
		if (Domain.charCodeAt(i) > 127) 
		{
			//"The e-mail address you entered contains invalid characters in the domain name.");
			return true;
  		}
	}
	
	var IPArray = Domain.match(IPDomain);
	if (IPArray!=null) 
	{
		for (var i=1; i <= 4; i++) 
		{
			if (IPArray[i] > 255) 
				{
		     		//"The e-mail address you entered contains an invalid destination IP address.");
					return true;
  				}
		}
		return false;
	}

	var PiecePattern = new RegExp("^" + Piece + "$");
	var DomainArray = Domain.split(".");
	var Len = DomainArray.length;
	for (i=0; i < Len; i++) 
	{
		if (DomainArray[i].search(PiecePattern) == -1) 
		{
     		//"The e-mail address you entered contains an invalid domain name.");
			return true;
	   	}
	}

	if (DomainArray[DomainArray.length - 1].length != 2 && DomainArray[DomainArray.length - 1].search(KnownDomains) == -1) 
	{
     	//"The e-mail address you entered does not end in a well-known domain or two letter country.");
		return true;
	}		
	
	if (Len < 2) 
	{
		//"The e-mail address you entered is missing a host name.");
		return true;
	}
	
	for (i = 0;  i < checkStr.length;  i++) 
	{ 
		ch = checkStr.charAt(i); 
		for (j = 0;  j < InvalidChars.length;  j++) 
			if (ch == InvalidChars.charAt(j)) 
			{
				return true; 
			}                       
	} 
	
	return false;
}


function toggleField( fieldID ) {
	var field		= $$(fieldID)[0];
	if (field != null) {
		field.toggle();
	}
}

function NewWindow(url, windowName, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(url, windowName, winprops);
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}

//embed for product page videos
function embedObject(objectPath,width,height)
{
	document.write('<object id="MediaPlayer1" width=' + width + ' height=' + height + ' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject" align="middle"> <param name="FileName" value="' + objectPath + '"><param name="ShowStatusBar" value="false"><param name="DefaultFrame" value="mainFrame"><embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" src="' + objectPath + '" align="middle" width=' + width + ' height=' + height + ' defaultframe="rightFrame" STARTTIME="00:01 showstatusbar=false></embed></object>')
}

function replaceExtraSpaces(obText)
{
	var oRegEx		= /( ){2,}/ig;
	obText.value	= obText.value.replace( oRegEx, ' ' );
}
