// JavaScript Document
/********************/
/***Preload Images***/
/********************/
var imgHomeA = new Image();
var imgHomeB = new Image();
var imgFindA = new Image();
var imgFindB = new Image();
var imgAuctionsA = new Image();
var imgAuctionsB = new Image();
var imgPhotosA = new Image();
var imgPhotosB = new Image();
var imgStaffA = new Image();
var imgStaffB = new Image();
var imgContactA = new Image();
var imgContactB = new Image();


//adds images to the cache
imgHomeA.src = "images/imgHome.jpg";
imgHomeB.src = "images/imgHomeHover.jpg";
imgFindA.src = "images/imgFindUs.jpg";
imgFindB.src = "images/imgFindUsHover.jpg";
imgAuctionsA.src = "images/imgAuctions.jpg";
imgAuctionsB.src = "images/imgAuctionsHover.jpg";
imgPhotosA.src = "images/imgPhotos.jpg";
imgPhotosB.src = "images/imgPhotosHover.jpg";
imgStaffA.src = "images/imgStaff.jpg";
imgStaffB.src = "images/imgStaffHover.jpg";
imgContactA.src = "images/imgContact.jpg";
imgContactB.src = "images/imgContactHover.jpg";

/*Admin Images*/
/*var imgAdminHomeA = new Image();
var imgAdminHomeB = new Image();
var imgAdminNewsA = new Image();
var imgAdminNewsB = new Image();
var imgAdminSubscribersA = new Image();
var imgAdminSubscribersB = new Image();
var imgAdminEventsA = new Image();
var imgAdminEventsB = new Image();
var imgEditEventA = new Image();
var imgEditEventB = new Image();

imgAdminHomeA.src = "images/Admin/imgAdminHome.jpg";
imgAdminHomeB.src = "images/Admin/imgAdminHomeHover.jpg";
imgAdminNewsA.src = "images/Admin/imgAdminNews.jpg";
imgAdminNewsB.src = "images/Admin/imgAdminNewsHover.jpg";
imgAdminSubscribersA.src = "images/Admin/imgAdminSubscribers.jpg";
imgAdminSubscribersB.src = "images/Admin/imgAdminSubscribersHover.jpg";
imgAdminEventsA.src = "images/Admin/imgAdminEvents.jpg";
imgAdminEventsB.src = "images/Admin/imgAdminEventsHover.jpg";
imgEditEventA.src = "images/Admin/imgAdminEditEvent.jpg"
imgEditEventB.src = "images/Admin/imgAdminEditEventHover.jpg"*/


var sPath = window.location.pathname;
/*var PopBG = new Image();
var SubscribeBG = new Image();
PopBG.src = "images/popImgBG.jpg";
SubscribeBG.src = "images/imgPopUpFooter.jpg";*/
/*Disable Enter*/
$(document).keydown(function(e){
		if (e.keyCode == 13) {
			return false;
		}
	});

/*This is the new function for loading pictures using jQuery*/
	$.setupJMPopups({
		screenLockerBackground: "#000000",
		screenLockerOpacity: "0.7",
		margin:"auto"
	});
	
	
	
	function openStaticPopup(imgTemp) 
	{
	  
			var img = new Image();
			img = document.getElementById("popUpImg");
			
			img.src = imgTemp;
			
			
			
			$.openPopupLayer({
				name: "myStaticPopup",
				target: "dvPicPopUp"
				
			});
			
			
			
		
	}
//PopUp list for Subscribers

function openAjaxPopup(sPath) 
	{
		$.openPopupLayer({
			name: "mySecondPopup",
			
			width: 300,
			url: "Subscribe.php?page="+sPath
		});
	}
