﻿var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}


getCenterXY = function () {
    var C, D, B, A;
    if (navigator.appName != "Microsoft Internet Explorer") {
        C = window.pageXOffset;
        D = window.innerWidth;
        B = window.pageYOffset;
        A = window.innerHeight
    } else {
        C = document.body.scrollLeft;
        D = document.body.offsetWidth;
        B = document.body.scrollTop;
        A = document.body.offsetHeight
    }
    return new Array((C + C + D) / 2, (B + B + A) / 2)
};


function newcenterPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	/*var AA = $("#popupContact").height();
	var BA = $("#popupContact").width();
	var E = getCenterXY();
	alert("e1=="+E[1]+"===e0=="+E[0]+"==top=="+AA+"left"+BA);
	$("#popupContact").css({
		"position": "absolute",
		"top": (E[1]*1 - AA*1)+ "px",
		"left": (E[0]*1 - BA*1)+ "px"
	});*/
	//only need force for IE6
	var p = $("#user_txtads");
	var offset = p.offset();
	$("#popupContact").css({
		"position": "absolute",
		"top": offset.top - 200,
		"left": offset.left 
	});
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
var pre = undefined;
function change_form(element1,toemail)
{    
	if(toemail != '')
	{
		$("#agents_email").val(toemail);
	}
	if(pre != undefined)   
	{     
		$('#'+pre).hide();    
	}
	$('#'+element1).show();
	pre = element1;
	
}
