var showhide = function(id){
	if($('#'+id).is(':hidden')){
		show(id);
	} else {
		hide(id);
	}
	return false;
}

var show = function(id){
		if($('#'+id).is(':hidden')){
			$('#'+id).show('normal');
		}
    return false;
} 


var hide = function(id){
		if($('#'+id).is(':visible')){
			$('#'+id).hide('slow');
		}
    return false;
} 


function redirect(url){
	window.location=url;
}


function roll(img_name, img_src){
	if (document[img_name]){
	document[img_name].src = img_src;
	}
}


function focusIt(id){
  var mytext = document.getElementById(id);
  mytext.focus();
}

function enable(id) {
       var e = document.getElementById(id);
       e.disabled=false;   
}

function disable(id) {
       var e = document.getElementById(id);
       e.disabled=true;   
}

 function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }

function unCheck(Form, Name){
	document.forms[Form].elements[Name].checked = false;
}

function Check(Form, Name){
	document.forms[Form].elements[Name].checked = true;
}

function fill(object,value){
	document.getElementById(object).value = value;
	document.getElementById(object).focus(); 
} 

function jumpToAnchor(anchor) {
	window.location = String(window.location).replace(/\#.*$/, "") + "#" + anchor;
}

function jumpToDiv(object) {
  x = document.getElementById(object);
  h= x.clientHeight;
  self.scrollTo(0,h);
}



function checkEmail(emailStr){

	var checkTLD=1; // boolean to check TLD

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;  // This the list of known TLDs that an e-mail address must end with.

	var emailPat=/^(.+)@(.+)$/; // user@domain regexp

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";  // forbidden characters

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; // joe@[123.124.233.4] is a legale-mail address. NOTE: The square brackets are required.

	var atom=validChars + '+'; // The following string represents an atom (basically a series of non-special characters.)

	var word="(" + atom + "|" + quotedUser + ")"; // The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string.

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); // The following pattern describes the structure of the user

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); // The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above.



	var matchArray=emailStr.match(emailPat); // Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze.

	if (matchArray==null){ // Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address.

		return false;

	}

	var user=matchArray[1];

	var domain=matchArray[2];

	for (i=0; i<user.length; i++) { // Start by checking that only basic ASCII characters are in the strings (0-127).

		if (user.charCodeAt(i)>127) {

			return false;

 		  }

	}

	for (i=0; i<domain.length; i++) {

		if (domain.charCodeAt(i)>127) {

			return false;

	   }

	}

	if (user.match(userPat)==null) { // See if "user" is valid 

		return false;

	}

	var IPArray=domain.match(ipDomainPat); // See if ip address is valid 

	if (IPArray!=null) {

		for (var i=1;i<=4;i++) {

			if (IPArray[i]>255) {

				return false;

		   }

		}

		return true;

	}

	var atomPat=new RegExp("^" + atom + "$");

	var domArr=domain.split(".");

	var len=domArr.length;

	for (i=0;i<len;i++) {

		if (domArr[i].search(atomPat)==-1) {

			return false;

	   }

	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {

		return false;

	}

	if (len<2) {

		return false;

	}

	return true;

}




