function set_page(page){
	document.getElementById("button_" + page).className = page + "_on";

}

function toggle(list){ 
	var listElementStyle=document.getElementById(list).style; 

	if (listElementStyle.display != "none"){
		listElementStyle.display="none"; 
	} else {
		listElementStyle.display="block"; 
	}
}

function gallery_viewer(image, gallery_title, gallery_name){
	//window.open('/development/viewer/?img=' + img + '&title=' + title + '', 'viewer', 'width=10,height=10,menubar=no,location=no,scrollbars=no,toolbar=no,top=0,left=0');
	//window.open('/gallery/viewer.asp?image=' + image + '&table=gallery&gallery_name=' + gallery_name + '', 'viewer', 'width=550,height=450,menubar=no,location=no,scrollbars=no,toolbar=no');
	create_popup("popup_container", image, "gallery", gallery_name);
	
}
function events_viewer(image,gallery_title,gallery_name){
	create_popup("popup_container", image, "events", gallery_name);
}

function createFlash(szMovieName, szWidth, szHeight) {

		var objHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="' + szWidth + '" height="' + szHeight + '">'
		objHTML += '<param name="movie" value="' + szMovieName + '" />'
		objHTML += '<param name="quality" value="high" />'
		//objHTML += '<param name="SCALE" value="exactfit" />'
		objHTML += '<param name="scale" value="noscale" />'
		objHTML += '<param name="wmode" value="transparent">'
		objHTML += '<param name="AllowScriptAccess" value="always" />'
		objHTML += '<param name="allowFullScreen" value="true">'
		objHTML += '<embed src="' + szMovieName + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + szWidth + '" height="' + szHeight + '" allowScriptAccess="always" wmode="transparent"></embed>'
		objHTML += '</object>'

		document.write(objHTML);
	}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function check_form(form_name){
	error_message = ""

	if(document[form_name].email_name.value == ""){
		error_message += "Sorry you didn't add your name\n";
	} else if(document[form_name].email_from.value == ""){
		error_message += "You need to enter your email address\n";
	} else if(document[form_name].email_message.value == ""){
		error_message += "You need to enter your message\n";
	}

	if(error_message != ""){
		alert(error_message);
		return false;
	} else {
		return true;
	}
}

function show_menu(div, submenu){
	var listElementStyle=document.getElementById(div).style; 
	listElementStyle.display="block";
	if(submenu == "true"){
		listElementStyle.top = "-25px";
	}
}

function delay_hide(){
	clearTimeout(delayhide);
}

function hide_menu(div){
	delayhide = setTimeout("delay_hide_menu('" + div + "')",250);
}

function delay_hide_menu(div){
	var listElementStyle=document.getElementById(div).style; 
	listElementStyle.display="none";
	clearTimeout(delayhide);
}

/**************************************************
	AJAX FORM SENDING
**************************************************/


var x;
var contact = new Array("name","phone","from","subject","message");

function check_form(url, form_name, height){
	error_message = "";
	url_string = "";
	
	for (x in this[form_name]){
		if (document[form_name][x].value != ""){
			url_string += "&" + this[form_name][x] + "=" + document[form_name][x].value;
		} else {
			switch (this[form_name][x]){
				case "name":
						error_message += "<p>Sorry you need to enter your name</p>\n";
					break;
				case "from":
					error_message += "<p>Sorry you need to enter your email address</p>\n";
					break;    
				case "phone":
					break;    
				default:
					error_message += "<p>Sorry you didn't enter your " + this[form_name][x] + "</p>\n";
				}
		}
	}

	if(error_message != ""){
		//alert(error_message);
		document.getElementById(form_name + "_error").style.display = "block";
		document.getElementById(form_name + "_error").innerHTML = error_message;
	} else {
		ajax_loader(url + url_string, form_name, height);
		//alert(url + url_string, form_name, height);	
	}

	return false;
}

function ajax_loader(url, div, height){

	loading(div, height);
	
	
	if (document.getElementById){
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}

	if (x){
		x.onreadystatechange = function() {
		if (x.readyState == 4 && x.status == 200) {
			document.getElementById(div).innerHTML = x.responseText;
		}
    }
    x.open("GET", url, true);
    x.send(null);
	}
}

function ajax_sender(url){

	if (document.getElementById){
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
    x.open("GET", url);
    x.send(null);

}

function loading(div, height){
    var objHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0\" width=\"100%\" height=\"100%\">";
    objHTML += "<param name=\"movie\" value=\"/flash/loading.swf\">";
    objHTML += "<param name=\"quality\" value=\"high\">";
    objHTML += "<param name=\"wmode\" value=\"transparent\">";
    objHTML += "<embed src=\"/flash/loading.swf\" width=\"100%\" height=\"100%\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed>";
    objHTML += "</object>";

	document.getElementById(div).style.height = height + "px";
	document.getElementById(div).innerHTML = objHTML;
}


/**************************************************
	POPUP CONTROL
**************************************************/

function create_popup(id, image, table, gallery_name){
	if (document.getElementById('popup_container') == null){
		launch_popup(id, image, table, gallery_name);
		//hideflash();
	} else {
		document.getElementById("popup_container").style.display = "block";
		document.getElementById("popup_container").innerHTML = amend_viewer(image, table, gallery_name);
		//hideflash();
	}
}

function popup_close(){
	document.getElementById("popup_container").style.display = "none";
}

var my_width = 0, my_height = 0;

function client_height(){
	
	if (typeof(window.innerWidth) == "number"){
		my_height = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		my_height = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
		my_height = document.body.clientHeight;
	}
	
	return my_height;
}

function client_width(){
	
	if (typeof(window.innerWidth) == "number"){
		my_width = window.innerWidth;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		my_width = document.documentElement.clientWidth;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)){
		my_width = document.body.clientWidth;
	}
	
	return my_width;
}


function launch_popup(id, image, table, gallery_name){
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute(id, id);
	newdiv.id = id;
	
	newdiv.style.width = client_width();
	newdiv.style.height = client_height();
	newdiv.style.height = document.body.scrollHeight + 20;

	//my_height = my_height - document.documentElement.scrollTop;

	newdiv.style.position = "absolute";
       
	newdiv.style.left = 0;
    newdiv.style.top = 0;

	newdiv.style.backgroundImage="url('/css/images/black_50.png')"; 

	newdiv.innerHTML = amend_viewer(image, table, gallery_name);
   
	document.body.appendChild(newdiv);
}

function amend_viewer(image, table, gallery_name){
	var objHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="' + my_width + '" height="' + my_height + '" style="margin-top: ' + document.documentElement.scrollTop + 'px;">';
	objHTML += '<param name="movie" value="/flash/gallery_viewer.swf?start_image=' + image + '&table=' + table + '&gallery_name=' + gallery_name + '">';
	objHTML += '<param name="wmode" value="transparent">';
	objHTML += '<embed src="/flash/gallery_viewer.swf?start_image=' + image + '&table=' + table + '&gallery_name=' + gallery_name + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + my_width + '" height="' + my_height + '"></embed>';
	objHTML += '</object>';
	
	return objHTML;

}

function hideflash(){

	var flash = document.getElementsByTagName('object');
	//var flash = document.getElementsByTagName('embed');

	for (var i = 0; i < flash.length; i++){
		//flash[i].style.display = "none";
		flash[i].style.visibility = 'hidden';
	} 

}

function showflash(){

	var flash = document.getElementsByTagName('object');
	//var flash = document.getElementsByTagName('embed');

	for (var i = 0; i < flash.length; i++){
		//flash[i].style.display = "none";
		flash[i].style.visibility = 'visible';
	} 

}