function newImage(arg) 
{
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}



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 checkIE(){
var detect = navigator.userAgent.toLowerCase();
if(detect.indexOf("msie")>-1)  return true; else return false;
}

function validateZip(field){

	if(document.getElementById(field).value.length<=0) return false; 
	if(!fncIsNumber(document.getElementById(field).value))	return false;
return true;
}


function fncIsNumber(n_strVal) {
	var digits="1234567890.";
	if(n_strVal.length>0)
	{
	for (var i=0; i < n_strVal.length; i++)
		if (digits.indexOf(n_strVal.charAt(i)) == -1)
			return false;
	} else return false;

	return true;
}


function fncIsNumberMy(obj) {
	var digits="1234567890.";
	var n_strVal=document.getElementById(obj).value;
	if(n_strVal.length>0)
	{
	for (var i=0; i < n_strVal.length; i++)
		if (digits.indexOf(n_strVal.charAt(i)) == -1)
			return false;
	} else 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':'incs/'+script,'onSuccess':function(req)
							{ 
								var dest_div='ajaxcontainer';
								obj = document.getElementById(dest_div);
								alert(req.responseText); 
								resetForm(form);
								closepopup();closepopup2();closepopup3();
							}
					    ,'timeout':30000
					    ,'onTimeout':function(req){ getformpost(script,form); }
					  }
					);

 }



	function validateContact(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('contact_fname').value.length<=0) { errstring=errstring+'- Your Name\n'; flag=0; }
	                if(!validateEmail('contact_email')) { errstring=errstring+'- Your Email\n'; flag=0; }
	                if(document.getElementById('dept_email').selectedIndex==0) { errstring=errstring+'- Select Topic\n'; flag=0; }
                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {

                              		 getformpost("contactform.php","cform");
					 resetForm("cform");


					}
				return false;

	}

	function clearAll(){
		if(document.getElementById('tab1'))		{
		 	document.getElementById('tab1').style.display="none";
		}
	
		if(document.getElementById('tab3'))		{
		 	document.getElementById('tab3').style.display="none";


		}

		if(document.getElementById('tab5'))		{
		 	document.getElementById('tab5').style.display="none";

		}


	}

	function getTab(num){
		clearAll();
	 	document.getElementById('tab'+num).style.display="block";
	}


function validateReserve(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('reserve_fname').value.length<=0) { errstring=errstring+'- Name\n'; flag=0; }
	                if(!validateEmail('reserve_email')) { errstring=errstring+'- Your Email\n'; flag=0; }
	                if(document.getElementById('reserve_phone').value.length<=0) { errstring=errstring+'- Phone\n'; flag=0; }
//	                if(parseInt(document.getElementById('reserve_guests').value)>3 || parseInt(document.getElementById('reserve_guests').value)<1) { errstring=errstring+'- You can invite from 1 to 3 guests\n'; flag=0; }

                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {

                              		 getformpost("reservetable.php","reservetable");
					 resetForm("reservetable");
					}
				return false;
}


function checkIE(){
var detect = navigator.userAgent.toLowerCase();
if(detect.indexOf("msie")>-1)  return true; else return false;
}


	function photosGo(what){
		if(checkIE())
		document.getElementById('ajaxnav').setAttribute('src', 'ajaxframework/mock-page.php?hash=gallery-'+what);
		else document.location.href="#gallery-"+what;
	}

	function videosGo(what){
		if(checkIE())
		document.getElementById('ajaxnav').setAttribute('src', 'ajaxframework/mock-page.php?hash=video-'+what);
		else document.location.href="#video-"+what;
	}

	var wnd = null;

