
// check input of search box
function checkSearch() {
	reSearch = /^.{2,}/;
	if (reSearch.test(window.document.SearchHudson.searchCriteria.value)) {
		reSearch2 = /.*Search Hudson.*/;
		reSearch3 = /^[ ]+$/;
		if (reSearch2.test(window.document.SearchHudson.searchCriteria.value)) {
			valid = 0;
		} else if (reSearch3.test(window.document.SearchHudson.searchCriteria.value)) {
			valid = 0;
		} else {
			valid = 1;
		}
	} else {
		valid = 0;
	}

	if (valid == 0) {
		alert('You must enter valid search criteria');
		window.document.SearchHudson.searchCriteria.focus();
		window.document.SearchHudson.searchCriteria.select();
		return false;
	} else {
		return true;
	}
}
// check input of search box



function PrintThisPage() 
{
   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=700,height=600,left=50,top=25"; 

   var sWinHTML = document.getElementById('bContent').innerHTML;

   
   var winprint=window.open("","",sOption); 
       winprint.document.open();
       winprint.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">');
       winprint.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>hudson.org</title><link rel="Stylesheet" type="text/css" href="/css/printPage.css"></head><body><p><img src="/images/logo.gif" alt="" ></p>');
       winprint.document.write(sWinHTML);          
       winprint.document.write('<p class="copyRight">&copy;Copyright '+ new Date().getFullYear() +' Hudson Institute. All Rights Reserved</p></body></html>');
      // winprint.document.close();
       winprint.focus(); 
}




function MM_openPrintWindow(theURL,winName,features) { //v2.0
						  myWindow = window.open(theURL,winName,features);
						  this.focus();
						}
						
	function openWindow(theURL,winName,features) { //v2.0
						  myWindow = window.open(theURL,winName,features);
						  
						}					
						
						function MM_openEmailWindow(theURL,winName,features) { //v2.0
						  myWindow = window.open(theURL,winName,features);
						  myWindow.focus();
						}
						
						
						
						
						
function SameAs() {
	if (document.coform.SameAsShipping.checked) {
		document.coform.bill_first_name.value = document.coform.first_name.value;
		document.coform.bill_last_name.value = document.coform.last_name.value;
		document.coform.bill_address1.value = document.coform.address1.value;
		document.coform.bill_address2.value = document.coform.address2.value;
		document.coform.bill_city.value = document.coform.city.value;
		document.coform.bill_state.value = document.coform.state.value;
		document.coform.bill_zip.value = document.coform.zip.value;
		document.coform.bill_country.value = document.coform.country.value;
		document.coform.bill_phone.value = document.coform.phone.value;
		document.coform.bill_email.value = document.coform.email.value;
	}
	else {
		document.coform.bill_first_name.value = "";
		document.coform.bill_last_name.value = "";
		document.coform.bill_address1.value = "";
		document.coform.bill_address2.value = "";
		document.coform.bill_city.value = "";
		document.coform.bill_state.value = "";
		document.coform.bill_zip.value = "";
		document.coform.bill_country.value = "";
		document.coform.bill_phone.value = "";
		document.coform.bill_email.value = "";
	}
}

function isEmail(str) {
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) {
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	} else {
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		return (!r1.test(str) && r2.test(str));
	}
}

function checkinteger(object_value)
{
    if (object_value.length == 0)
        return true;
    
	var decimal_format = ".";
	var check_char;
    
	check_char = object_value.indexOf(decimal_format)
    
    if (check_char < 1)
		return checknumber(object_value);
    else
		return false;
}

function checknumber(object_value)
{
    if (object_value.length == 0)
        return true;
    
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
    
	check_char = start_format.indexOf(object_value.charAt(0))
    
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;

	for (var i = 1; i < object_value.length; i++) {
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1) {
			if (decimal)		
				return false;
			else
				decimal = true;
		} 
		else if (check_char == 0) {
			if (decimal || digits)	
				trailing_blank = true;
		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    return true
}

function checkcreditcard(object_value)
{
	var white_space = " -";
	var creditcard_string="";
	var check_char;

    if (object_value.length == 0)
        return true;

	for (var i = 0; i < object_value.length; i++) {
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}
	
    if (creditcard_string.length == 0) return false;
	if (creditcard_string.charAt(0) == "+") return false;
	if (!checkinteger(creditcard_string)) return false;
	
	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i))

		if (doubledigit) {
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0) {
				checkdigit++;
			}
			doubledigit = false;
		}
		else {
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;
}


