var popupStat = 0;

function show_message(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#message-send-friend").height();
	var popupWidth = jQuery("#message-send-friend").width();

	jQuery("#message-send-friend").css({
		"position": "fixed",
		"top": windowHeight/3-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"z-index":"9999"
	});
	setTimeout(function(){ jQuery('#message-send-friend').fadeIn("slow"); }, 2000);
	setTimeout(function(){ jQuery('#message-send-friend').fadeOut("slow"); }, 5000);

	
}

function loadvote(){
	//loads popup only if it is disabled
	if(popupStat==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#votepopup").fadeIn("slow");
		popupStat = 1;
	}
}

//disabling popup with jQuery magic!
function disablevote(){
	//disables popup only if it is enabled
	if(popupStat==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#votepopup").fadeOut("slow");
		popupStat = 0;
	}
}

//centering popup
function centervote(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#votepopup").height();
	var popupWidth = jQuery("#votepopup").width();
	//centering
	jQuery("#votepopup").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"z-index":"9999"
	});
	//only need force for IE6
	
	
	
}


//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	jQuery("#subm_form").click(function(){
		centervote();
		loadvote();
	jQuery.ajax({
	type: "POST",
	url: "/wp-content/themes/opinion/op_vote.php",
	data: "id=1",
	cache: false,
	success: function(html)
	{
	jQuery('#votepopup p#opinions').html(html);
	}
	});
	
/*	
	jQuery("#popupvotesave").click(function(){

		var ask_name = jQuery("#ask_name").val();
		var ask_phone = jQuery("#ask_phone").val();
		var ask_prod = jQuery("#ask_prod").val();
		var ask_url = jQuery("#ask_url").val();
		var ask_redirect = jQuery("#ask_redirect").val();
		//var friend_name = jQuery("#friend_name").val();
		//var friend_email = jQuery("#friend_email").val();
		//var your_message = jQuery("#your_message").val();
		//var url = jQuery("#url").val();
		//alert (ask_url);
		var completeAjax = jQuery.ajax({
		type: "POST",
		url: "ask_url",
		data: {ask_name:ask_name,ask_phone:ask_phone,ask_prod:ask_prod,ask_redirect:ask_redirect},
		cache: false
		});
		completeAjax.complete(function(){ 
			disablevote(); 
			alert('Form Sent!');
		});		
	});
*/
	jQuery("#askusnowForm").submit(function(){
			var ask_name = jQuery("#ask_name").val();
			var ask_phone = jQuery("#ask_phone").val();
			var ask_prod = jQuery("#ask_prod").val();
			var ask_url = jQuery("#ask_url").val();
			var action_url = jQuery("#askusnowForm").attr('action');
			jQuery.post(action_url, { ask_name: ask_name, ask_phone: ask_phone, ask_prod: ask_prod, ask_url: ask_url },
			function(data){
				jQuery('#message_sent').html(data);						
				}
			);
			
			jQuery('#message_sent').fadeIn('slow');
			setTimeout(function(){
				disablevote();
				jQuery('#message_sent').hide();
			},5000);
			return false;
			
	});

	
	jQuery("#popupvoteclose").click(function(){
		disablevote();
	});
	//Click out event!



	//Press Escape event!
	jQuery(document).keypress(function(e){
		if(e.keyCode==27 && popupStat==1){
			disablevote();
		}
	});

			

	});

});