function open_window(page_url, wid, hei)
{
	var wnd_height = (hei) ? hei : 400;
	var wnd_width = (wid) ? wid : 600;
	var wnd_left = (screen.width - wid)/2;
	var wnd_top = (screen.height - hei)/2;
	if(wnd)
	{
		wnd = window.open(page_url, "preview_wnd", "location=no,menubar=no,personalbar=no,scrollbars=yes,status=no,toolbar=no,width="+wnd_width+",height="+wnd_height+",left="+wnd_left+",top="+wnd_top);
		wnd.focus();
	}
	else
	{
		wnd = window.open(page_url, "preview_wnd", "location=no,menubar=no,personalbar=no,scrollbars=yes,status=no,toolbar=no,width="+wnd_width+",height="+wnd_height+",left="+wnd_left+",top="+wnd_top);
	}
}



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 openPopup()
		{
		var width=350;
		var height=200;
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1]-0;
		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;

		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('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";

		}

	function closepopup2()
		{
			document.getElementById('shaded').className="shaded_hid";
			document.getElementById('infoiframe_div2').className="infoiframe_hidden";

		}

	function closepopup3()
		{
			document.getElementById('shaded').className="shaded_hid";
			document.getElementById('infoiframe_div3').className="infoiframe_hidden";

		}





	function validateShare(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('share_frname').value.length<=0) { errstring=errstring+'- Your Name\n'; flag=0; }
	                if(document.getElementById('share_fremail').value.length<=0) { errstring=errstring+'- Your Email\n'; flag=0; }

	                if(document.getElementById('share_name').value.length<=0) { errstring=errstring+'- Friend\'s Name\n'; flag=0; }
	                if(document.getElementById('share_email').value.length<=0) { errstring=errstring+'- Friend\'s Email\n'; flag=0; }
                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {

                              		 getformpost("shareprocess.php","share_form");
					}
				return false;

	}


	function validateJoin(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('join_name').value.length<=0) { errstring=errstring+'- Your Name\n'; flag=0; }
	                if(!validateEmail('join_email')) { errstring=errstring+'- Email\n'; flag=0; }
                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {
						getformpost("shareprocess.php","joinform");
					}
				return false;

	}


	function eventgo(what){
	var detect = navigator.userAgent.toLowerCase();
	if(detect.indexOf("msie")>-1) 
		document.getElementById('ajaxnav').setAttribute('src', 'ajaxframework/mock-page.php?hash=event-'+what);
	else  location.href='http://www.thedrynksoho.com/#event-'+what;
	
	}


	function homego(){
	var detect = navigator.userAgent.toLowerCase();
	if(detect.indexOf("msie")>-1) 
		document.getElementById('ajaxnav').setAttribute('src', 'ajaxframework/mock-page.php?hash=home');
	else  location.href='http://www.thedrynksoho.com/#home';
	
	}


	function validateSendPhoto(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('sp_name').value.length<=0) { errstring=errstring+'- Friend\'s Name\n'; flag=0; }
	                if(!validateEmail('sp_email')) { errstring=errstring+'- Friend\'s Email\n'; flag=0; }
                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {
						getformpost("sendphoto.php","spform");
					}
				return false;

	}


	function validateSendEvent(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('se_name').value.length<=0) { errstring=errstring+'- Friend\'s Name\n'; flag=0; }
	                if(!validateEmail('se_email')) { errstring=errstring+'- Friend\'s Email\n'; flag=0; }
                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {
						getformpost("sendevent.php","seform");
					}
				return false;

	}

	function openSend(id){
		var width=350;
		var height=200;
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1]-0;
		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;

		document.getElementById('infoiframe_div2').style.top=tp+"px";
		document.getElementById('infoiframe_div2').style.left=(getClientCenterX()-half_width)+"px";

		document.getElementById('infoiframe_div2').style.width=width+"px";
		document.getElementById('infoiframe_div2').style.height=height+"px";
	
		document.getElementById('shaded').className="shaded_vis";
		document.getElementById('infoiframe_div2').className="infoiframe_visible";

		document.getElementById('sp_id').value=id;

	}


	function openSendEvent(id,type){
		var width=350;
		var height=200;
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1]-0;
		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;

		document.getElementById('infoiframe_div3').style.top=tp+"px";
		document.getElementById('infoiframe_div3').style.left=(getClientCenterX()-half_width)+"px";

		document.getElementById('infoiframe_div3').style.width=width+"px";
		document.getElementById('infoiframe_div3').style.height=height+"px";
	
		document.getElementById('shaded').className="shaded_vis";
		document.getElementById('infoiframe_div3').className="infoiframe_visible";

		document.getElementById('se_id').value=id;
		document.getElementById('se_type').value=type;

	}


var t;

var is_image_loaded = function(img) { 
    // IE 
    if(!img.complete) { 
        return false; 
    } 
    // Others 
    if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { 
        return false; 
    } 
    return true; 
} 

//	$(".slideshow .slideshowslides").css({"display":'none'});

	function checkLoadedSlideshow(){
	var totalcount=0;
	var loadedcount=0;	

	$('.slideelement').each(function(){ totalcount+=1; });

	var slideshows=($('.slideelement').get());

	$('.slideelement').each(function(){ if(is_image_loaded($(this).get(0))) loadedcount+=1; });

	if(loadedcount==totalcount) {
		$(".slideshow .slideshowslides").css({"display":'block'});
		$(".slideshow .slideshowloader").css({"display":'none'});
	 	clearInterval(t);
		    $('.slideshowslides').cycle({
			fx: 'fade' 
		});
	}

	}

	function slideshowInit(){
	t=setInterval("checkLoadedSlideshow()",2000);
	}

