var xmlHttp;
var Effect;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function validate_contact_form()
{
    
	msg = "";
    valid = true;

    if ( document.contact_form.message.value == "" )
    {
		msg = msg + "You must enter a message.\n";
        valid = false;
    }   
	
    if ( document.contact_form.name.value == "" )
    {
		msg = msg + "You must enter your name.\n";
        valid = false;
    }   	
	
    if ( document.contact_form.captcha_code.value == "" )
    {
		msg = msg + "You must enter the security code.\n";		
        valid = false;
    }   	

	
	if (document.contact_form.email.value != "")
	{
	
		apos = document.contact_form.email.value.indexOf("@");
		dotpos = document.contact_form.email.value.lastIndexOf(".");
		
		if (apos < 1 || dotpos - apos < 2)
		{
			msg = msg + "The email address entered is not valid.\n";		
			valid = false;
		}
		
	}
	
	if(document.contact_form.email.value == "" && document.contact_form.tel.value == "")
    {
		msg = msg + "You must enter either your telephone number or email address.\n";		
        valid = false;
    }   	

	if(valid == false)       
	{
        alert (msg);		
	}
	   

    return valid;
	
}

function showPhoto(filename, caption)
{
	document.getElementById('viewer').innerHTML = '<img src="/viewer/' + filename + '" alt="' + caption + '" />';
	new Effect.ScrollTo('header', { duration: 1 });		

}

/*
function showPhoto(filename, caption)
{
	document.getElementById('viewer').innerHTML = '<img src="/viewer/' + filename + '" alt="' + caption + '" />';
	new Effect.ScrollTo('header', { duration: 1 });		

}
*/

/*
function showPhoto(filename, caption, prev_filename, prev_caption, next_filename, next_caption, nextnext_filename, nextnext_caption)
{

	var viewer_content = "";
	


	if(next_filename != "")
	{						
		viewer_content = viewer_content +
						 "<a class=\"next viewer_arrow\" href=\"/viewer/" + next_filename + "\" onclick=\"javascript: showPhoto('" + next_filename + "', '" + next_caption + "', '" + filename  + "', '" + caption + "', '" + nextnext_filename + "', '" + nextnext_caption + "'); return false;\" title=\"" + nextnext_caption + "\"><span>&gt;</span></a>" +
				
						 "<a href=\"/viewer/" + next_filename + "\" onclick=\"javascript: showPhoto('" + next_filename + "', '" + next_caption + "', '" + filename  + "', '" + caption + "', '" + nextnext_filename + "', '" + nextnext_caption + "'); return false;\" title=\"" + nextnext_caption + "\">";						 
	}						 
	
	viewer_content = viewer_content +	
				 	 "<img src=\"/viewer/" + filename + "\" alt=\"" + caption + "\" />";

	if(next_filename != "")
	{
		viewer_content = viewer_content +
					 	 "</a>";
	}

	
	document.getElementById('viewer').innerHTML = viewer_content;
	
	new Effect.ScrollTo('header', { duration: 1 });		

}
*/

function showThumbsPage(page_id, p)
{

	document.getElementById("thumbs").innerHTML = "<img src=\"images/loader.gif\" alt=\"Loading Indicator\" /> <span id=\"loading\">Please Wait...</span>";
	
	//new Effect.BlindUp('thumbs', { queue: 'front', duration: 0.5 });		
	new Effect.ScrollTo('thumbs', { duration: 1 });										
	
	xmlHttp = GetXmlHttpObject()

	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	var url = "../php/ajax/showThumbsPage.php?page_id=" + page_id;
	url = url + "&p=" + p;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("thumbs").innerHTML = xmlHttp.responseText;		
		//new Effect.BlindDown('thumbs', { queue: 'front', duration: 0.5 });				
	}
}

function showNextPhoto(photo_number, page_id)
{
	//document.getElementById("thumbs").innerHTML = "<img src=\"images/loader.gif\" alt=\"Loading Indicator\" /> <span id=\"loading\">Please Wait...</span>";
	
	//new Effect.BlindUp('thumbs', { queue: 'front', duration: 0.5 });		
	//new Effect.ScrollTo('thumbs', { duration: 1 });		
	
	//document.getElementById('viewer').innerHTML = "<img src=\"images/loader.gif\" alt=\"Loading Indicator\" class=\"viewer_loader\" /> <span id=\"loading\">Please Wait...</span>";								
	document.getElementById('viewer').innerHTML = "";
	
	xmlHttp = GetXmlHttpObject()

	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	var url = "../php/ajax/showNextPhoto.php?page_id=" + page_id;
	url = url + "&x=" + photo_number;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = nextPhotoShown;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function nextPhotoShown() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//document.getElementById("thumbs").innerHTML = xmlHttp.responseText;		
		//new Effect.BlindDown('thumbs', { queue: 'front', duration: 0.5 });		
		
		document.getElementById('viewer').innerHTML = xmlHttp.responseText;
		//new Effect.ScrollTo('viewer', { duration: 1 });				
				
	}
}
