function newWindow(url, name, width, height) {
 var newwindow;
 name = name.replace(" ", "_");
 name = name.replace(".", "_");
 if(width > screen.width){
  width = screen.width;
 }
 if(height> screen.height){
  height = screen.height;
 }
 
 leftoffset=(screen.width-width)/2;
 topoffset=(screen.height-height)/2;		
 config='left='+leftoffset+',top='+topoffset+',width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
 newwindow=window.open(url, name, config, true);
 
 newwindow.focus();
}

function showObject(id){
 e = document.getElementById(id);
 if(e){
  e.style.display="block";
  e.style.visibility="visible";
 }
}

function hideObject(id){
 e = document.getElementById(id);
 if(e){
  e.style.display="none";
 }
}

function scrollto(href){
 window.location.assign(href);
}


function checkUniquePhrase(phrase){
 
 if(phrase.length > 0){
  sid = Math.random();
  url = "/photo-dict/uniquephrase.php?phrase=" + phrase + "&sid="+sid;
  YAHOO.util.Connect.asyncRequest('GET',url, {success: uniquePhraseHandler});
//  new Ajax.Request(url, {onSuccess: uniquePhraseHandler, method: 'get'});
 }
}

uniquePhraseHandler = function (transport){
 data  = transport.responseText;
 if(data != "0"){
  var reg = new RegExp();
  var ph = data.match("^([0-9]+)-(.*)$");
  if(ph && ph.length==3){
   if(confirm("Phrase already exists. Redirect?")){
    window.location.replace("/photo-dict/phrase/" + ph[1] + "/" + ph[2] + ".html");
   }
  }
  else{
   alert(data);
  }
  return;
 }
}

function delPhoto(photoid){
 sid = Math.random();
 url = "/photo-dict/delphoto.php?delpicc=" + photoid + "&sid="+sid;
 YAHOO.util.Connect.asyncRequest('GET',url, {success: delPhotoHandler});
// new Ajax.Request(url, {onSuccess: delPhotoHandler, method: 'get', parameters: params});
}

delPhotoHandler = function (transport){
 data  = transport.responseText;
 if(data.substr(0, 1) == "0"){
  alert("Photo has been removed");
  window.location.replace(window.location.href);
  return;
 }
 else{
  alert(data);
  window.location.replace(window.location.href);
 }
}

//Shows progress bar layer
function showProgressBar(){
 var height;
 var width;
 var scrolly;
 height=getDocumentHeight() + "px";
 width=getDocumentWidth() + "px";
 scrolly = getDocumentScrollY();
 if(scrolly) {
  scrolly += "px";
 }
 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('progressbarmsg');
 if(element){
  if(scrolly){
   element.style.top=scrolly;
  }
  element.style.display="block";
  element.style.visibility="visible";
 }
}
//Hides progress bar layer
function hideProgressBar(){
 document.getElementById('cloud').style.display="none";
 document.getElementById('progressbarmsg').style.display="none";
}

function $(id){
 return document.getElementById(id);
}