function validateEmail(field){
	var emailReg = "^[a-z|0-9]+([\-|_|\.]?[a-z|0-9|_]+)*@[a-z|0-9]+([\-|\.]+[a-z|0-9]+)+$";
	var regex = new RegExp(emailReg);
	if (!regex.test(document.getElementById(field).value.toLowerCase()))
	{
		return false;
	}					
return true;
}


function getRequestBody(oForm) { 
     var aParams = new Array();
     for(var i = 0; i < oForm.elements.length; i++) {
         var sParam = encodeURIComponent(oForm.elements[i].name);
         sParam += "=";
         sParam += encodeURIComponent(oForm.elements[i].value);
         aParams.push(sParam);
     }
     return aParams.join("&");
 }

function resetForm(formid){
document.getElementById(formid).reset();
}



 function getformpost(script,form) {
         
         var nameRequestForm = document.getElementById(form);
         var post_arg = getRequestBody(nameRequestForm);
         
					AjaxRequest.post(
					  {
					    'queryString': post_arg,
					    'url':''+script+'','onSuccess':function(req)
							{ 
//								var dest_div='ajaxcontainer';
//								obj = document.getElementById(dest_div);
								alert(req.responseText); 
								closepopup();
							}
					    ,'timeout':30000
					    ,'onTimeout':function(req){ getformpost(script,form); }
					  }
					);

 }


function checkEmail(){
                var errstring='';
                var flag=1;

			if(!validateEmail('email')) { errstring=errstring+'- Email\n'; flag=0; }

                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {
                              		 getformpost("incs/newsletter.process.php",'newsletter');
					 resetForm('newsletter');
				}
				return false;
}



	function photosgo(what){
		if(checkIE())
		document.getElementById('ajaxnav').setAttribute('src', 'ajaxframework/mock-page.php?hash=photos-'+what);
		else document.location.href="#photos-"+what;
	}

function checkIE(){
var detect = navigator.userAgent.toLowerCase();
if(detect.indexOf("msie")>-1)  return true; else return false;
}



function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getClientCenterX()
{
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1];
		var wid=document.body.scrollWidth;

	return parseInt(wid/2);
}

function getClientCenterY()
{
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1];
		var wid=document.body.scrollWidth;

	return parseInt(hei/2)+getBodyScrollTop();
}



	function openSubmit()
		{
		var width=800;
		var height=660;
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1]-4;
		var wid=document.body.scrollWidth;

		var half_width=width/2;
		var half_height=height/2;

		document.getElementById('shaded').style.height=hei+"px";
		document.getElementById('shaded').style.width=wid+"px";

		if((getClientCenterY()-half_height)>0) var tp=getClientCenterY()-half_height-60; else var tp=10;
		tp=100;

		document.getElementById('infoiframe_div').style.top=tp+"px";
		document.getElementById('infoiframe_div').style.left=(getClientCenterX()-half_width)+"px";

		document.getElementById('infoiframe_div').style.width=width+"px";
		document.getElementById('infoiframe_div').style.height=height+"px";

		document.getElementById('iframedoc').src="submit.event.php";
	
		document.getElementById('shaded').className="shaded_vis";
		document.getElementById('infoiframe_div').className="infoiframe_visible";
		}


	function closepopup()
		{
			document.getElementById('shaded').className="shaded_hid";
			document.getElementById('infoiframe_div').className="infoiframe_hidden";

		}

