function comForm(idForm){
    //$("commentform").setStyle({display: 'block' });
    //$("commentform").setStyle({display: 'block'});
    //$("commentform").css({dispaly: "block"});

}


function showAnswer(id){
    var elem = document.getElementById(id);
    var elemHideButton = document.getElementById('hide_'+id);
    var elemShowButton = document.getElementById('show_'+id);
    if(elem){
        elemShowButton.style.display = "none";
        elemHideButton.style.display = "block";
        elem.style.display = "block";
    }
}

function hideAnswer(id){
    var elem = document.getElementById(id);
    var elemHideButton = document.getElementById('hide_'+id);
    var elemShowButton = document.getElementById('show_'+id);
    if(elem){
        elemShowButton.style.display = "block";
        elemHideButton.style.display = "none";
        elem.style.display = "none";
    }

}

/*
function createTellWindow(id){
    var elem = document.getElementById('999')
    if(!elem){
        var tell = document.createElement('DIV');
        tell.id="999";
tell.innerHTML += '<div id="ins1"><form method="POST" name="tell">Your Name * <input type="text" name="your_name">Your Email * <input type="text" name="your_email">Frienads Email 1 * <input type="text" name="friends_email1">Frienads Email 2 <input type="text" name="friends_email2">Frienads Email 3 <input type="text" name="friends_email3"><div id="ins2">*Required fields. Email addresses and names are used for this mailing only and are not retained by PIRLS for any future purposes.</div><div id="ins3"><input type="submit" value="" class="submit"/><input type="hidden" name="tellafriend" value="1"></form></div></div>';
        tell.className="tellWindow";
        document.body.appendChild(tell);
    }
    else{
        if(elem.style.display == "none"){
            elem.style.display = "block";
        }
        else{
            elem.style.display = "none";
        }
    }

}
*/

function getElementsByNameIE(tag, name) {
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function checkedbtn( element, hid1)
{
    var arrName = element.getAttribute('name');
    if(navigator.appName == "Netscape")
    {
        var x = document.getElementsByName(arrName);
        for(i = 0; i < x.length; i++)
        {
            x[i].className = "check";
        }
    }
    else
    {
        var y = getElementsByNameIE('tr', arrName);
        for(i = 0; i < y.length; i++)
        {
            y[i].className = "check";
        }

    }


    if(element.className == "checked")
    {
        element.className = "check";
    }
    else
    {
        element.className = "checked";
    }

    var hid = document.getElementById(hid1);
    hid.value = element.id.replace(/choice_/i, '');

}

function photopage(classname, id, imgfrom, imgto, imgcur) {

    var url = '../ajax/images.php';
    var pars = 'classname='+classname+'&id='+id+'&imgfrom='+imgfrom+'&imgto='+imgto+'&imgcur='+imgcur;

    var myAjax = new Ajax.Request(
        url,
        {method: 'get', parameters: pars, onFailure: reportError, onComplete: function(r){restoreimages(r)}});

    return false;
}

function restoreimages (r) {
    var ret=r.responseText;
    var imagesnav=$("imagesnav");
    imagesnav.innerHTML=ret;
}

function photoset (classname, id, imgcur) {

    var url = '../ajax/imageplace.php';
    var pars = 'classname='+classname+'&id='+id+'&imgcur='+imgcur;

    var myAjax = new Ajax.Request(
        url,
        {method: 'get', parameters: pars, onFailure: reportError, onComplete: function(r){restoreimageplace(r)}});

    return false;
}

function restoreimageplace(r) {
    var ret=r.responseText;
    var imagesnav=$("imageplace");
    imagesnav.innerHTML=ret;
}

function reportError(request) {
    alert('Sorry. There was an error.');
}

function myshow(field, id) {

    var reshow=1;
    if (show_desc) {
        if (show_desc==id) var reshow=0;
    }

    if (reshow) {
        var posy=getPosition(field)[1];
        var posx=getPosition(field)[0];
        var div=$(id);
        div.style.position="absolute";
        div.style.top=eval(posy-20)+"px";
        div.style.left=eval(posx-20)+"px";
        div.style.display="block";
        show_desc=id;
    }
}

function myhide(id) {
    var div=$(id);
    div.style.display="none";
    show_desc=0;
}

function getPosition(obj) {
    var o=obj;
    var x=0, y=0;
    while(o) {
        x+=o.offsetLeft;
        y+=o.offsetTop;
        o=o.offsetParent;
    }
    return [x,y];
}

var win;
function big_photo(f,w,h) {
    if (win) {
        win.close();
    }

    win=window.open('../photo.php?f='+f, null, "width="+w+",height="+h+",toolbar=0,scrollbars=no,resizable=no");
    return false;
}

function viewImg(image_href){
      var xstr = 'scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,location=no,resizable=yes,width=160,height=160';
      var prodWindow = window.open(image_href, 'window'+Math.round(Math.random()*1000), xstr);
      if (prodWindow) prodWindow.focus();
}

function backToSite(){
    var prodWindow = window.opener;
    if (prodWindow){
        prodWindow.focus();
        window.close();
    }
}

function housePrew(url, dir_image, image_name){
    var house_prev = document.getElementById('house');
    house_prev.innerHTML = '<a href="/view_img.php?dir_image='+dir_image+'&amp;image_name='+image_name+'" target="_blank" onclick="viewImg(this.href); return false;"><img src="'+url+dir_image+'/medium/'+image_name+'" alt="" /></a>';
}

var popupWindow = null;

function popup(wName, url, width, height, options)
{
    var iLeft = ( screen.availWidth  - width ) / 2 ;
    var iTop  = ( screen.availHeight - height ) / 2 ;

    var sOptions = {};
    if (options)
    {
        sOptions.toolbar = options.toolbar || 'no';
        sOptions.status  = options.status || 'no';
        sOptions.resizable = options.resizable || 'no';
        sOptions.dependent = options.dependent || 'yes';
        sOptions.scrollbars = options.scrollbars || 'no';
    }
    sOptions.width  = width;
    sOptions.height = height;
    sOptions.left   = iLeft;
    sOptions.top    = iTop;

    var wOptions = '';
    for (var x in sOptions)
    {
        if (wOptions != '')
        {
            wOptions += ',';
        }
        wOptions += x + '=' + sOptions[x];
    }

    var isOpera = !!window.opera;

    try
    {
        if (popupWindow)
        {
            popupWindow.close();
        }
    }
    catch(e){/* Handle opera bug */}

    var popupBlocker = "The resources browser could not be opened." +
                        " Make sure that" +
                        " all popup blockers are disabled.";

    var isMSIE = /*@cc_on!@*/false;
    if ( isMSIE )
    {
        // The following change has been made otherwise IE will open the file
        // browser on a different server session (on some cases):
        // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
        // by Simone Chiaretta.
        popupWindow = window.open(url, wName, wOptions) ;

        if ( popupWindow )
        {
            // Detect Yahoo popup blocker.
            try
            {
                var sTest = popupWindow.name ; // Yahoo returns "something",
                // but we can't access it, so detect that and avoid strange errors for the user.
                popupWindow.opener = window ;
            }
            catch(e)
            {
                alert(popupBlocker) ;
            }
        }
        else
        {
            alert(popupBlocker) ;
        }
    }
    else
    {
            popupWindow = window.open(url, wName, wOptions);
    }

    if (!popupWindow)
    {
        alert(popupBlocker) ;
    }

}
