// JavaScript Document
window.onload = rolloverInit;

function validateEmail(inputControl, helpControl) {
   
  return validateRegExt(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
    inputControl, helpControl);
}
function validateRegExt(regex, input, Control) {
  if (!regex.test(input)) {
    if (Control != null)
		Control.className = "red";
	return false;
  }
  else {
    if (Control != null)
      Control.className = "orange";
    return true;
  }
}
function HL(inputControl)
{
	return inputControl.className = "orange";
}
function NormHL(inputControl)
{
	return inputControl.className = "";
}
function typing(inputControl)
{
	return inputControl.value = ""; 
}
function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   }



function rolloverInit()
{
	for(var i=0;i<document.images.length;i++)
	{
		if(document.images[i].parentNode.className == "roll")
		{
			setupRollover(document.images[i]);
		}
	}
}

function setupRollover(thisImage)
{
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = function() {this.src = this.outImage.src;}
	
	thisImage.clickImage = new Image();
	thisImage.clickImage.src = "./images/"+thisImage.id+"_roll.png";
	thisImage.onclick = function(){this.src = this.clickImage.src;}
	
	thisImage.overImage = new Image();
	thisImage.overImage.src = "./images/"+thisImage.id+"_roll.png";
	thisImage.onmouseover = function(){this.src = this.overImage.src;}
}






function HighlightEffect(element, start, end, restore, dur)
{
	new Effect.Highlight(element, 
	{
		startcolor: start,
		endcolor: end,
		restorecolor: restore,
		duration: dur
	});
}

function change(id, newClass) {

identity=document.getElementById(id);

identity.className=newClass;

}

function sweetFade(id)//useing scriptaculous changes the opacity of the div to 100% from 0 and and leaves the visiablity to visiable
{	
	new Effect.Opacity(id,{from: 0.0,to: 1.0,duration: 5});
}

var MovieDiv = '2';//even numbers are ture odd numbers are flase
var MapDiv = '3';//the reason why these are odd is beacause they start hidden
var PhotoDiv = '5';
var SlideNum = '2';

function Moviehide(id)//useing scriptaculous hides the div with the Fade animation and puts the visiablity to hidden
{	
	MovieDiv = '1';
	SlideNum = '1';
	new Effect.Fade(id);
}
function Movieshow(id)//useing scriptaculous shows the div with the Appear animation and puts the visiablity to visiable
{	
	MovieDiv = '2';
	SlideNum = '2';
	
	new Effect.Appear(id);
}

function ShowMovie(id) /*toggles the hide and show function based of the value of ShowDiv a public variable which changes states in the hide and show function.*/
{
	if(MovieDiv == '2')//2 is true 1 is false
	{
		Moviehide(id);
	}
	else
	{
		setTimeout("Movieshow('"+id+"')", 3000);
	}
}



function Maphide(id)//useing scriptaculous hides the div with the Fade animation and puts the visiablity to hidden
{	
	MapDiv = '3';
	SlideNum = '3';
	new Effect.Fade(id);
}
function Mapshow(id)//useing scriptaculous shows the div with the Appear animation and puts the visiablity to visiable
{	
	MapDiv = '4';
	SlideNum = '4';
	
	new Effect.Appear(id);
}

function ShowMap(id) /*toggles the hide and show function based of the value of ShowDiv a public variable which changes states in the hide and show function.*/
{
	if(MapDiv == '4')
	{
		Maphide(id);
	}
	else
	{
		setTimeout("Mapshow('"+id+"')", 3000);
	}
}

function Photohide(id)//useing scriptaculous hides the div with the Fade animation and puts the visiablity to hidden
{	
	PhotoDiv = '5';
	SlideNum = '5';
	new Effect.Opacity(id,{from: 1.0,to: 0.0,duration: 1});
}
function Photoshow(id)//useing scriptaculous shows the div with the Appear animation and puts the visiablity to visiable
{	
	PhotoDiv = '6';
	SlideNum = '6';
	new Effect.Opacity(id,{from: 0.0,to: 1.0,duration: 1});
}

function ShowPhoto(id) /*toggles the hide and show function based of the value of ShowDiv a public variable which changes states in the hide and show function.*/
{
	if(PhotoDiv == '6')
	{
		Photohide(id);
	}
	else
	{
		setTimeout("Photoshow('"+id+"')", 3000);
	}
}


