﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
/***************************/

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - 380 ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(url){
	if( navigator.userAgent.match(/Android/i) ||
		navigator.userAgent.match(/webOS/i) ||
		navigator.userAgent.match(/iPhone/i) ||
		navigator.userAgent.match(/iPod/i)
	 	){
		if ( url.match(/britcomVideo/) ) {
			var video_id = url.match(/video_id=([0-9]+)/)[1];
			url = '/home/iframeBritcomVideo/video_id/'+video_id;
			document.location.href = url;
			return false;
		}
	}

	//loads popup only if it is disabled
	$('#popupContact').center();
	$('#popupContact').load(url);
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");

		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

 //loading popup with jQuery magic!
function loadContactSalesPopup(url){

		//loads popup only if it is disabled
		$('#popupSaleContact').center();
		$('#popupSaleContact').load(url);
		if(popupStatus==0){
			$("#backgroundPopup").css({
				"opacity": "0.7"
			});
			$("#backgroundPopup").fadeIn("slow");

			$("#popupSaleContact").fadeIn("slow");
			popupStatus = 1;
		}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		$('#popupSaleContact').fadeOut("slow");
		$("#popupContactManifest").fadeOut("slow");
		popupStatus = 0;
		$('#popupContact').html('&nbsp;');
		$('#popupSaleContact').html('&nbsp;');
		$('#popupContactManifest').html('&nbsp;');
	}
}

//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();
	alert("screenHeight => "+screen.height + " windowHeight => "+ window.height + " InnerHeight => "+window.innerHeight + " popupHeight => "+popupHeight);
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": (window.innerHeight- 350 )/2,
		"left": (window.innerWidth- 650 ) /2
	});
	//only need force for IE6

	$("#backgroundPopup").css({
		"height": windowHeight
	});

}


//CONTROLLING EVENTS IN jQuery
function loadJavascript(){
$(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 the x event!
	$("#popupContactClose1").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#popupSaleContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#popupSaleContactClose1").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});
}
loadJavascript();

      function clearForm() {
        // iterate over all of the inputs for the form
        // element that was passed in
        $(':input', $('#refinedSearch')).each(function() {
          var type = this.type;
          var tag = this.tagName.toLowerCase(); // normalize case
          // it's ok to reset the value attr of text inputs,
          // password inputs, and textareas
          if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = "";
          // checkboxes and radios need to have their checked state cleared
          // but should *not* have their 'value' changed
          else if (type == 'checkbox' || type == 'radio')
          {
        	  this.checked = false;
        	  if(type == 'checkbox')
        	  {
        		  $(".jqTransformChecked").removeClass("jqTransformChecked");
        	  }
          }
          // select elements need to have their 'selectedIndex' property set to -1
          // (this works for both single and multiple select elements)
          else if (tag == 'select')
            this.selectedIndex = 0;
        });
      }


<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

