﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
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;
		
	}
	
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	
		/*var txtNote =  $('textarea[id=scooter_note_add]').val();
		var noteDate = $('input[name=note_date_add]').val();
		if(txtNote!=""){
				
				var testChars= /[\.]/;
				var testChars2= /[\/]/;
				if (noteDate.match(testChars)) {
					var dateBits = $('input[name=note_date_add]').val().split('.');
					var noteDate = dateBits[1] + '/' + dateBits[0] + '/' + dateBits[2];
				}else if(noteDate.match(testChars2)){
					var noteDate = noteDate;
				}else{
					var noteDate = $('input[name=note_date_hid]').val();
				}
				if(confirm("Weet je zeker dat je deze notitie wilt opslaan?"))
				{
					$.ajax(
					{
						type: "POST",
						url: "/addons/ajax/general_process.php",
						data: 'task=add_note&user=<?=$USER->GetID();?>&txtNote=' + txtNote + '&noteDate=' + noteDate + '&Scooter=' + <?=$ID?>,				
						success: function(result){
							if(result == 'success') 
							{
								location.reload(true);
							}
							else alert(result);
						}
					});
				}
		}else{
			alert('Voeg een notitie toe!');
		}*/
	
	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
	var sh2=getScrollHeight();
	/*alert (sh2);
	alert (popupHeight);
	alert( sh2/2);*/
	$("#popupContact").css({
		"position": "absolute",//absolute
		"top": sh2-popupHeight/*900*/,//windowHeight/2-popupHeight/2
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
       	   
   return w ? w : 0;
} 

function getScrollHeight()
{
  /* var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;*/
   
   /*// Scrollbalken im Body ausschalten
	document.body.style.overflow = 'hidden';
	var height = document.body.clientHeight;
 
	// Scrollbalken
	document.body.style.overflow = 'scroll';
 
	height -= document.body.clientHeight;
 
	// Der IE im Standardmode
	if(!height) height = document.body.offsetHeight-document.body.clientHeight;
 
	// ursprüngliche Einstellungen wiederherstellen
	document.body.style.overflow = '';
 
	return height;*/
   
   
    var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
return viewportheight;
   
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	

		
	
	//LOADING POPUP
	//Click the button event!
	$(".buy").click(function(){
		/*var test = caller.id;
            alert(test.val());*/
		//load popup
		var qtID = $(this).attr("id");
		var qtREL = $(this).attr("rel");
		$('.buy2').attr("href", qtID);
		$('.verder').attr("href", qtREL);
		 //alert(qtID);
		loadPopup();
		
		
		
		//centering with css
		centerPopup();
		
		//window.scroll(0,900); // horizontal and vertical scroll targets
		var sh=getScrollHeight();
		$('html, body').animate({ scrollTop: (sh/2) }, 'fast');
		
	});
				
	//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();
		}
	});

});