function MovieholdSlide(id)
{
	if(SlideNum == '1')
	{
		Effect.toggle(id,'slide', {duration:1});
	}
	else if (SlideNum == '2')
	{
		setTimeout("Effect.toggle('"+id+"','slide', {duration:1})", 2000);
		
	}
	else if (SlideNum == '3')
	{
		Effect.toggle(id,'slide', {duration:1});
		
	}
	else if (SlideNum == '4')
	{
		setTimeout("Effect.toggle('"+id+"','slide', {duration:1})", 2000);
		
	}
	else if (SlideNum == '5')
	{
		Effect.toggle(id,'slide', {duration:1});
		
	}
	else if (SlideNum == '6')
	{
		setTimeout("Effect.toggle('"+id+"','slide', {duration:1})", 2000);
		
	}
}

var escapeOverlay = {
	fx: function(e) 
	{
		// To make script compatable with both MSIE and Firefox
		var kC  = (window.event) ? event.keyCode : e.keyCode;
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
		
		// If keypressed is escape and the new entry field is empty
		if(kC==Esc && ($F('newvalue') == '' || $F('newvalue') == null) )
			closeDialogue();
		else if(kC==Esc && window.confirm('Are you sure you wish to close the dialogue box?') )
			closeDialogue();
	}
}

// Save in cache (to be able to stopObserving() it), see Prototype API docs for more info:
// http://www.prototypejs.org/api/event
escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);

// loadPopup shows the overlay and dialogue box
function loadPopup()
{
    	// Show the overlay (disables rest of page)
	showOverlay();
	
	// Show dialogue and focus on newvalue
	$('dialogue').show();
	$('newvalue').focus();
}
 
// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	$('overlay').show();
	
	Event.observe(document, 'keypress', escapeOverlay.bfx );
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	$('overlay').hide();
	
	Event.stopObserving(document, 'keypress', escapeOverlay.bfx );
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue()
{
	hideOverlay();
	
	// Hide dialogue
	$('dialogue').hide();
	
	// Clear dialogue
	$('newvalue').value = '';
}

function FadeIn(element)
{
	new Effect.Appear(element,{duration:2, from:0, to:1.0});
}

function FadeImg(element)
{
	new Effect.Appear(element,{duration:2, from:0.5, to:1.0});
}

function FadeImgOut(element)
{
	new Effect.Fade(element,{duration:1, from:1.0, to:0.0});
}
function FadeImgIn(element)
{
	new Effect.Appear(element,{duration:1, from:0.0, to:1.0});
}
function imgDel(imgID)
{
	FadeImgOut('PH'+imgID);
	setTimeout('fadeAway('+imgID+')',2000);
}

function fadeAway(imgID)
{
	new Ajax.Request('imgDel.php?Did='+imgID,
						{
							method: 'get',
							onSuccess: function(request)
							{
								$('PH'+imgID).innerHTML = request.responseText;
							}
						}
					);
}	
function imgAdd(imgID)
{
	FadeImgOut('PH'+imgID);
	setTimeout('fadeAwayAd('+imgID+')',2000);

}

function fadeAwayAd(imgID)
{
	new Ajax.Request('imgAdd.php?Aid='+imgID,
						{
							method: 'get',
							onSuccess: function(request)
							{
								$('PH'+imgID).innerHTML = request.responseText;
							}
						}
					);
}
function SignUp(form)
{
	
	if((form.name.value.length == 0) || (form.email.value.length == 0) || (form.message.value.length == 0))
	{
		if(form.name.value.length == 0)
		{
			form.name.className = "red";
			form.name.focus(); 
		}
	
		if(form.email.value.length == 0)
		{
			form.email.className = "red";
			form.email.focus(); 
		}
		
		if(form.message.value.length == 0)
		{
			form.message.className = "red";
			form.message.focus(); 
		}
		return;
	}
	if(!validateEmail(form.email.value,form.email))
	{
		return;
	}
	else
	{
	FadeImgOut('containForm');
	var name = form.name.value;
	var email = form.email.value;
	var message = form.message.value;
	setTimeout("signin('"+name+"','"+email+"','"+message+"')",1000);
	setTimeout("FadeImgIn('containForm')",2000);
	
	}
}
function signin(name,email,message)
{
	
	new Ajax.Request('../mailing.php?sign=0&name='+name+'&email='+email+'&message='+message,{
					 method: 'get',
					 onSuccess: function(request)
					 {
						$('containForm').innerHTML = request.responseText;
						
					 }
					 });
}
