/***************************/
//@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 popupStatus2 = 0;

//loading popup with jQuery magic!
function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus2==0){
		$("#backgroundPopup2").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup2").fadeIn("slow");
		$("#popupContact2").fadeIn("slow");

		//var imgRep = '<img src="/wp-content/themes/newsmojo-child/images/private-jet-video.jpg" width="250" height="157">';
		//document.getElementById('videoDiv').innerHTML = imgRep;

		popupStatus2 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus2==1){
		$("#backgroundPopup2").fadeOut("slow");
		$("#popupContact2").fadeOut("slow");

		//var vidRep = '<div style="position:absolute; top:0; left:0; z-index:1;"><iframe width="250" height="157" src="http://www.youtube.com/embed/SmHkFQFfnd8" frameborder="0" allowfullscreen></iframe></div>';
		//document.getElementById('videoDiv').innerHTML = vidRep;

		popupStatus2 = 0;
	}
}

//centering popup
function centerPopup2(){
	//request data for centering
	var windowWidth;	// = document.documentElement.clientWidth;
	var windowHeight;	// = document.documentElement.clientHeight;
	var E;

	/////////// Handling Window Width + 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')
		{
			//alert('browser 1');
		  windowWidth = window.innerWidth;
		  windowHeight = window.innerHeight;
		  E = window.pageYOffset;
		}

		// 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)
		{
			//alert('browser 2');
		   windowWidth = document.body.clientWidth;	//.documentElement.clientWidth;
		   windowHeight = document.body.clientHeight;	//.documentElement.clientHeight;
		   E = document.body.scrollTop;
		   //alert('windowWidth: '+windowWidth+"\nwindowHeight: "+windowHeight);
		}

		// older versions of IE

		else
		{
			//alert('browser 3');
		   windowWidth = document.getElementsByTagName('body')[0].clientWidth;
		   windowHeight = document.getElementsByTagName('body')[0].clientHeight;
		   E = document.getElementsByTagName('body')[0].scrollTop;
		}
	//////////////// end ////////////////////////////////////



	var popupHeight = $("#popupContact2").height();
	var popupWidth = $("#popupContact2").width();

	//alert('popupHeight:'+popupHeight+', popupWidth:'+popupWidth);
	var pTop = windowHeight/2-popupHeight/2;
	var pBot = windowWidth/2-popupWidth/2;
	//alert('top:'+pTop+', pBot:'+pBot);

	//centering
	$("#popupContact2").css({
		"position": "absolute",
		"top": (E + 50),	//windowHeight/2-popupHeight/2,
		"left": pBot	//windowWidth/2-popupWidth/2
	});
	//only need force for IE6

	$("#backgroundPopup2").css({
		"height": windowHeight,
		"width": windowWidth
	});

}


//My function to pop a form
function formPop(allQuotes)	{ 	//main,o1,o2,o3,o4)	//msg,items,quote)



	var aqCount = allQuotes.length;
	var quoteSplit;
	var qs_1;

	for(var i = 0; i < aqCount; i++){
		//alert(allQuotes[i]);
		document.getElementById('quoteRow_'+i).style.visibility="visible";
		quoteSplit = allQuotes[i].split('||');			//separate all values in the quote values string
		for(j in quoteSplit){
			qs_1 = quoteSplit[j].split('=');
			if(i == 0){
				if(qs_1[0] == 'trip_distance_miles'){
					//set quote_distMi to ms_1[1]
					document.getElementById('quote_distMi_'+i).innerHTML = qs_1[1];
				}
				if(qs_1[0] == 'trip_distance_kilometers'){
					//set quote_distMi to ms_1[1]
					document.getElementById('quote_distKm_'+i).innerHTML = qs_1[1];
				}
				if(qs_1[0] == 'trip_type'){
					//set quote_myTripType to ms_1[1]
					document.getElementById('quote_myTripType_'+i).innerHTML = qs_1[1];
				}
			}

			if(qs_1[0] == 'trip_flight_time_h'){
				//set quote_flightTime_h to ms_1[1]
				document.getElementById('quote_flightTime_h_'+i).innerHTML = qs_1[1]+' h ';
			}
			if(qs_1[0] == 'trip_flight_time_m'){
				//set quote_flightTime_m to ms_1[1]
				document.getElementById('quote_flightTime_m_'+i).innerHTML = qs_1[1]+' m';
			}
			if(qs_1[0] == 'payment_flight_cost'){
				//set quote_flightCostMember to ms_1[1]
				document.getElementById('quote_flightCostMember_'+i).innerHTML = numberFormat(qs_1[1],'$');
			}
			if(qs_1[0] == 'jet_type'){
				//set quote_myJetType to ms_1[1]
				document.getElementById('quote_myJetType_'+i).innerHTML = qs_1[1];
			}
			if(qs_1[0] == 'jet_manufacturer'){
				if (qs_1[1] != 'UNDEFINED'){
					//set quote_myJetType to ms_1[1]
					document.getElementById('quote_myJetManu_'+i).innerHTML = qs_1[1] + ' ';
				}
			}
			if(qs_1[0] == 'jet_model'){
				//set quote_myJetType to ms_1[1]
				document.getElementById('quote_myJetModel_'+i).innerHTML = qs_1[1];
			}
		}
	}


	//LOADING POPUP
	//centering with css
	centerPopup2();
	//load popup
	loadPopup2();


	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose2").click(function(){
		disablePopup2();
	});
	//Click out event!
	$("#backgroundPopup2").click(function(){
		disablePopup2();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus2==1){
			disablePopup2();
		}
	});
}