function validate(form) {

	var words = /\w/;


	if (form.name == 'blog_comment') {

		if (!words.test(form.login.value)) {
	 		jAlert('Please enter in your name', 'Error', function(r) {
		 		if(r){
		         form.login.focus();
		 		}
			}); 
			return false;
		}

		if (!words.test(form.comment.value)) {
	 		jAlert('Please enter in your comment', 'Error', function(r) {
		 		if(r){
		         form.comment.focus();
		 		}
			}); 
			return false;
		}

		/* if security code exists */
		if (form.security_code != 'undefined' && !words.test(form.security_code.value)) {
	 		jAlert('Please enter security code', 'Error', function(r) {
		 		if(r){
		         form.security_code.focus();
		 		}
			}); 
			return false;
		}
		/* END */

	}



	if (form.name == 'rsvpform') {

		if (!words.test(form.fname.value)) {
	 		jAlert('Please enter in your first name', 'Error', function(r) {
		 		if(r){
		         form.fname.focus();
		 		}
			}); 
			return false;
		}
		
		if (!words.test(form.lname.value)) {
	 		jAlert('Please enter in your last name', 'Error', function(r) {
		 		if(r){
		         form.lname.focus();
		 		}
			}); 
			return false;
		}
	
		if (!checkEmail(form.emailaddress.value)) {
	 		jAlert('Please enter in a valid email address', 'Error', function(r) {
		 		if(r){
		         form.emailaddress.focus();
		 		}
			}); 
			return false;
		}

		/* if security code exists */
		if (form.security_code != 'undefined' && !words.test(form.security_code.value)) {
	 		jAlert('Please enter security code', 'Error', function(r) {
		 		if(r){
		         form.security_code.focus();
		 		}
			}); 
			return false;
		}
		/* END */

	}



	if (form.name == 'quickreg') {

	//Check Email
		if (!checkEmail(form.email.value)) {
 		jAlert('Please enter in a valid email address', 'Error', function(r) {
	 		if(r){
	         form.email.focus();
	 		}
		}); 
		return false;
		}
	//END


	//Check zipcode
		if (document.getElementById('signup_02') && isNaN(form.zipcode.value)) {
 		jAlert('Please enter in a valid zip code', 'Error', function(r) {
	 		if(r){
	         form.zipcode.focus();
	 		}
		}); 

		return false;
		}
	//END


	//Check First Name
		if (document.getElementById('signup_03') && form.fname.value=='') {
 		jAlert('Please enter in your first name', 'Error', function(r) {
	 		if(r){
	         form.fname.focus();
	 		}
		}); 

		return false;
		}
	//END


	//Check Last Name
		if (document.getElementById('signup_04') && form.lname.value=='') {
 		jAlert('Please enter in your last name', 'Error', function(r) {
	 		if(r){
	         form.lname.focus();
	 		}
		}); 

		return false;
		}
	//END

	//Check City
		if (document.getElementById('signup_05') && form.city.value=='') {
 		jAlert('Please enter in your city', 'Error', function(r) {
	 		if(r){
	         form.city.focus();
	 		}
		}); 

		return false;
		}
	//END


	}


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

/* Jquery Dialog Box */

var showPopUp = function(el,el_width,el_height,el_left,el_top){
	$('#'+el).show('slow');
	$("#cover").show();

	var dlg = document.getElementById(el);
	var cvr = document.getElementById('cover');

	dlg.style.position="absolute";
	dlg.style.zIndex="50";
	dlg.style.background="#ffffff";
	dlg.style.left="280px";
	dlg.style.top=el_top+"px";
	dlg.style.width=el_width+"px";
	dlg.style.height=el_height+"px";

	cvr.style.display = "block";
	cvr.style.position="fixed";
	cvr.style.width="100%";
	cvr.style.height="100%";
	cvr.style.left="0px";
	cvr.style.top="0px";
	cvr.style.background="rgb(255, 255, 255)";
	cvr.style.opacity="0.01";


	scroll(0,0); // Hack to roll page to top it must be done.
	
  return false;
} 


var closePopUp = function(el,refresh){
	$('#'+el).hide('slow');
	$("#cover").hide();
	$("#cover").height($(document).height());


	if(refresh=='undefined'){
		window.location.reload();
	}
	if(refresh=='yes'){
		window.location.reload();
	}

	return false;
}


function popup(url) {
	    winName = "details";
        options = 'width=500, height=350, resizable=yes, scrollbars=yes';
        newWin = window.open(url, winName, options);
        newWin.focus();
}


/* Used on popup window */
function resizeWin(windowHeight,windowWidth){

    if (!windowHeight) {   this.windowHeight = 400;   } else { this.windowHeight = windowHeight; }
    if (!windowWidth) {   this.windowWidth = 300;    } else { this.windowWidth = windowWidth; }
		
		window.resizeTo(this.windowHeight,this.windowWidth);
		window.focus();

		var centerWidth = (window.opener.screen.width - this.windowWidth) / 2;
		var centerHeight = (window.opener.screen.height - this.windowHeight) / 2;
}
/ * END */

