//////////////////////////////////////////////////////////////////////
//JavaScripts for Yapig (Yet Another PHP image gallery);
//Distributed under GPL license.
//
// -> Thanks to Thomas ORIEUX
//
//Yapig's Home Page: http://yapig.sourceforge.net
////////////////////////////////////////////////////////////////////////

/**
 * sets the arguments size for an image.
 */

function setsize(imgid,width,height){
    var obj=MM_findObj(imgid);
    obj.width=Math.round(width);
    obj.height=Math.round(height);
}

/**
 * sets image size zoomx, imgid
 */

function zoom(imgid,zoomx) {
    var obj=MM_findObj(imgid);
    var w=obj.width;
    var h=obj.height;
    obj.width=Math.round(w*zoomx);
    obj.height=Math.round(h*zoomx);
}

/**
* For preloading images
*/

function preload(src){
    tmp= new Image;tmp.src=src;
}

/**
* Select an object (got from Macromedia Dreamweaver)
*/
function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}


/****************************************************************

   User comments check Functions 

*****************************************************************/


/**
 * Valida que la dirección de correo tenga un formato adecuado
 */
function checkEmail(obj) {
  var ok=true;

    re=/(^[0-9a-zA-Z_\.-]{1,}@[0-9a-zA-Z_\-]{1,}\.[0-9a-zA-Z_\-]{2,}$)/
      if (!re.test(obj.value)) {
        /*
        alert("e-mail: example@example.com");
        //obj.value="";
        */
        ok = false;
      }


    return(ok);
}

function checkWeb(obj) {

 var ok=true;

    re=/^http:\/\//
      if (!re.test(obj.value)) {
        obj.value= "http://" + obj.value;
     }

return(ok);
}


function formCheck(obj){

  var cadena = "";
  var bgColor="#FFDDDD";
  var borderColor="#FF0000";
  var all_ok = true;

    //Set default style values
	
     obj.web.style.backgroundColor="";
     obj.web.style.borderColor="";

     obj.mail.style.backgroundColor="";
     obj.mail.style.borderColor="";


if ( (obj.mail.value != "") && (checkEmail(obj.mail) == false) ) {
    cadena = cadena + "e-mail: example@example.com\n";
    email=false;
    all_ok = false;
}

if (cadena != "") {
    alert(cadena);
    if (!email) {
       obj.mail.style.backgroundColor=bgColor;
       obj.mail.style.borderColor=borderColor;
    }
}

  return(all_ok);

}


function show(){
 var ndiv = document.createElement('div');
 ndiv.id="aa";
 ndiv.style['backgroundColor'] = "green";
 ndiv.style['width'] = "100px";
 ndiv.style['height'] = "100px";
 ndiv.innerHTML="Click here";
 document.getElementById('outer').appendChild(ndiv);
}


function hide(){
 document.getElementById('outer').removeChild(document.getElementById('aa'));
}


function bak_highlight_element0(){
 var ndiv = document.createElement('div');
 ndiv.id="aa";
 ndiv.style['backgroundColor'] = "#A2A2E8";
 ndiv.style['margin'] = "0px";
 ndiv.innerHTML="Highlighted";
 document.getElementById('element0').appendChild(ndiv);
}

function highlight_element0(){
 var x=document.getElementById("element0")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element0(){
 var x=document.getElementById("element0")
 x.style['backgroundColor'] = "#9F9FAF";
}

function highlight_element1(){
 var x=document.getElementById("element1")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element1(){
 var x=document.getElementById("element1")
 x.style['backgroundColor'] = "#9F9FAF";
}

function highlight_element2(){
 var x=document.getElementById("element2")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element2(){
 var x=document.getElementById("element2")
 x.style['backgroundColor'] = "#9F9FAF";
}

function highlight_element3(){
 var x=document.getElementById("element3")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element3(){
 var x=document.getElementById("element3")
 x.style['backgroundColor'] = "#9F9FAF";
}

function highlight_element4(){
 var x=document.getElementById("element4")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element4(){
 var x=document.getElementById("element4")
 x.style['backgroundColor'] = "#9F9FAF";
}

function highlight_element5(){
 var x=document.getElementById("element5")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element5(){
 var x=document.getElementById("element5")
 x.style['backgroundColor'] = "#9F9FAF";
}

function highlight_element6(){
 var x=document.getElementById("element6")
 x.style['backgroundColor'] = "#A2A2E8";
}

function lowlight_element6(){
 var x=document.getElementById("element6")
 x.style['backgroundColor'] = "#9F9FAF";
}
