/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2007 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 3
  as published by the Free Software Foundation.
  
  ********************************************
  Coppermine version: 1.4.14
  $Source$
  $Revision: 3966 $
  $Author: gaugau $
  $Date: 2007-09-17 08:53:13 +0200 (Mo, 17 Sep 2007) $
**********************************************/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function writeCookie(name, data, noDays){
  var cookieStr = name + "="+ data
  if (writeCookie.arguments.length > 2){
    cookieStr += "; expires=" + getCookieExpireDate(noDays)
    }
  document.cookie = cookieStr
}

function readCookie(cookieName){
   var searchName = cookieName + "="
   var cookies = document.cookie
   var start = cookies.indexOf(cookieName)
   if (start == -1){ // cookie not found
     return ""
     }
   start += searchName.length //start of the cookie data
   var end = cookies.indexOf(";", start)
   if (end == -1){
     end = cookies.length
     }
   return cookies.substring(start, end)
}

function blocking(nr, cookie, vis_state)
{
        if (document.layers)
        {
                current = (document.layers[nr].display == 'none') ? vis_state : 'none';
                if (cookie != '')
                        writeCookie(nr, current);
                document.layers[nr].display = current;
        }
        else if (document.all)
        {
                current = (document.all[nr].style.display == 'none') ? vis_state : 'none';
                if (cookie != '')
                        writeCookie(nr, current);
                document.all[nr].style.display = current;
        }
        else if (document.getElementById)
        {
                display = (document.getElementById(nr).style.display == 'none') ? vis_state : 'none';
                if (cookie != '')
                        writeCookie(nr, display);
                document.getElementById(nr).style.display = display;
        }
}


function adjust_popup()
{
        var w, h, fixedW, fixedH, diffW, diffH;
        if (document.documentElement && document.body.clientHeight==0) {     // Catches IE6 and FF in DOCMODE
                fixedW = document.documentElement.clientWidth;
                fixedH = document.documentElement.clientHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - document.documentElement.clientWidth;
                diffH = fixedH - document.documentElement.clientHeight;
                w = fixedW + diffW + 16; // Vert Scrollbar Always On in DOCMODE.
                h = fixedH + diffH;
                if (w >= screen.availWidth) h += 16;
        } else if (document.all) {
                fixedW = document.body.clientWidth;
                fixedH = document.body.clientHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - document.body.clientWidth;
                diffH = fixedH - document.body.clientHeight;
                w = fixedW + diffW;
                h = fixedH + diffH;
                if (h >= screen.availHeight) w += 16;
                if (w >= screen.availWidth)  h += 16;
        } else {
                fixedW = window.innerWidth;
                fixedH = window.innerHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - window.innerWidth;
                diffH = fixedH - window.innerHeight;
                w = fixedW + diffW;
                h = fixedH + diffH;
                if (w >= screen.availWidth)  h += 16;
                if (h >= screen.availHeight) w += 16;
        }
        w = Math.min(w,screen.availWidth);
        h = Math.min(h,screen.availHeight);
        window.resizeTo(w,h);
        window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}

function show_section(e) {
    if (document.getElementById(e).style.display == 'none') {
        document.getElementById(e).style.display = 'block';
    } else {
        document.getElementById(e).style.display = 'none';
    }
}


function expand()
{
        var Nodes = document.getElementsByTagName("table")
        var max = Nodes.length
        for(var i = 0;i < max;i++) {
                var nodeObj = Nodes.item(i)
                var str = nodeObj.id
                if (str.match("section")) {
                        nodeObj.style.display = 'block';
                }
        }
}

function hideall()
{
        var Nodes = document.getElementsByTagName("table")
        var max = Nodes.length
        for(var i = 0;i < max;i++) {
                var nodeObj = Nodes.item(i)
                var str = nodeObj.id
                if (str.match("section")) {
                        nodeObj.style.display = 'none';
                }
        }
}
function popUp2(URL,WIDTH,HEIGHT,SCROLL,LEFT,TOP) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "','scrollbars="+ SCROLL +",width="+ WIDTH +",height="+ HEIGHT +",left = "+ LEFT +",top = "+ TOP +"');");
}

function openUpWindowVideochat(uid)
{
        var name = 'videochat_' + uid;
        var url = 'http://www.iloveinterracial.com/chat/window-mode/';

        var left = Math.round((screen.width - width) / 2);
        var top = Math.round((screen.height - height) / 2);
        var width = 900;
        var height = 560;
        var isResizeAble = true;

        var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no';
        styleStr += ',resizable=' + (isResizeAble ? 'yes' : 'no');
        styleStr += ',width=' + width + ',height=' + height;
        styleStr += ',left=' + left + ',top=' + top;
        styleStr += ',screenX=' + left + ',screenY=' + top;

        var res = window.open(url, name, styleStr);
        res.focus();
}

