//		AJAX FUNCTIONS 
function makeObject(){
	var x; 
	var browser = navigator.appName; 
	//detect the client browser
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		x = new XMLHttpRequest();
	}
	
	return x;
}
	//call the function makeObject()
		//call the function makeObject()	
	//call the function makeObject()
	var request = makeObject();
	var photoid = "";// stores the photo id which is being added
	var userid = "";// stores the user rand which is being added
	var priceid = "";
	
	var x=0;//stores the x coordinate of the mouse click in add_to_cart
	var y=0;//stores the y coordinate of the mouse click in add_to_cart
	var  rbgroup_value='';


	
function rbvalue() 
	{
		for (i=0;i<document.price.radiobutton.length;i++) 
		{ 
			if (document.price.radiobutton[i].checked) 
			{ 
				rbgroup_value = document.price.radiobutton[i].value; 
			} 
		} 
	//document.price.rbgrouptxt.value=rbgroup_value;
	}

		
function add_to_cart(ss,ph,pr){
	  
		//document.documentElement.scrollTop; 
		var e = window.event;
		var browser = navigator.appName; 
		//detect the client browser
		if(browser == "Microsoft Internet Explorer"){
			x=e.clientX;
			y=e.clientY;
			
		}
		
		var scrOfX = 0, scrOfY = 0;

		if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
			
		
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}

		y=y+scrOfY;
		
		photoid = ph;
		userid = ss;
		priceid = pr;
		pr = rbgroup_value;
		
		//if(document.getElementById(photoid).innerHTML=="add to cart"){
			//alert(pr);
			//document.all.radiobutton.display="none";
			//request.open('get', "ajax.php?val=add_photo&u="+ss+"&p="+ph+"&q="+pr);
			//request.onreadystatechange = add_to_cart_returned; 
		//}
		if(document.getElementById(photoid).innerHTML=="Add to Cart"){
		if ((rbgroup_value=='')){
		alert("Please Select a Size");
		}else{
		request.open('get', "ajax.php?val=add_photo&u="+ss+"&p="+ph+"&q="+pr);
		request.onreadystatechange = add_to_cart_returned;
		}
		}

		if(document.getElementById(photoid).innerHTML=="Remove"){
			
			request.open('get', "ajax.php?val=remove_photo&u="+ss+"&p="+ph);
			request.onreadystatechange = remove_from_cart_returned; 
		}
			
		request.send('');
}

function add_to_cart_returned(){
	if (request.readyState == 1) {
		
		document.getElementById("cartadd").style.left=(x-300)+ "px";
		document.getElementById("cartadd").style.top=(y-220)+ "px";
		document.getElementById("cartadd").style.display="";
	}

	if (request.readyState == 4) {
		document.getElementById("cartadd").style.display="none";


    	if (request.status == 200) {		
			document.getElementById("total_value").innerHTML=request.responseText;
			document.getElementById(photoid).innerHTML="Remove";
			//document.getElementById("span").innerHTML="<div id='price_radio' style='display:'none' >";
			document.getElementById("price_radio").style.display="none";
			//document.all.price_radio.style.display="none";
			document.getElementById("cart_status").innerHTML="<a href='Cart.php'>View Cart</a>";
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}
function remove_from_cart_returned(){
	if (request.readyState == 1) {
		document.getElementById("cartremove").style.left=(x-300)+ "px";
		document.getElementById("cartremove").style.top=(y-220)+ "px";
		document.getElementById("cartremove").style.display="";
	}

	if (request.readyState == 4) {
		document.getElementById("cartremove").style.display="none";


    	if (request.status == 200) {
		
			document.getElementById("total_value").innerHTML=request.responseText;
			document.getElementById(photoid).innerHTML="add to cart";
			//document.getElementById("span").innerHTML="<div id='price_radio' style='display:'inline' >";
			document.getElementById("price_radio").style.display="inline";
			if(document.getElementById("cart_num_photos")!="null"){
				
				
				var temp=document.getElementById("cart_num_photos").innerHTML.split(">");
				var j=parseInt(temp[1]);
				j=j-1;
				if(j<0){j=0;}
				document.getElementById("cart_num_photos").innerHTML="<strong>"+j+"</strong>";
			}
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}
function set_cart_photos(){
	if (request.readyState == 1) {
//		document.all.subcatmsg.innerHTML="Loading.....";
	}

	if (request.readyState == 4) {
//		document.all.subcatmsg.innerHTML="";


    	if (request.status == 200) {		
			alert(request.responseText);
			//document.getElementById("cart_num_photos").innerHTML=request.responseText;
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}

//function get_sub_cat(v){
function get_sub_cat(v,i){

for(j=1;j<21;j++){
	if(document.getElementById("category_"+j)!=null){document.getElementById("category_"+j).style.backgroundColor="#f4ffd2";}
}
document.getElementById(i).style.backgroundColor="#f2f8d2";
	request.open('get', "ajax.php?val=get_subcat&v="+v);
	request.onreadystatechange = display_sub_cat; 
	request.send('');
}
function display_sub_cat(){
	if (request.readyState == 1) {
		document.getElementById("subcategory").style.display="";
	}

	if (request.readyState == 4) {
//		document.getElementById("subcatwait").style.display="none";
    	if (request.status == 200) {
			document.getElementById("subcategory").innerHTML=request.responseText ;
		}
		else {
    		alert('There was a problem with the request.');
		}
	}		
}
//		END AJAX FUNCTIONS


var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  if (document.all)
  {
    document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
    document.getElementById(pictureName).filters.blendTrans.Apply();
  }
  document.getElementById(pictureName).src = nextImage;
  if (document.all)
  {
    document.getElementById(pictureName).filters.blendTrans.Play();
  }
  var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
    + ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"',"+displaySecs+")",
    displaySecs*2000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null) {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}
/*
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validateForm(theForm)
{
	// Customize these calls for your form

	// Start ------->
	if (!validRequired(theForm.fNameisandi,"Name"))
		return false;

	if (!validRequired(theForm.fCompanyisandi,"Company"))
		return false;

	if (!validRequired(theForm.fPhoneisandi,"telephone"))
		return false;

		if (!validEmail(theForm.fEmailisandi,"Email Address",true))
		return false;

	if (!validRequired(theForm.fCommentisandi,"Comments",true))
		return false;
	// <--------- End
	
	return true;
}
*/

function login_submit(){
	if((document.admin_login.username.value!="")&&(document.admin_login.password.value!="")){
		document.admin_login.action="process.php?val=login";
		document.admin_login.submit();
	}
	else{alert("Username and Password cannot be empty. Please enter valid values");}	
}
var popupwindow;
function show_large(ne){
	popupwindow=window.open('view_large.php?val='+ne,'popup','height=500,width=550');
	popupwindow.focus();
}

function add_order(){

			document.order.action="ajax.php?val=add_order";
			document.order.submit();
			popupwindow=window.open('http://67.19.12.131/ssl/online_booking.html','popup','height=600,width=800,resizable,scrollbars');			
			popupwindow.focus();
			return true;
}
function verify_mail(){
	document.verifymail.action="ajax.php?val=verify_mail";
	document.verifymail.submit();
	return true;
}