var compDiv;
var arrPageScroll;
var arrPageSizes=new Array();

function openPopDiv(divId,frameIndex)
{
	compDiv=divId;
	centerPopup(divId);
	$('#'+divId).children('iframe').attr('src','party_menus/modal-image-template-'+frameIndex+'.html');
	loadPopup(divId);
}
function closePopDiv(divId)
{
   
	compDiv=divId;
    disablePopup(divId)
}
function loadPopup(popDiv)
{
    $("#fade").fadeIn("fast");
    $("div#"+popDiv).fadeIn("fast")
}
function disablePopup(popDiv)
{
    $("#fade").fadeOut("fast");
    $("div#"+popDiv).fadeOut("fast")
}
function centerPopup(popDiv)
{
    var windowWidth=$(document).width();
    var windowHeight=$(document).height();
    var popupHeight=$("div#"+popDiv).height();
    var popupWidth=$("div#"+popDiv).width();
    arrPageScroll=___getPageScroll();
    arrPageSizes=___getPageSize();
    $("div#"+popDiv).css({"position":"absolute","top":getScrollTop()+"px","left":windowWidth/2-popupWidth/2,"z-Index":1002});
    $("#fade").css({"height":windowHeight+popupHeight/4+50,opacity:0.7,"width":windowWidth})
}

$(document).ready(function()
{
    $("#fade").click(function(){closePopDiv(compDiv)});
    $(document).keypress(function(e){
    if(e.keyCode==27){closePopDiv(compDiv)}});
   // $(window).scroll(function(){$("#"+compDiv).stop().animate({"top":(arrPageSizes[3]/ 2 - $("#" + compDiv).height() /2+getScrollTop())+"px",opacity:1.0},500)})
});

function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}if(yScroll<windowHeight){pageHeight=windowHeight}else{pageHeight=yScroll}if(xScroll<windowWidth){pageWidth=xScroll}else{pageWidth=windowWidth}arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize};
function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft}arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll};

function getScrollTop()
{
    var ScrollTop=document.body.scrollTop;
    if(ScrollTop==0)
    {
        if(window.pageYOffset)
        ScrollTop=window.pageYOffset;
        else 
        ScrollTop=(document.body.parentElement)?document.body.parentElement.scrollTop:0;
     }
        return ScrollTop;
}

function show_hide_text(obj)
{
	if (obj.title==obj.value)
	{
		obj.value='';
	}
}

function showContactPopup()
{
	$('#Name_Popup').val($('#Name').val());
	$('#Company_Popup').val($('#Company').val());
	$('#Email_Popup').val($('#Email').val());
	$('#Phone_Popup').val($('#Phone').val());

	openPopDiv('popUp',1);
}

function sendContactDetails()
{
	
	if ($('#Name_Popup').val()=='')
	{
		alert("Name cannot be blank!");
		$('#Name_Popup').focus();
		return false;
	}
	if ($('#Email_Popup').val()=='')
	{
		alert("Email cannot be blank!");
		$('#Email_Popup').focus();
		return false;
	}
	
	var RE_EMAIL = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (!RE_EMAIL.test($('#Email_Popup').val())) {
		alert("Please enter a valid email address!");
	   $('#Email_Popup').focus();
		return false;
	   }

var data=$('#contact_form').serialize();

$.ajax({
	  type: "POST",
	  url: site_url+'contactus',
	  data: data,
	  success: function (data){
		
			$('#msg_box').html(data);
			$('#msg_box').show();
		}

	 });

}

function closeContactPopup()
{
	
		closePopDiv('popUp');
    
}