//Ajax Stuff
function AddSubscriber()
{
	var Name = document.getElementById("txtName").value
	var Email = document.getElementById("txtEmail").value
	var imgWorking = new Image();
	imgWorking.src = "Images/running.gif";
	Name = $.trim(Name);
	Email = $.trim(Email);
	//alert("'"+Email+"'");
	if(Email.length == 0 && Name.length == 0)
	{
		return false;
		
	}
	var url="SubscriberProcess.php?txtName="+Name+"&txtEmail="+Email;
	
	
	
	if (window.XMLHttpRequest) 
	{ 
		xmlhttp = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject) 
	{ 
		try { 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch (e)
		{ 
			try
			{ 
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch (e)
			{
			} 
		} 
	} 
	
	
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  	xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	
	  var dvAddSubscriber = document.getElementById("btnAddSubscriber")
	  dvAddSubscriber.innerHTML = "<img src='Images/running.gif' width='80%' height='20px' alt='' />";
	  

	  xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("dvPopUpBody").innerHTML=xmlhttp.responseText;
		}
	  }
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
//Resets the popup form if there was an error
function ReturnValue()
{
	var RedoForm = "<form action='SubscriberProcess.php' method='get' id='frmSubscribe'>";
	RedoForm += "<div>Name: <input type='text' id='txtName' name='txtName'  /></div>";
	RedoForm += "<div>Email:&nbsp;  <input type='text' id='txtEmail' name='txtEmail'  /></div>";
	RedoForm += "<div id='btnAddSubscriber'>"
	RedoForm += "<input type='button' name='btnSubmit' id='btnSubmit' onclick='AddSubscriber()' value='Add address' />";
	RedoForm += "</div>";
	RedoForm +=  "</form>";
	document.getElementById("dvPopUpBody").innerHTML =RedoForm;
}


//function for hover effects
function ImageChange(event, imgChange)
{
	var img = event.srcElement || event.target;
	img.src = imgChange.src;

}
/**/
var now = new Date()
var year = now.getFullYear()
var month = now.getMonth() + 1;
	//Formats the month with the format 'yyyymm'
	var currentMonth 
	
/*var preLoad = new Image
preLoad.src = "images/OverLay.png";
preLoad.src = "images/popupBG.gif";*/


/*This funtion shows the message in the calendar for the events*/
function show(hover) 
{
	//Shows the DIVs on the calendar (ones with events)
	myObj = document.getElementById(hover);
	myObj.style.visibility = 'visible';
}
/*This funtion hides the message in the calendar for the events*/
function hide(hover) 
{
	//Hides the DIVs on the calendar (ones with events)
	myObj = document.getElementById(hover);
	myObj.style.visibility = 'hidden';
}

/*This function turns the current month to visible(display:block)*/
function strtCalendar(serverMonth)
{	/*Called After Calendar Loads*/
	lstMnth = document.getElementById('lstMonth');
	//lstMnth.selectedIndex = 0;
	//This will go the the DIV with the current month and year
	selectedMonth = document.getElementById(serverMonth);
	selectedMonth.style.display = 'block';
	//Loads the current month value so that when the month is switched it can turn the old one off
	currentMonth = serverMonth;
}
/*This function goes when the lstMonth is changed*/
function clndrChange(lstOption)
{
	//Turns off previous DIVs
	prevMonth = document.getElementById(currentMonth);
	prevMonth.style.display = 'none';
	//Turns on selected DIVs
	selectedMonth = document.getElementById(lstOption.value);
	selectedMonth.style.display = 'block';
	//Overwrites the previous month that was selected with the current month
	currentMonth = lstOption.value;
}

function Validate()
{
	var lstMonth = document.getElementById("Month")
	var lstYear = document.getElementById("Year")
	var lstDate = document.getElementById("Date")
	
	if(lstMonth.selectedIndex == 0)
	{
		alert("Please select the month of the event");
		lstMonth.focus();
		return false
	}
	
	if(lstYear.selectedIndex == 0)
	{
		alert("Please select the year of the event");
		lstYear.focus();
		return false
	}

	if(lstDate.selectedIndex == 0)
	{
		alert("Please select the date of the event");
		lstDate.focus();
		return false
	}

}

//Function for table row hover effects
	function RowHover(event, On)
	{
		var theTag = event.target || event.srcElement
		
		if (theTag.tagName != "TD" ) return;
	 
		
		var OriginalFontColor = theTag.parentNode.style.color
		if(On)
		{
			theTag.parentNode.style.backgroundColor = "#336699";
			theTag.parentNode.style.color = "white";
		}
		else
		{
			theTag.parentNode.style.backgroundColor = "transparent";
			theTag.parentNode.style.color = "black";
		}
	}
















/*This Functions is for the hover box in the picture pages*/
  function showBox(imgID)
  {  
  	var srcImage = document.getElementById("imgMain1");
	
  
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	var height = document.documentElement.clientHeight + document.documentElement.scrollHeight; 
	/*The Position of the box*/
    var layer = document.createElement('div');
    layer.style.zIndex = 2;
    layer.id = 'layer';
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    layer.style.height =document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.3';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
    document.body.appendChild(layer);  


	/*The Box that the image is in*/
    var box = document.createElement('div');
    box.style.zIndex = 3;
    box.id = 'box';
    box.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
    box.style.top = '100px';
    box.style.left = (width / 2) - (600 / 2) + 'px'; 
    box.style.height = '425px';
    box.style.width = '600px';
	box.style.backgroundRepeat = 'no-repeat';
		

	//box.style.backgroundColor = 'white';
	box.style.backgroundImage = "url('images/popupBG.gif')";
    //box.style.border = '2px solid silver';
    box.style.padding = '20px';
	document.body.appendChild(box);  
	
	/*Get the source image*/
	
	/*The image thats in the box*/
    var imgPic = document.createElement('img');
    imgPic.src = srcImage.src;
	imgPic.style.width ='600px';
	imgPic.style.height = '400px';
	box.appendChild(imgPic);
	
	/*The Overlay*/
   var OverLay = document.createElement('div');
    OverLay.style.zIndex = 10;
    OverLay.id = 'OverLay';
    OverLay.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
    OverLay.style.top = '100px';
    OverLay.style.left = (width / 2) - (600 / 2) + 'px'; 
    OverLay.style.height = '425px';
    OverLay.style.width = '600px';
	//OverLay.style.backgroundRepeat = 'no-repeat';
	//OverLay.style.backgroundColor = 'white';
	//OverLay.style.backgroundImage = "url('images/OverLay.png')";
    //OverLay.style.border = '2px solid silver';
    OverLay.style.padding = '20px';
	box.appendChild(OverLay);
	
    /*Close Button*/
    var btnClose = document.createElement('a');
    btnClose.innerHTML = 'Close Window';
	btnClose.style.position = "absolute";
	btnClose.style.marginLeft = '455px';
	btnClose.style.marginTop = '413px';
	btnClose.style.fontSize = '20px';
	btnClose.style.textDecoration = 'none';
	OverLay.appendChild(btnClose);
	
	btnClose.href = 'javascript:void(0)';
	/*Close the popup if the button is pressed*/
    btnClose.onclick = function() 
    {
      document.body.removeChild(document.getElementById('layer'));
      document.body.removeChild(document.getElementById('box'));
    };
    /*Close the popup if anything but the popup is clicked*/  
    layer.onclick = function()
	{
      document.body.removeChild(document.getElementById('layer'));
      document.body.removeChild(document.getElementById('box'));
    };

  }

