// My Collection Of Useful Scripts

// print function

	function print_page() {
		if (document.all || document.layers)
		{
			window.print();
		}
	}

// browser status bar message

	window.status="The Polymer Conversions Difference"

// rollover script

	function MM_findObj(n, d) { 
	  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); return x;
	}
	
	function MM_swapImage() { 
	  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];}
	}
	
	function MM_swapImgRestore() { 
	  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() { 
	 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];}}
	}

// reloads the window if Netcrap4 resized

	function MM_reloadPage(init) {  
	  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
	MM_reloadPage(true);

// user decides if link opens new window, use a checkbox

	function targetLinks(winNew)
	{
	   if (winNew) where = "_blank";
	   else where = "_self";
	   for (var i=0; i<=(document.links.length-1); i++)
	   {
	   document.links[i].target = where;
	   }
	}

// form field validation scripts

	function mustEnter(fields, messages, theForm) {
		for(x=0;x<fields.length;x++) {
			if (theForm[fields[x]].value == '') {
				alert(messages[x]);
				theForm[fields[x]].focus();
				return false;
			}
		}
		return true;
	}

	function mustSelect(fields, messages, theForm) {
		for(x=0;x<fields.length;x++) {
			if(theForm[fields[x]].options[theForm[fields[x]].selectedIndex].value == '') {
				alert(messages[x]);
				theForm[fields[x]].focus();
				return false;
			}
		}
		return true;
	}

// check length of form fields

	function CheckLength(length) {
		 if (window.event.srcElement.value.length >= length) {
		 alert('You have reached the maximum length of characters permitted here.');
		 return false;                         
		 }
	}

// input color swapper

	function on(object) {
	object.style.backgroundColor = '#ffffcc';
	}

	function off(object) {
	object.style.backgroundColor = '';
	}

// IE specific style class toggle script

	function toggle ( targetId ){ 
	target = document.all( targetId );
		if (target.style.display == "none"){		
				target.style.display = "";
				window.event.srcElement.className = "whatevername1";
			} else {		
				target.style.display = "none";
				window.event.srcElement.className = "whatevername2";
				}
		}	

function bookmark() { 
  var bookmarktitle = document.title;
  var bookmarkurl = document.location;
  var netscape
  netscape="To Bookmark this page please click the page you would like to bookmark and press CTRL+D. If you would like to add this page to your Netscape Sidebar, please click OK on the next window which appears.";
 
  if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
    window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  }
}

function pciOrderDvdCheck(pciForm)
{
	if(pciForm.name.value.length < 2)
	{
		alert('Please enter a name with at least 2 characters.');
		pciForm.name.focus();
		pciForm.name.select();
		return false;
	}
	if(pciForm.company.value.length < 2)
	{
		alert('Please enter a company name with at least 2 characters.');
		pciForm.company.focus();
		pciForm.company.select();
		return false;
	}
	if(!ValidEmail(pciForm.email_add.value))
	{
		alert('Please enter a valid email address.');
		pciForm.email_add.focus();
		pciForm.email_add.select();
		return false;
	}
	if(pciForm.add_one.value.length < 3)
	{
		alert('Please enter an address with at least 3 characters.');
		pciForm.add_one.focus();
		pciForm.add_one.select();
		return false;
	}
	if(pciForm.city.value.length < 2)
	{
		alert('Please enter a city with at least 2 characters.');
		pciForm.city.focus();
		pciForm.city.select();
		return false;
	}
	if(pciForm.zip.value.length < 1)
	{
		alert('Please enter a zipcode.');
		pciForm.zip.focus();
		pciForm.zip.select();
		return false;
	}
	return true;
}


function pciApplyCheck()
{
	return true;
}

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
// Input Field Validation
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
function EmailCharacters(passedVal)
{ 
	if (passedVal == "")
	{ 
		return ""; 
	}
	var final_value = '';
	for (i = 0 ; i < passedVal.length; i++)
	{
		if ((passedVal.charAt(i) >= "0" && passedVal.charAt(i) <= "9") || (passedVal.charAt(i) >= "a" && passedVal.charAt(i) <= "z") || (passedVal.charAt(i) >= "A" && passedVal.charAt(i) <= "Z") || passedVal.charAt(i) == "_" || passedVal.charAt(i) == "@" || passedVal.charAt(i) == ".")
		{
			final_value = final_value + '' + passedVal.charAt(i);
		}
	}
	return final_value;
}

function ValidEmail(email)
{
	if (email == "")
	{
		return false;
	}
	var segment = new Array(false,false,false,false,false);
	var temp_segment = false;
	if (email.charAt(email.length-1) == '.')
	{
		return false;
	} 
	for (i = 0 ; i < email.length; i++)
	{ 
		temp_segment = segment[0];
		if (!temp_segment)
		{ 
			if ((email.charAt(i) >= "0" && email.charAt(i) <= "9") || (email.charAt(i) >= "a" && email.charAt(i) <= "z") || (email.charAt(i) >= "A" && email.charAt(i) <= "Z") || email.charAt(i) == "_")
			{
				if (segment[0] == false)
				{
					segment[0] = true;
				}
			}
		}
		if (temp_segment)
		{
			temp_segment = segment[1];
			if (email.charAt(i) == "@")
			{
				if (segment[1] == true)
				{
					return false;
				}
				if (segment[0] == true && segment[1] == false)
				{
					segment[1] = true;
				}
			}
		}
		if (temp_segment)
		{
			temp_segment = segment[2];
			if ((email.charAt(i) >= "0" && email.charAt(i) <= "9") || (email.charAt(i) >= "a" && email.charAt(i) <= "z") || (email.charAt(i) >= "A" && email.charAt(i) <= "Z") || email.charAt(i) == "_")
			{
				if (segment[0] == true && segment[1] == true && segment[2] == false)
				{
					segment[2] = true;
				}
			}
		}
		if (temp_segment)
		{
			temp_segment = segment[3];
			if (email.charAt(i) == ".")
			{
				if (segment[0] == true && segment[1] == true && segment[2] == true && segment[3] == false)
				{
					segment[3] = true;
				}
			}
		}
		if (temp_segment)
		{
			temp_segment = segment[4];
			if ((email.charAt(i) >= "0" && email.charAt(i) <= "9") || (email.charAt(i) >= "a" && email.charAt(i) <= "z") || (email.charAt(i) >= "A" && email.charAt(i) <= "Z") || email.charAt(i) == "_")
			{
				if (segment[0] == true && segment[1] == true && segment[2] == true && segment[3] == true)
				{
					segment[4] = true;
				}
			}
		}
		if (segment[0] && segment[1] && segment[2] && segment[3] && segment[4])
		{
			return true;
		}
	} 
	return false;
}
