//Detects max document width
function getDocumentWidth(){
	if(typeof(window.innerWidth)=='number'){//non-IE
		return window.innerWidth;
	}
	if(document.documentElement && document.documentElement.clientWidth){ //IE6+
		return document.documentElement.clientWidth + document.documentElement.scrollLeft;
	}
	if(document.body && document.body.clientWidth){//IE
		return document.body.clientWidth + document.body.scrollLeft;
	}
	return 0;
}
//Detects max document height
function getDocumentHeight(){
 var max = 0;
 if(document.body && document.body.clientHeight && document.body.clientHeight > max)
  max = document.body.clientHeight;
  
 if(typeof(window.document.height)=='number'){//non-IE
  if(window.document.height > max)
   max = window.document.height;
 }
    
 if(document.documentElement && document.documentElement.scrollHeight){ //IE6+
  if(document.documentElement.scrollHeight > max)
   max = document.documentElement.scrollHeight
 }
 if(document.body && document.body.scrollHeight){//IE
  if(document.body.scrollHeight > max)
   max = document.body.scrollHeight;
 }
 return max;
}
//Detects document Y scrolling
function getDocumentScrollY(){
	if(typeof(window.document.height)=='number'){//non-IE
		return window.scrollY;
	}
	if(document.documentElement && document.documentElement.scrollTop){ //IE6+
		return document.documentElement.scrollTop;
	}
	if(document.body && document.body.scrollTop){//IE
		return document.body.scrollTop;
	}	
}
//Shows error layer
function showErrorPanel(photoid){
	var height;
	var width;
	var scrolly;
	height=getDocumentHeight() + "px";
	width=getDocumentWidth() + "px";
	scrolly = getDocumentScrollY();
	if(scrolly) {
	 scrolly += "px";
	}
	var element = document.getElementById('ephotoid');
	if(!element)
	 return;
	element.value=photoid;
	
	element = document.getElementById('cloud');
	
	if(element){
	
		element.style.height=height;
		element.style.width=width;
		
		element.style.display="block";
		element.style.visibility="visible";
		
	} 
	element = document.getElementById('overlay');
	
	if(element){
		if(scrolly){
			element.style.top=scrolly;
		}
		element.style.display="block";
		element.style.visibility="visible";
	}
	document.getElementById('errorText').focus();
}
//Hides error layer
function hideErrorPanel(){
	document.getElementById('cloud').style.display="none";
	document.getElementById('overlay').style.display="none";
}

handleErrorResponse = function (transport){
 //alert("OK");
 var response  = transport.responseText;
 if (response.charAt(0) == "-"){ 
  alert("Error: " + response.substring(2));
  return;
 }
 alert('Thank you, your error has been reported.'); 
}

//Sends error and hides error layer
function sendError(){

	var uri = "http://" + location.hostname + "/photo-dict/pdadmin/adderror.php";
	var e = document.getElementById('ephotoid');
	//var picid = e.value;
	var post_data = "pictureid=" + e.value + "&passwd=4ce8591e7ecb7b985b2a10620aff43d3";

	var e = document.getElementById('errorText');
//	var errorText = e.value;
	post_data +="&errordesc="+e.value;
	
//	debug("sending:\n" + uri + "\n"+post_data);
	//new Ajax.Request(uri, {onSuccess: handleErrorResponse, method: 'post', parameters: post_data});
	//alert('ok');                
	YAHOO.util.Connect.asyncRequest('POST',uri,{success: handleErrorResponse}, post_data); 
	hideErrorPanel();
}
