   function queryString(parameter) { 
		  var loc = location.search.substring(1, location.search.length);
		  var param_value = false;

		  var params = loc.split("&");
		  for (i=0; i<params.length;i++) {
		      param_name = params[i].substring(0,params[i].indexOf('='));
		      if (param_name == parameter) {
		          param_value = params[i].substring(params[i].indexOf('=')+1)
		      }
		  }
		  if (param_value) {
		      return param_value;
		  }
		  else {
		      return false; //Here determine return if no parameter is found
		  }
		}
function $(id){
	return document.getElementById(id);	
}

function checkEntry() {
	if(isEmpty($('email').value)){
		showErrorPopupWindow("Please enter your email address.","email");
		$('email').focus();
		return false;
	} else
	if(!checkEmail($('email').value)){
		showErrorPopupWindow("Please enter a valid email address.","email");
		$('email').focus();
		return false;
	} else
	if(isEmpty($('email2').value)){
		showErrorPopupWindow("Please re-enter your email address.","email2");
		$('email2').focus();
		return false;
	} else
	if(confirmEmail($('email').value,$('email2').value)){
		showErrorPopupWindow("Re-entered email address is not matched with your email address.","email2");
		$('email2').focus();
		return false;
	}
	if(isEmpty($('password').value)){
		showErrorPopupWindow("Please enter your password.","password");
		$('password').focus();
		return false;
	} else
	 if($('confirm_password').style.display=='none')
	 {
		 showErrorPopupWindow("Please re-enter your password.","confirm_password_text");
		$('confirm_password_text').focus();
		return false;
	 }
	 else
	if(isEmpty($('confirm_password').value)){
		showErrorPopupWindow("Please re-enter your password.","confirm_password");
		$('confirm_password').focus();
		return false;
	} 
	if(confirmPassword($('password').value,$('confirm_password').value)){
		showErrorPopupWindow("Re-entered password is not matched with your password.","confirm_password");
		$('confirm_password').focus();
		return false;
	}

	if(isEmpty($('fn').value) || $('fn').value=="First Name"){
		
		showErrorPopupWindow("Please enter your first name.","fn");
		$('fn').focus();
		return false;
	} else
	if(isEmpty($('ln').value) || $('ln').value=="Last Name"){
		showErrorPopupWindow("Please enter your last name.","ln");
		$('ln').focus();
		return false;
	} else
	if(isEmpty($('addr').value)){
		showErrorPopupWindow("Please enter your address 1.","addr");
		$('addr').focus();
		return false;
	} else
	if(isEmpty($('city').value)){
		showErrorPopupWindow("Please enter your city.","city");
		$('city').focus();
		return false;
	} else
	if(checkState($('st').value)) {
		showErrorPopupWindow("Please select your state.","st");
		$('st').focus();
		return false;	
	} else
	if(isEmpty($('zip').value)) {
		showErrorPopupWindow("Please enter your zip code.","zip");
		$('zip').focus();
		return false;
	} else
	if(!IsNumeric($('zip').value)) {
		showErrorPopupWindow("Please enter valid zip code - only numbers must be entered.","zip");
		$('zip').focus();
		return false;
	} else
	if(checkMaxLength($('zip').value,5)) {
		showErrorPopupWindow("Please enter valid zip code - 5 digits must be entered.","zip");
		$('zip').focus();
		return false;
	} else
	if(isEmpty($('ph1').value)) {
		showErrorPopupWindow("Please enter your phone number.","ph1");
		$('ph1').focus();
		return false;
	} else
	if(!IsNumeric($('ph1').value)) {
		showErrorPopupWindow("Please enter your valid phone number - only numbers must be entered.","ph1");
		$('ph1').focus();
		return false;
	} else
	if(checkMaxLength($('ph1').value,3)) {
		showErrorPopupWindow("Please enter your valid phone number - 3 digits must be entered.","ph1");
		$('ph1').focus();
		return false;
	} else
	if(isEmpty($('ph2').value)) {
		showErrorPopupWindow("Please enter your phone number.","ph2");
		$('ph2').focus();
		return false;
	} else
	if(!IsNumeric($('ph2').value)) {
		showErrorPopupWindow("Please enter your valid phone number - only numbers must be entered.","ph2");
		$('ph2').focus();
		return false;
	} else
	if(checkMaxLength($('ph2').value,3)) {
		showErrorPopupWindow("Please enter your valid phone number - 3 digits must be entered.","ph2");
		$('ph2').focus();
		return false;
	} else
	if(isEmpty($('ph3').value)) {
		showErrorPopupWindow("Please enter your phone number.","ph3");
		$('ph3').focus();
		return false;
	} else
	if(!IsNumeric($('ph3').value)) {
		showErrorPopupWindow("Please enter your valid phone number - only numbers must be entered.","ph3");
		$('ph3').focus();
		return false;
	} else
	if(checkMaxLength($('ph3').value,4)) {
		showErrorPopupWindow("Please enter your valid phone number - 4 digits must be entered.","ph3");
		$('ph3').focus();
		return false;
	} else
	if(checkDOB($('month').value)) {
		showErrorPopupWindow("Please select a month.","month");
		$('month').focus();
		return false;	
	} else
	if(checkDOB($('date').value)) {
		showErrorPopupWindow("Please select a day.","date");
		$('date').focus();
		return false;	
	} else
	if(checkDOB($('year').value)) {
		showErrorPopupWindow("Please select a year.","year");
		$('year').focus();
		return false;	
	} else
	if(ageValidation()!=null) {
		showErrorPopupWindow("You must be 18 years old to enter.","year");
		return false;
	}
	if(isEmpty($('captcha').value)){
		showErrorPopupWindow("Please enter the code.","captcha");
		$('captcha').focus();
		return false;
	}
	return true;
}

