// JavaScript Document

function enterPDFs()
{
	check_page = location.href
	
	checkImages_ = check_page.indexOf("index.php")
	if (checkImages_ > 0) preloadImages() 
	
	check_ = check_page.indexOf("ProductPDFs.php")
	if (check_ > 0)
	{
	//
		if (read_cookie("SPECO_pdf") == null)
		{ 
		window.location.replace("request_PDF.php")
		}
		else
		{
		if (check_ == 0) window.location.replace("ProductPDFs.php")
		}
	}
}


function write_cookie (name, value, path)
{
        // Build the expiration date string:
        var expiration_date = new Date ();
        expiration_date . setYear (expiration_date . getYear () + 1);
        expiration_date = expiration_date . toGMTString ();
		// Build the set-cookie string:
        var cookie_string = escape (name) + "=" + escape (value) +
                "; expires=" + expiration_date;
        if (path != null)
                cookie_string += "; path=" + path;

        // Create/update the cookie:
        document . cookie = cookie_string;
		
		//test to see if cookies are enabled
	    //if (value != read_cookie (name)) {alert("Cookies must be enabled to store User ID");}   
}

function read_cookie (key, skips)
{
	// Set skips to 0 if parameter was omitted:
	if (skips == null)
			skips = 0;

	// Get cookie string and separate into individual cookie phrases:
	var cookie_string = "" + document . cookie;
	var cookie_array = cookie_string . split ("; ");

	// Scan for desired cookie:
	for (var i = 0; i < cookie_array . length; ++ i)
	{
			var single_cookie = cookie_array [i] . split ("=");
			if (single_cookie . length != 2)
					continue;
			var name  = unescape (single_cookie [0]);
			var value = unescape (single_cookie [1]);

			// Return cookie if found:
			if (key == name && skips -- == 0)
					return value;
	}

	// Cookie was not found:
	return null;  
}

function delete_cookie (name, path)
{
	// Build expiration date string:
	var expiration_date = new Date ();
	expiration_date . setYear (expiration_date . getYear () - 1);
	expiration_date = expiration_date . toGMTString ();

	// Build set-cookie string:
	var cookie_string = escape (name) + "=; expires=" + expiration_date;
	if (path != null)
			cookie_string += "; path=" + path;

	// Delete the cookie:
	document . cookie = cookie_string;
 }
 
function VIDEO(item)
{	
	URL = "dsp_mediaplayer.php?filename="+item;
	//URL = "http://www.schneiderequip.com/new_site/"+item;
	window.open(URL,"VIDEO","scrollbars=0,HEIGHT=310,WIDTH=460");
}

function newImage(arg) 
{
	if (document.images) 
		{
			rslt = new Image();
			rslt.src = arg;
			return rslt;
		}
}

function changeImages() 
{//preloadFlag = true
	if (document.images && (preloadFlag == true)) 
		{//alert()
			for (var i=0; i<changeImages.arguments.length; i+=2) 
				{
					document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
				}
		}
}

var preloadFlag = false;
function preloadImages() 
{
	if (document.images) 
		{
			a_02_over = newImage("images/a_02-over.gif");
			a_03_over = newImage("images/a_03-over.gif");
			a_04_over = newImage("images/a_04-over.gif");
			a_05_over = newImage("images/a_05-over.gif");
			a_06_over = newImage("images/a_06-over.gif");
			c_02_over = newImage("images/c_02-over.gif");
			c_03_over = newImage("images/c_03-over.gif");
			c_04_over = newImage("images/c_04-over.gif");
			c_05_over = newImage("images/c_05-over.gif");
			c_06_over = newImage("images/c_06-over.gif");
			c_07_over = newImage("images/c_07-over.gif");
			c_08_over = newImage("images/c_08-over.gif");
			c_09_over = newImage("images/c_09-over.gif");		
			preloadFlag = true;
		}
}


function change(form)
{    
	var checkemail = document.request.EMAIL.value
	var name = document.request.C_NAME.value
	var add_1 = document.request.ADD_1.value
	var city = document.request.CITY.value
	var state = document.request.STATE.value
	var zip = document.request.ZIP.value
	var phone = document.request.PHONE.value
	
	if (name == "")
		{
			window.alert ("The 'Name' field is required")
			return(false)
		}			

	if (add_1 == "")
		{
			window.alert ("The 'Street Address' field is required")
			return(false)
		}
	if (city == "")
		{
			window.alert ("The 'City' field is required")
			return(false)
		}							
	if (state == "")
		{
			window.alert ("The 'State' field is required")
			return(false)
		}
	if (zip == "")
		{
			window.alert ("The 'Zip' field is required")
			return(false)
		}
	if (phone == "")
		{
			window.alert ("The 'Phone' field is required")
			return(false)
		}												
	
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=checkemail.match(emailPat)
	if (matchArray==null) 
		{
			alert("Email address seems incorrect (check @ and .'s)")
			return false
		}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) 
		{
			alert("The username in the E-mail doesn't seem to be valid.")
			return false
		}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
		{
		  for (var i=1;i<=4;i++) 
			{
				if (IPArray[i]>255) 
					{
						alert("Destination IP address in the E-mail address is invalid!")
						return false
					}
			}
			return true
		}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
		{
			alert("The domain name in the E-mail address doesn't seem to be valid.")
			return false
		}
		
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
		{
			alert("The E-mail address must end in a three-letter or two letter domain. (i.e. .com or .uk)")
			return false
		}

	if (len<2) 
		{
			var errStr="This E-mail address is missing a hostname!"
			alert(errStr)
			return false
		}	
	NOERROR = "True"
	if (NOERROR = "True")
		{
			return(true)
		}  
}


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_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_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];}
}


function IM()
	{
		URL = "employ_im.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=500,WIDTH=475");
	}
function IM2()
	{
		URL = "employ_im2.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=500,WIDTH=475");
	}
function FM()
	{
		URL = "employ_fm.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=500,WIDTH=375");
	}
function SM()
	{
		URL = "employ_sm.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}
function PE()
	{
		URL = "employ_pe.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}
function PM()
	{
		URL = "employ_pm.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}
function DE()
	{
		URL = "employ_des.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}	
function CE()
	{
		URL = "employ_ce.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}
function ST()
	{
		URL = "employ_st.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}	
function MM()
	{
		URL = "employ_mm.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}	
function ET()
	{
		URL = "employ_et.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}			
function AM()
	{
		URL = "employ_am.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}			
function PS()
	{
		URL = "employ_ps.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}			
function MT()
	{
		URL = "employ_mt.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}			
function SAE()
	{
		URL = "employ_sae.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}			
function MSS()
	{
		URL = "employ_mss.php"
		window.open(URL,"Employ","scrollbars=1,HEIGHT=350,WIDTH=375");
	}
