
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)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	return xmlHttp;
		
}


function showEditNews(id, page)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_news.php"
	url = url+"?id="+id;
	url = url+"page="+page;
		
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged 
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("show_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("show_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}


function showEditMenuCategory(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_menu_category.php"
	url = url+"?id="+id;
		
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged2
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("food_category_field").style.display = "none";
		document.getElementById("menu_category_field").style.display = "none";
		document.getElementById("edit_food_category_field").style.display = "none";
		document.getElementById("edit_menu_category_field").style.display = "block";
		document.getElementById("edit_menu_category_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_menu_category_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}

function showEditMenuItem(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_menu_item.php"
	url = url+"?id="+id;

	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged3
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("menu_item_field").style.display = "none";
		document.getElementById("edit_menu_item_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_menu_item_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}

function showEditVideo(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_video.php"
	url = url+"?id="+id;

	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged4
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged4() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("video_field").style.display = "none";
		document.getElementById("edit_video_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_video_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}

function showEditPhoto(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_photo.php"
	url = url+"?id="+id;

	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged5
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged5() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("photo_field").style.display = "none";
		document.getElementById("edit_photo_field").innerHTML = xmlHttp.responseText
	} 
	else
	{
		document.getElementById("edit_photo_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}


function showEditFoodCategory(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_food_category.php"
	url = url+"?id="+id;
		
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged6
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged6() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("food_category_field").style.display = "none";
		document.getElementById("menu_category_field").style.display = "none";
		document.getElementById("edit_menu_category_field").style.display = "none";
		document.getElementById("edit_food_category_field").style.display = "block";
		document.getElementById("edit_food_category_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_food_category_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}

function showEditVideoCategory(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_video_category.php"
	url = url+"?id="+id;
		
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged7
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged7() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById('add_photo_category_option').style.display='block';
		document.getElementById('add_video_category_option').style.display='block';
		document.getElementById("video_category_field").style.display = "none";
		document.getElementById("photo_category_field").style.display = "none";
		document.getElementById("edit_photo_category_field").style.display = "none";
		document.getElementById("edit_video_category_field").style.display = "block";
		document.getElementById("edit_video_category_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_video_category_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}


function showEditPhotoCategory(id)
{ 
	
	//alert("tetre");
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_photo_category.php"
	url = url+"?id="+id;
		
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged8
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged8() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById('add_photo_category_option').style.display='block';
		document.getElementById('add_video_category_option').style.display='block';
		document.getElementById("video_category_field").style.display = "none";
		document.getElementById("photo_category_field").style.display = "none";
		document.getElementById("edit_video_category_field").style.display = "none";
		document.getElementById("edit_photo_category_field").style.display = "block";
		document.getElementById("edit_photo_category_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_photo_category_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}


function sendComments()
{
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	var name = document.contact_form.name.value;
	var phone = document.contact_form.phone.value;
	var email = document.contact_form.email.value;
	var comments = document.contact_form.comments.value;
	
	var url = "process_contact.php?name="+name+"&phone="+phone+"&email="+email+"&comments="+comments;
	
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged9
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
	
}

function stateChanged9() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("name").value = "";
		document.getElementById("phone").value = "";
		document.getElementById("email").value = "";
		document.getElementById("comments").value = "";
		//alert(xmlHttp.responseText);
		document.getElementById("contact_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("contact_field").innerHTML = "<img src = images/loading.gif>";
	}
}



function validateComments()
{
	var name = document.contact_form.name.value;
	var phone = document.contact_form.phone.value;
	var email = document.contact_form.email.value;
	var comments = document.contact_form.comments.value;
	
	if(name == "")
	{
		alert("Please enter name");
		document.contact_form.name.focus();
		return false;
	}
	/*if(phone == "")
	{
		alert("Please enter phone");
		document.contact_form.phone.focus();
		return false;
	}
	if(phone !="")
	{
		if(isNaN(phone))
		{
			alert("Please enter phone in numeric value");
			document.contact_form.phone.focus();
			return false;
		}
	}*/
	if(email == "")
	{
		alert("Please enter email address");
		document.contact_form.email.focus();
		return false;
	}
	if(email!="")
	{
		if (! isValidEmail(email)) 
		{
			alert("Please enter a valid email address");
			document.contact_form.email.focus();
			return false;
		}
		
	} 
	
	if(comments == "")
	{
		alert("Please enter comments");
		document.contact_form.comments.focus();
		return false;
	}
	return true;
}


function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


function showVideo(name)
{
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
			
	var url = "process_video.php?name="+name;
	
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged10
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
	
}

function stateChanged10() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("video_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("video_field").innerHTML = "<img src = images/loading.gif>";
	}
}

function showEditTestimonial(id)
{
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
			
	var url = "edit_testimonials.php?id="+id;
	
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged11
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
	
}

function stateChanged11() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("show_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("show_field").innerHTML = "<img src = images/loading.gif>";
	}
}


function showEditHappyItem(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_happy_item.php"
	url = url+"?id="+id;

	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged12
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged12() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("menu_item_field").style.display = "none";
		document.getElementById("edit_menu_item_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_menu_item_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}


function showEditAudio(id)
{ 
	
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "edit_audio.php"
	url = url+"?id="+id;

	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged13
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged13() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById("audio_field").style.display = "none";
		document.getElementById("edit_audio_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("edit_audio_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}

function controlSound()
{
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return false;
	}
	
	
	var url = "control_sound.php"
	
	//alert("URL "+url);
	
	xmlHttp.onreadystatechange = stateChanged14
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChanged14() 
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		//alert( xmlHttp.responseText );
		document.getElementById("sound_field").innerHTML = xmlHttp.responseText 
	} 
	else
	{
		document.getElementById("sound_field").innerHTML = "<img src = ../images/loading.gif>";
	}
}