function checkLogin() {
	if(isEmpty($('email').value)){
		showErrorPopupWindow("Please enter your email address.","email");
		$('email').focus();
		return false;
	} else
	if(!checkEmail($('email').value)){
		showErrorPopupWindow("Please enter a valid email address.","email");
		$('email').focus();
		return false;
	} else
	if(isEmpty($('password').value)){
		showErrorPopupWindow("Please enter your password.","password");
		$('password').focus();
		return false;
	}
	return true;
}

function checkForgotPassword() {
	if(isEmpty($('email').value)){
		showErrorPopupWindow("Please enter your email address.","email");
		$('email').focus();
		return false;
	} else
	if(!checkEmail($('email').value)){
		showErrorPopupWindow("Please enter a valid email address.","email");
		$('email').focus();
		return false;
	}
	return true;
}

function createErrorPopup(errorMsg){
	var errorPopup = '';
	errorPopup += '<div class="errorPopupDivBg">';
	errorPopup += '<div class="errorInnerDiv">';
	errorPopup += '<p class="font-size11 closeDiv rt"><a href="javascript:void(0)" title="" style="color:#666666;" class="closeLink colorClose" onclick="closeErrorPopupWindow()">Close&nbsp;</a><a href="javascript:void(0)" title="" onclick="closeErrorPopupWindow()"><img src="images/close.png" width="12" height="12" alt="" align="absbottom" /></a></p>';
	errorPopup += '<div class="clear"></div>';
	errorPopup += '<table cellpadding="0" cellspacing="0" border="0">'; 	
	errorPopup += '<tr>';
	errorPopup += '<td align="left" valign="middle" height="115" width="350">';
	errorPopup += '<p class="font_size12">'+errorMsg+'</p>';	
	errorPopup += '</td>';
	errorPopup += '</tr>';
	errorPopup += '</table>';							
	errorPopup += '</div>';
	errorPopup += '</div>';
	return errorPopup;
}

var curFieldId = "";
function showErrorPopupWindow(errorMsg,cur_field_id){
	curFieldId = cur_field_id;
	$("errorPopupDiv").innerHTML = createErrorPopup(errorMsg);
	$("errorPopupDiv").style.display = "block";
}

function closeErrorPopupWindow(){
	$("errorPopupDiv").style.display = "none";
	$(curFieldId).focus();
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=false;
	var Char;
	
	if(sText!=''){
		IsNumber=true;
		for (i = 0; i < sText.length; i++) 
		{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
				break;
			}
		}
	}
	return IsNumber;
}
function isEmpty(field) {
	return (field.length == 0);
}

function confirmEmail(email,conf_email){
	if(email==conf_email){
		return false;
	}
	return true;
}

function confirmPassword(pwd,conf_pwd){
	if(pwd==conf_pwd){
		return false;
	}
	return true;	
}

