sfHover = function() {
	var sfEls = document.getElementById("tabsnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}

consultHover = function() {
	if(document.getElementById("consulting")){
		var sfEls = document.getElementById("consulting").getElementsByTagName("p");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" hover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" hover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", consultHover);

supportHover = function() {
    if(document.getElementById("support")){
	var sfEls = document.getElementById("support").getElementsByTagName("p");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
	}
}
if (window.attachEvent) window.attachEvent("onload", supportHover);

trainHover = function() {
	if(document.getElementById("training")){
	var sfEls = document.getElementById("training").getElementsByTagName("p");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
	}
}
if (window.attachEvent) window.attachEvent("onload", trainHover);

newsHover = function() {
	if(document.getElementById("newsletter")){
	var sfEls = document.getElementById("newsletter").getElementsByTagName("p");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
	}
}





function validate() {
	var d = document.purchase_form;
	if ( isWhitespace(d.first_name.value) )
	{
		alert ("Must Enter a Name");
		return false;
	}
	else if ( isWhitespace(d.last_name.value) )
	{
		alert ("Must Enter a Name");
		return false;
	}
	else if ( isWhitespace(d.company_name.value) )
	{
		alert ("Must Enter a Company Name");
		return false;
	}
	else if ( isWhitespace(d.street1.value) )
	{
		alert ("Must Enter an Address");
		return false;
	}
	else if ( isWhitespace(d.city.value) )
	{
		alert ("Must Enter a City");
		return false;
	}
	else if ( isWhitespace(d.state.value) )
	{
		alert ("Must Enter a State");
		return false;
	}
	else if ( isWhitespace(d.zipcode.value) )
	{
		alert ("Must Enter a ZipCode");
		return false;
	}
	else if ( isWhitespace(d.country.value) )
	{
		alert ("Must Enter a Country");
		return false;
	}
	else if ( isWhitespace(d.work_phone.value) )
	{
		alert ("Must Enter a Phone Number");
		return false;
	}
	else if ( isWhitespace(d.email.value) )
	{
		alert ("Must Enter an Email Address");
		return false;
	}
	else if ( isWhitespace(d.cc_first_name.value) )
	{
		alert ("Must Enter a Credit Card First Name");
		return false;
	}
	else if ( isWhitespace(d.cc_last_name.value) )
	{
		alert ("Must Enter a Credit Card Last Name");
		return false;
	}
	else if ( isWhitespace(d.cc_method.value) )
	{
		alert ("Must Enter a Credit Card Method");
		return false;
	}
	else if ( isWhitespace(d.cc_number.value) )
	{
		alert ("Must Enter a Credit Card Number");
		return false;
	}
	else if ( isWhitespace(d.cc_exp_month.value) )
	{
		alert ("Must Enter a Credit Card Epx Month");
		return false;
	}
	else if ( isWhitespace(d.cc_exp_year.value) )
	{
		alert ("Must Enter a Credit Card Exp Year");
		return false;
	}
	else if ( d.tos.checked == false )
	{
			alert ("Must Agree to the EpikOne Terms and Conditions");
			return false;
	}
	else
	{
			return true;
	}

}

var acceptStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_- ";
var numStr = "1234567890.";
var intStr = "1234567890";
var nameStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'-.,` ";
var alphaStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var alphanumericStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

function formError( f, msg, elName )
{
	alert( msg );
	if ( f.elements[elName].length > 1 )
		f.elements[elName][0].focus();
	else
		f.elements[elName].focus();		
	return false;		
}

function isAlphaNumericNoDash( str )
{
	var i;
	var result = true;
	for ( i=0 ; i<str.length ; i++ )
		if ( alphanumericStr.indexOf( str.charAt( i ) ) == -1 )
			result = false;
	return result;	
}

function isAlphaNumeric( str )
{
	var i;
	var result = true;
	for ( i=0 ; i<str.length ; i++ )
		if ( acceptStr.indexOf( str.charAt( i ) ) == -1 )
			result = false;
	return result;	
}

function isAlphabetic( str )
{
	var i;
	var result = true;
	for ( i=0 ; i<str.length ; i++ )
		if ( alphaStr.indexOf( str.charAt( i ) ) == -1 )
			result = false;
	return result;	
}

function isNumber( str )
{
	var i;
	//if ( str.charAt(0) == "-" )
		//str = str.substr(1);
	for ( i=0; i<str.length; i++ )
		if ( isNaN(parseInt(str.charAt(i))) )
			return false;
	return true;
}

function isNumeric( str )
{
	var i;
	var i;
	var result = true;
	var dotCount = 0;
	for ( i=0 ; i<str.length ; i++ )
	{
		if ( numStr.indexOf( str.charAt( i ) ) == -1 )
			result = false;
		if ( str.charAt( i ) == '.' )
			dotCount++; 
	}
	if ( dotCount > 1 )
		result = false;
	return result;		
}

function isInteger( str )
{
	var i;
	var i;
	var result = true;
	var dotCount = 0;
	for ( i=0 ; i<str.length ; i++ )
	{
		if ( intStr.indexOf( str.charAt( i ) ) == -1 )
			result = false;
	}
	return result;		
}

// Check whether string s is empty.
function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or whitespace characters only.
function isWhitespace(s)
{   
	var i;
	var whitespace = " \t\n\r";
	if (isEmpty(s)) return true;
	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.
	for (i = 0; i < s.length; i++)
	{
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	// All characters are whitespace.
	return true;
}

// Email address must be of form a@b.c 
// Rules are:
// - there must be at least one character before the @
// - there must be at least one character before and after the .
// - the characters @ and . are both required
function isEmail(str)
{   
	if (isEmpty(str)) return false;
	if (isWhitespace(str)) return false;
	// there must be >= 1 character before @, so we
	// start looking at character position 1 (i.e. second character)
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	    return false
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	}
	
	if (str.indexOf(dot,(lat+2))==-1){
	    return false
	}
	
	if (str.indexOf(" ")!=-1){
	    return false
	}
	
	return true					
}

function isPassword(strPassword, strUserid)
{
	var i;
	var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@$^*()-_+={}[]:;<>,.";
	var alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var numbers = "1234567890";
	var specialChars = "!@$^*()-_+={}[]:;<>,.";
	var alphabetsFound = false;
	var numbersFound = false;
	var specialCharsFound = false;

	// Make sure the password does not contain the UserID.
	if ((strPassword.toLowerCase()).indexOf((strUserid.toLowerCase())) >= 0)
	{
		alert("Password cannot contain the UserID.");
		return false;
	}
	
	// Check for length of characters in the password.
	if (strPassword.length < 7 || strPassword.length > 50)
	{
		alert("Please enter between 7 and 50 characters for the password.");
		return false;
	} 
	
	// Check each character against the valid characters.  If a char is not found it is invalid.
	for (i = 0; i < strPassword.length; i++)
	{
		var c = strPassword.charAt(i);
		if (validChars.indexOf(c) == -1)
		{ 
			alert("Password cannot contain character: " + c);
			return false;
		}
	}
	
	// Make sure the password is comprised of letters and at least one number or one special charecter.
	for (i = 0; i < strPassword.length; i++)
	{
		var c = strPassword.charAt(i);
		if (alphabets.indexOf(c) >= 0)
		{
			alphabetsFound = true;
			break;
		}
	}
	
	for (i = 0; i < strPassword.length; i++)
	{
		var c = strPassword.charAt(i);
		if (numbers.indexOf(c) >= 0)
		{
			numbersFound = true;
			break;
		}
	}
	
	for (i = 0; i < strPassword.length; i++)
	{
		var c = strPassword.charAt(i);
		if (specialChars.indexOf(c) >= 0)
		{
			specialCharsFound = true;
			break;
		}
	}
	
	if (!(alphabetsFound == true && (numbersFound == true || specialCharsFound == true)))
	{
		alert("Password must be comprised of letters and at least one number or one special character.");
		return false;
	}
	
	return true;
}

// Returns true if string s is a valid Year number.  Must be 4 digits.
function IsYear(s)
{   
	var i;
	var validChars = "1234567890";
	
    // Verify that year is all digits
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (validChars.indexOf(c) == -1) return false;
	}
	
	return (s.length == 4);
}

function isDate( str )
{
	var inputStr = str;
	var delim1;
	var delim2;
	var mm;
	var dd;
	var yyyy;	
	var numdelim;
	var validcharresult = true;
	
	// First check for allowed numbers and characters
	for ( i=0 ; i<str.length ; i++ )
		if ( dateStr.indexOf( str.charAt( i ) ) == -1 )
			validcharresult = false;
	if (! validcharresult) {
		alert("The date entry is not in an acceptable format.\nPlease enter dates in the following format:  mm/dd/yyyy.");
		return false;
	}
			
	// Check if there are more than two delimiters
	numdelim = 0;
	for ( i=0 ; i<str.length ; i++ )
		if ( "/".indexOf( str.charAt( i ) ) > -1 )
			numdelim++;
			
	if (numdelim > 2) {
		// There are more than two delimiters
		alert("The date entry is not in an acceptable format.\nPlease enter dates in the following format:  mm/dd/yyyy.");
		return false;
	}

	delim1 = inputStr.indexOf("/");
	delim2 = inputStr.lastIndexOf("/");

	if (delim1 != -1 && delim1 == delim2) {
		// There is only one delimiter in the string
		alert("The date entry is not in an acceptable format.\nPlease enter dates in the following format:  mm/dd/yyyy.");
		return false;
	}

	if (delim1 != -1) {
		// There are delimiters - extract month, day, and year component values and discard delimiters.
		mm = parseInt(inputStr.substring(0, delim1), 10);
		dd = parseInt(inputStr.substring(delim1 + 1, delim2), 10);
		yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length), 10);
	}
	else {
		// There are no delimiters.
		alert("The date entry is not in an acceptable format.\nPlease enter dates in the following format:  mm/dd/yyyy.");
		return false;		
	}

	if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {
		// There is a non-numeric character in one of the component values.
		alert("The date entry is not in an acceptable format.\nPlease enter dates in the following format:  mm/dd/yyyy.");
		return false;
	}
	
	if (mm < 1 || mm > 12) {
		// Month value is not 1 thru 12
		alert("Months must be entered between the range of 01 (January) and 12 (December).");
		return false;
	}
	
	if (dd < 1 || dd > 31) {
		// Date value is not 1 thru 31
		alert("Days must be entered between the range of 01 and a maximum of 31 (depending on the month and year).");
		return false;
	}
	
	if (yyyy < 100) {
		// Year value is two digits
		alert("The date entry is not in an acceptable format.\nPlease enter dates in the following format:  mm/dd/yyyy.");
		return false;
	}
	
	if (!checkMonthLength(mm, dd)) {
		return false;
	}
	if (mm == 2) {
		if (!checkLeapMonth(mm, dd, yyyy)) {
			return false;
		}
	}
	
	return true;
}

function logout()
{
	document.cookie = "msd=0";
	this.location.href="msdlogin.php";
}

function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
  }

function popwin(URL,name,width,height) {
   HorizPos = 0;
   VertPos = 0;
   if(screen){
	   HorizPos = (screen.width-width) / 2;
	   VertPos = (screen.height-height) / 2;
   }
   varPopupWin=window.open(URL, name,'width='+width+',height='+height+',left='+HorizPos+',top='+VertPos+',scrollbars=yes,toolbar=no,menubar=no,resizeable=no');
   varPopupWin.focus(); 
}

function validterms(){
	if(document.urchin5.urchinterms.checked && document.urchin5.epikterms.checked){
		return true;
	}else{
		
		if(!document.urchin5.urchinterms.checked){
			alert("Please make sure you have read and accepted the Urchin Terms of Service");
		}else 	if(!document.urchin5.epikterms.checked){
			alert("Please make sure you have read and accepted the EpikOneTerms of Service");
		}
				
		return false;
	}

}