$(document).ready(function() {
    $("#ctrlActions").ajaxSend(function(){
        $('#ctrlContainer').show();
        $(this).empty().html("<center><img src='/themes/hardwired/images/ajax_process.gif' border=0></center>");
    });
});

function ajaxShowRateBox(pid) {
    $.get('/ajax_input.php?action=rate&pid=' + pid, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
        }
    }, "json");
}

function ajaxShowShareBox(pid) {
    $.get('/ajax_input.php?action=share&pid=' + pid, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
        }
    }, "json");
}

function ajaxRate(pid, rate) {
    $.post('/ajax_input.php?action=rate&pid=' + pid + '&rate=' + rate, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
        }
    }, "json");
}

function ajaxAdd2Fav(pid) {
    $.get('/ajax_input.php?action=add2fav&pid=' + pid, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
            $('#add2favorites').html(data.buttText);
        }
    }, "json");
}

function ajaxAdd2Playlist(pid) {
    $.get('/ajax_input.php?action=add2play&mode=add&pid=' + pid, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
        }
    }, "json");
}

function ajaxShowReportBox(pid) {
    $.get('/ajax_input.php?action=report&pid=' + pid, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
        }
    }, "json");
}

function bookmark_link(title, url)
{
    if (window.sidebar)
    {
        window.sidebar.addPanel(title, url, "");
    }
    else if( window.external )
    {
        window.external.AddFavorite( url, title);
    }
}

function select_all (obj) {
    var text_val=eval(obj);
    text_val.focus();
    text_val.select();
}

function ajxPlaySelect (id) {
    if (id == 0) {
        $("#plCreateNew").show();
        $('#plSubmit').val("Create");
    } else {
        $("#plCreateNew").hide();
        $('#plSubmit').val("Add");
    }

    if (id >= 0)
        $("#plSubmit").removeAttr('disabled');
    else
        $("#plSubmit").attr("disabled", "disabled");
}

function ajxReportSubmit(pid) {
    var reason = getRadioValue($('*[name=reason]').get());

    $.post('/ajax_input.php?action=report&mode=report_send&pid=' + pid,
        {reason : reason, other: $('#iOther').val(), category: $('#iCategory').val()}, function(data) {
        if (data) {
            $('#ctrlActions').html(data.ctrlHTML);
        }
    }, "json");
}

function ajxPlaySubmit(pid) {
    var id = $('#plID').val();
    if (id == 0) {
        if ($('#plTitle').val() == "") {
            alert('Playlist title can not be empty, please enter correct title');
            return false;
        }

        $.post('/ajax_input.php?action=add2play&mode=create&pid=' + pid,
            {title : $('#plTitle').val()}, function(data) {
            if (data) {
                $('#ctrlActions').html(data.ctrlHTML);
            }
        }, "json");
    } else if (id > 0) {
        $.post('/ajax_input.php?action=add2play&mode=addlist&pid=' + pid,
            {playid : id}, function(data) {
            if (data) {
                $('#ctrlActions').html(data.ctrlHTML);
            }
        }, "json");
    }
    return false;
}

function ajxFavSubmit(pid) {
    var id = $('#plID').val();
    if (id == 0) {
        if ($('#plTitle').val() == "") {
            alert('Favorites list title can not be empty, please enter correct title');
            return false;
        }

        $.post('/ajax_input.php?action=add2fav&mode=create&pid=' + pid,
            {title : $('#plTitle').val()}, function(data) {
            if (data) {
                $('#ctrlActions').html(data.ctrlHTML);
            }
        }, "json");
    } else if (id > 0) {
        $.post('/ajax_input.php?action=add2fav&mode=addlist&pid=' + pid,
            {playid : id}, function(data) {
            if (data) {
                $('#ctrlActions').html(data.ctrlHTML);
            }
        }, "json");
    }
    return false;
}

function ajxFavSelect (id) {
    if (id == 0) {
        $("#plCreateNew").show();
        $('#plSubmit').val("Create");
    } else {
        $("#plCreateNew").hide();
        $('#plSubmit').val("Add");
    }

    if (id >= 0)
        $("#plSubmit").removeAttr('disabled');
    else
        $("#plSubmit").attr("disabled", "disabled");
}

function ajxReportSelect(reason) {
    if (reason == 0)
        reason = getRadioValue($('*[name=reason]').get());
    if (reason == 4) {
        $('#rsCategory').show();

        if ($('#iCategory').val() > 0)
            $("#plSubmit").removeAttr('disabled');
        else
            $("#plSubmit").attr("disabled", "disabled");
    } else {
        $('#rsCategory').hide();

        $("#plSubmit").removeAttr('disabled');
    }
}

function getRadioValue(radioObject)
{
    var value = null;
    for (var i = 0; i < radioObject.length; i++) {
        if (radioObject[i].checked) {
            value = radioObject[i].value;
            break;
        }
    }
    return value;
}