function checkEmail(e) {
	if(e.value==''){
		return false;
	}else{
		var filter = /^[A-Za-z0-9][A-Za-z0-9\_\-\.]*\@[A-Za-z0-9][A-Za-z0-9\_\-\.]*\.[A-Za-z]{2,}$/;
		var filter2 = /(\.\.+)|(\@\@+)|(\_\_+)|(\-\-+)/;
		var filter3 = /(\.ac|\.ad|\.ae|\.aero|\.af|\.ag|\.ai|\.al|\.am|\.an|\.ao|\.aq|\.ar|\.arpa|\.as|\.at|\.au|\.aw|\.ax|\.az|\.ba|\.bb|\.bd|\.be|\.bf|\.bg|\.bh|\.bi|\.biz|\.bj|\.bm|\.bn|\.bo|\.br|\.bs|\.bt|\.bv|\.bw|\.by|\.bz|\.ca|\.cat|\.cc|\.cd|\.cf|\.cg|\.ch|\.ci|\.ck|\.cl|\.cm|\.cn|\.co|\.com|\.coop|\.cr|\.cu|\.cv|\.cx|\.cy|\.cz|\.de|\.dj|\.dk|\.dm|\.do|\.dz|\.ec|\.edu|\.ee|\.eg|\.er|\.es|\.et|\.eu|\.fi|\.fj|\.fk|\.fm|\.fo|\.fr|\.ga|\.gb|\.gd|\.ge|\.gf|\.gg|\.gh|\.gi|\.gl|\.gm|\.gn|\.gov|\.gp|\.gq|\.gr|\.gs|\.gt|\.gu|\.gw|\.gy|\.hk|\.hm|\.hn|\.hr|\.ht|\.hu|\.id|\.ie|\.il|\.im|\.in|\.info|\.int|\.io|\.iq|\.ir|\.is|\.it|\.je|\.jm|\.jo|\.jobs|\.jp|\.ke|\.kg|\.kh|\.ki|\.km|\.kn|\.kr|\.kw|\.ky|\.kz|\.la|\.lb|\.lc|\.li|\.lk|\.lr|\.ls|\.lt|\.lu|\.lv|\.ly|\.ma|\.mc|\.md|\.mg|\.mh|\.mil|\.mk|\.ml|\.mm|\.mn|\.mo|\.mobi|\.mp|\.mq|\.mr|\.ms|\.mt|\.mu|\.museum|\.mv|\.mw|\.mx|\.my|\.mz|\.na|\.name|\.nc|\.ne|\.net|\.nf|\.ng|\.ni|\.nl|\.no|\.np|\.nr|\.nu|\.nz|\.om|\.org|\.pa|\.pe|\.pf|\.pg|\.ph|\.pk|\.pl|\.pm|\.pn|\.pr|\.pro|\.ps|\.pt|\.pw|\.py|\.qa|\.re|\.ro|\.ru|\.rw|\.sa|\.sb|\.sc|\.sd|\.se|\.sg|\.sh|\.si|\.sj|\.sk|\.sl|\.sm|\.sn|\.so|\.sr|\.st|\.su|\.sv|\.sy|\.sz|\.tc|\.td|\.tel|\.tf|\.tg|\.th|\.tj|\.tk|\.tl|\.tm|\.tn|\.to|\.tp|\.tr|\.travel|\.tt|\.tv|\.tw|\.tz|\.ua|\.ug|\.uk|\.um|\.us|\.uy|\.uz|\.va|\.vc|\.ve|\.vg|\.vi|\.vn|\.vu|\.wf|\.ws|\.ye|\.yt|\.yu|\.za|\.zm|\.zw)$/i;

		if( (!filter.test( e )) ) {
			return false;
		}
		if( filter2.test( e )){
			return false;
		}
		if( !filter3.test( e )){
			return false;
		}
	}
	return true;
}

function checkMaxLength(value,len){
	if(value.length == len)
		return false;
	else 
		return true;
}

function checkState(value){
	if(value == null || value == '' || value == 'State')
		return true;
	else 
		return false;	
}

function checkDOB(value){
	if(value == null || value == '' || value == 'Month' || value == 'Day' || value == 'Year')
		return true;
	else 
		return false;	
}

function checkMaxWords(value){
	var strArr;
	var trim_value;
	trim_value = RTrim(MTrim(LTrim(value)));
	strArr = trim_value.split(" ");
	if(strArr.length > 50){
		return true;
	}
	else{return false;}
}

