var iCookieLifeTime=0.02;	/* days, */

function PostalFieldsOnOff(form)
{

	if(form.haspostal.checked)
	{
		form.postalname.disabled	=true;
		form.postalcity.disabled	=true;
		form.postaladdress.disabled	=true;
		form.postalcountry.disabled	=true;
		form.postalzip.disabled		=true;

		form.postalname.value		=form.billingname.value;
		form.postalcity.value		=form.billingcity.value;
		form.postaladdress.value	=form.billingaddress.value;
		form.postalcountry.value	=form.billingcountry.value;
		form.postalzip.value		=form.billingzip.value;
	}
	else
	{
		form.postalname.disabled	=false;
		form.postalcity.disabled	=false;
		form.postaladdress.disabled	=false;
		form.postalcountry.disabled	=false;
		form.postalzip.disabled		=false;
	}	
}


function ShowHideDiv(divID)
{
	var Div			='#'+divID;
	var CookieName	=divID;
	var imgID=document.getElementById(divID+'_img');

	//$(Div).show("blind", {}, 1000);
	if (document.getElementById(divID).style.display == 'none')
	{
		$(Div).show("blind",{},"slow");
		/*create cookie*/
		var date = new Date();
		date.setTime(date.getTime()+(iCookieLifeTime*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		imgID.src="skins/default/images/uparrow.png";	

		document.cookie = CookieName+"="+'show'+expires+"; path=/";
	
	}
	else
	{
		$(Div).hide("blind",{},"slow");	
		var date = new Date();
		date.setTime(date.getTime()+(iCookieLifeTime*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		imgID.src="skins/default/images/downarrow.png";	

		document.cookie = CookieName+"="+'hide'+expires+"; path=/";
	}
}

function EraseLoginFields()
{
	document.getElementById('login_pass').value = "";
	document.getElementById('login_name').value = "";
}
/************************/
$(document).ready(function() {

	$('#NewsWarning').show("blind",{},4000);

	/*
  $('.toolTip').hover(
    function() {
    this.tip = this.title;
    $(this).append(
     '<div class="toolTipWrapper">'
        +'<div class="toolTipTop"></div>'
        +'<div class="toolTipMid">'
          +this.tip
        +'</div>'
        +'<div class="toolTipBtm"></div>'
      +'</div>'
    );
    this.title = "";
    this.width = $(this).width();
    $(this).find('.toolTipWrapper').css({left:this.width-22})
    $('.toolTipWrapper').fadeIn(300);
  },
    function() {
      $('.toolTipWrapper').fadeOut(100);
      $(this).children().remove();
        this.title = this.tip;
      }
  );
  */


});


/***********************/
//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){
		$("#PopupBackground").css({
			"opacity": "0.7"
		});
		$("#PopupBackground").fadeIn("slow");
		$("#PopupDiv").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#PopupBackground").fadeOut("slow");
		$("#PopupDiv").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#PopupDiv").height();
	var popupWidth = $("#PopupDiv").width();
	//centering

	var topPosition=windowHeight/2-popupHeight/2;

	if(topPosition<0)
	{
		topPosition=50;
	}

	$("#PopupDiv").css({
		"position": "absolute",
		"top": topPosition,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#PopupBackground").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//Click the button event!
	$("#ShowPopUpDiv").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		return false;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#PopupDivClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#PopupBackground").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