function MTrim(value){
	var word_space = true;
	var trim_value = '';
	for(cnt=0;cnt<value.length;cnt++){
		if(cnt == 0 || cnt == value.length-1){
			if(value.charAt(cnt) == ' '){
				trim_value = trim_value; 
			}
			else{
				trim_value = trim_value+value.charAt(cnt);
			}
		}
		else{
			if(value.charAt(cnt) == ' '){
				if(word_space){
					trim_value = trim_value+value.charAt(cnt);			
					word_space = false;
				}
			}
			else{
				word_space = true;
				trim_value = trim_value+value.charAt(cnt);
			}
		}
	}
	return trim_value;
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

function isChecked(obj){
	if(obj.checked)
		return false;
	else
		return true;	
}

/** Vista Input Field Fix **/
function vista_InputField_Fix(){
	if (navigator.userAgent.indexOf("Windows NT 6.0") > -1) {
		var headID = document.getElementsByTagName("head")[0];         
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = 'css/vista_style.css';
		headID.appendChild(cssNode);
	}
}

function firefox3_Fix(){
	if (navigator.userAgent.indexOf("Windows NT 5.1") > -1) {
		if(navigator.userAgent.indexOf(" Firefox/3.0 ") > -1){
			document.getElementById('addr').style.width='350px';
			document.getElementById('addr2').style.width='350px';
			
			document.getElementById('st').style.width='82px';
			
			document.getElementById('zip').style.width='96px';
			
			document.getElementById('ph1').style.width='96px';
			document.getElementById('ph2').style.width='96px';
			document.getElementById('ph3').style.width='96px';
			
			document.getElementById('month').style.width='104px';
			document.getElementById('date').style.width='104px';
			document.getElementById('year').style.width='104px';
			
			document.getElementById('captchaDiv').style.width='150px';
			document.getElementById('captchaDiv').style.margin='0px 28px 0px 0px';
			
			document.getElementById('try_another').style.margin='-10px 162px 0px 0px';
		}
		else if(navigator.userAgent.indexOf(" Firefox/2.0.0.16") > -1){
			document.getElementById('addr').style.width='350px';
			document.getElementById('addr2').style.width='350px';
			
			document.getElementById('st').style.width='82px';
			
			document.getElementById('zip').style.width='96px';
			
			document.getElementById('ph1').style.width='96px';
			document.getElementById('ph2').style.width='96px';
			document.getElementById('ph3').style.width='96px';
			
			document.getElementById('month').style.width='104px';
			document.getElementById('date').style.width='104px';
			document.getElementById('year').style.width='104px';
			
			document.getElementById('captchaDiv').style.width='150px';
			document.getElementById('captchaDiv').style.margin='0px 28px 0px 0px';
			
			document.getElementById('try_another').style.margin='-10px 162px 0px 0px';
		}
		else if(navigator.userAgent.indexOf(" Firefox/3.0.19") > -1){
			document.getElementById('addr').style.width='350px';
			document.getElementById('addr2').style.width='350px';
			
			document.getElementById('st').style.width='82px';
			
			document.getElementById('zip').style.width='96px';
			
			document.getElementById('ph1').style.width='96px';
			document.getElementById('ph2').style.width='96px';
			document.getElementById('ph3').style.width='96px';
			
			document.getElementById('month').style.width='104px';
			document.getElementById('date').style.width='104px';
			document.getElementById('year').style.width='104px';
			
			document.getElementById('captchaDiv').style.width='150px';
			document.getElementById('captchaDiv').style.margin='0px 28px 0px 0px';
			
			document.getElementById('try_another').style.margin='-10px 162px 0px 0px';
		}
	}	
}

function resetVal(obj){
	var val=$(obj).value;
	if(val=='Re-enter Password')
	{
		$('confirm_password_text').style.display='none';
		$('confirm_password').style.display='';
		$('confirm_password').value='';
		$('confirm_password').focus();
	}
}

function chkDefVal(obj){
	var cpass_val=$('confirm_password').value;
//alert('test');
	if(cpass_val==''){
		$('confirm_password').value='';
		$('confirm_password').style.display='none';
		$('confirm_password_text').style.display='';
		$('confirm_password_text').value='Re-enter Password';
	}
}

//Check 18 years of age
function ageValidation() {
	
	var stop = readCookie("dob");
	if(stop && stop!='') {
    	return "You must be at least 18 years of age to enter.";
	}
	// check to make sure person didn't enter "31" for days with 30
	var monthChosen = parseInt($('month').value)+1;
	var day = $('date').value;
	var year = $('year').value;
		
	// determine if year input is a leap year
	var leapyear = false;
	if ( year % 100 == 0 ) { if (year % 400 == 0)  leapyear = true;  }
	else {if (year % 4 == 0)  leapyear = true;  }

	// if leap year and user input in day greater than 29
	if( ( day > 29) &&  leapyear  &&  monthChosen==2 )
	{  return "Please enter valid date of birth"; }

	// on a non leap year, feb still has only 28 days
	if ( ( day > 28) &&  !leapyear  &&  monthChosen==2 )
	{  return "Please enter valid date of birth"; }

	// if user chose any month with 30 days and input day greater than 31
	if ( (day > 30) && ( monthChosen==4 || monthChosen==6 || monthChosen==9 || monthChosen==11 ) )
	{  return "Please enter valid date of birth"; }

	// check if person younger than thisOld
	var thisOld = 18;
	var d = new Date();
	// 3.0 compliant:
	var thisYear = d.getYear();
	var m = d.getMonth()+1;
	var t = d.getDate();
	// accounts for netscape bug about reading the date
	if (thisYear < 1900) { thisYear = thisYear + 1900 }
	// check age if at least 18
	var error = false;
	
	if ( ( (thisYear - year == thisOld) && (monthChosen == m) && (day > t) ) ||
		( (thisYear - year == thisOld) && (monthChosen > m ) ) ||
		(thisYear - year < thisOld) )
    {		
		createCookie("dob","true",0);
    	return "You must be at least 18 years of age to enter.";
	}
	return;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

