/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2009 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.25
  $HeadURL: https://coppermine.svn.sourceforge.net/svnroot/coppermine/trunk/cpg1.4.x/scripts.js $
  $Revision: 5997 $
  $Author: gaugau $
  $Date: 2009-05-26 08:43:24 +0200 (Di, 26 Mai 2009) $
**********************************************/
function popitup( pid, checkedValue ){
  newwindow = window.open("makelive.php?pid="+pid+"&makelive="+checkedValue, 'newwin', 'width=100,height=100,scrollbars=no');
}

function discontinueProduct( piddisc, piddischash, leaddisc, leaddischash, advertiserdisc, advertiserdischash ){
   newwindow = window.open("discontinue_product.php?piddisc="+piddisc+"&piddischash="+piddischash+"&leaddisc="+leaddisc + "&leaddischash="+leaddischash+"&advertiserdisc="+advertiserdisc+"&advertiserdischash="+ advertiserdischash, 'newwin', 'width=125,height=125,scrollbars=no');
}

function deletePic( pid ){
  newwindow = window.open("delete.php?id="+pid+"&what=picture", 'newwin', 'width=100,height=100,scrollbars=no');
}


// Cleans up search criteria on admin search screen.
function cleanupCriteria(){
  document.frm1.search.value = "";
  document.frm1.txtuploaddt1.value = "";
  document.frm1.txtuploaddt2.value = "";
  
  document.frm1.txtupdatedt1.value = "";
  document.frm1.txtupdatedt2.value = "";
  document.frm1.make_live.value = "";
  document.frm1.ddRoom.selectedIndex = 0;
  document.frm1.ddbrand.selectedIndex = 0;
  document.frm1.ddmaterial.selectedIndex = 0;
  document.frm1.ddpiece.selectedIndex = 0;
  document.frm1.ddretailer.selectedIndex = 0;
  document.frm1.sortOrder.selectedIndex = 0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  newwindow = window.open(theURL,winName,features);
  if (window.focus) {newwindow.focus()}
}

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 RequestInformation(id)
    {
        var stores = ""; var advert="";
        var comma =""; var storecount=""; var ddindex=0;
    
        var len1 = document.reqInfoForm.chkadvertiser.length;
        var storeselected =false;
        for (var i=0; i < document.reqInfoForm.chkadvertiser.length; i++)
        {
            if((document.reqInfoForm.chkadvertiser[i].checked))
            {
                advert = advert + comma + document.reqInfoForm.chkadvertiser[i].value;
                comma = ",";
            }
        }
        comma = "";
        if (advert ==""){
             alert("Select a Retailer");
             return false;
        }
        /*
        for (var i=0; i < document.reqInfoForm.chkadvertiser.length; i++)
        {
            if(document.reqInfoForm.chkadvertiser[i].checked)
            {
                storecount = eval("document.reqInfoForm.storeconts"+document.reqInfoForm.chkadvertiser[i].value+".value");
                if (storecount != "0") 
                {
                var ddindex = eval("document.reqInfoForm.store" + document.reqInfoForm.chkadvertiser[i].value +".options[document.reqInfoForm.store" +document.reqInfoForm.chkadvertiser[i].value +".selectedIndex].value");
                    if (ddindex == "")
                    {
                        alert("Select a Store");
                        return false;
                    }
                    else
                    {
                        stores = stores + comma + ddindex;
                        comma = ",";
                    }
                }
                else
                {
                    stores = stores + comma + 0;
                    comma = ",";
                }
            }
        }
        if (stores != "") stores="&store="+stores;
        */
        var pid = "&pid="+id+"&brand="+document.reqInfoForm.hidbrand.value;
        var otherval = "&pnum="+document.reqInfoForm.hidprodnum.value+"&pname="+document.reqInfoForm.hidprodname.value;
        
        window.open("storedata.php?adver="+advert+stores+pid+otherval,"myNewWin","width=480,height=570,scrollbars=yes,toolbar=0,resizable=yes"); 
    }
    
    function popupmicrosite(site)
    {
      var width  = 1000;
      var height = 500;
      var left   = (screen.width  - width)/2;
      var top    = (screen.height - height)/2;
      var params = 'width='+width+', height='+height;
        params += ', top='+top+', left='+left;
        params += ', directories=no';
        params += ', location=no';
        params += ', menubar=no';
        params += ', resizable=no';
        params += ', scrollbars=yes';
        params += ', status=no';
        params += ', toolbar=no';
      window.open(site,"MicroWind",params);
    }
    
    function checkAll(chkBoxObject, field)
    {
        if (chkBoxObject.checked){
            for (i = 0; i < field.length-1; i++){
                field[i].checked = true;
            }
        } else {
            for (i = 0; i < field.length-1; i++){
                field[i].checked = false;
            }
        }
    }

function RequestInformationMicrosite(advertiserid, numstores, pictureid)
    {
        var stores = ""; var advert="";
        var ddindex=0;
    
        var storeselected =false;
        advert = advertiserid;

        if (numstores != "0") 
        {
            var ddindex = eval("document.reqInfoForm.store.options[document.reqInfoForm.store.selectedIndex].value");
            if (ddindex == "")
            {
                alert("Select a Store");
                return false;
            }
            else
            {
                stores =  ddindex;
            }
        }
        if (stores != "") stores="&store="+stores; else stores="&store=";
        
        var pid = "&pid="+pictureid+"&brand="+document.reqInfoForm.hidbrand.value;
        var otherval = "&pnum="+document.reqInfoForm.hidprodnum.value+"&pname="+document.reqInfoForm.hidprodname.value;
        
        window.open("storedata.php?adver="+advert+stores+pid+otherval,"myNewWin","width=480,height=570,scrollbars=yes,toolbar=0,resizable=yes"); 
    }

    function changeStyle(style)
    {
        document.frm1.ddstyle.value = style.value;
        document.frm1.submit();
    }
    function changeRoom(room)
    {
        document.frm1.ddRoom.value = room.value;
        document.frm1.ddpiece.value = '';
        document.frm1.submit();
    }
    function changePiece(piece)
    {
        document.frm1.ddpiece.value = piece.value;
        document.frm1.submit();
    }
    function changeBrand(brand)
    {
        document.frm1.ddbrand.value = brand.value;
        document.frm1.submit();
    }
    function changeMaterial(material)
    {
        document.frm1.ddmaterial.value = material.value;
        document.frm1.submit();
    }
    
    // Below functions for changing using footer
    
    function changeStyleFooter(style)
    {
        document.frm1.ddRoom.value = '';
        //document.frm1.ddstyle.value = style;
        document.frm1.ddpiece.value = '';
        document.frm1.ddbrand.value = '';
        document.frm1.ddmaterial.value = '';
        document.frm1.submit();
    }
    function changeRoomFooter(room)
    {
        document.frm1.ddRoom.value = room;
        //document.frm1.ddstyle.value = '';
        document.frm1.ddpiece.value = '';
        document.frm1.ddbrand.value = '';
        document.frm1.ddmaterial.value = '';
        document.frm1.submit();
    }
    function changePieceFooter(piece)
    {
        document.frm1.ddRoom.value = '';
        //document.frm1.ddstyle.value = '';
        document.frm1.ddpiece.value = piece;
        document.frm1.ddbrand.value = '';
        document.frm1.ddmaterial.value = '';
        document.frm1.submit();
    }
    function changeBrandFooter(brand)
    {
 
        document.frm1.ddRoom.value = '';
        //document.frm1.ddstyle.value = '';
        document.frm1.ddpiece.value = '';
        document.frm1.ddbrand.value = brand;
        document.frm1.ddmaterial.value = '';
        document.frm1.submit();
    }
    function changeMaterialFooter(material)
    {
        document.frm1.ddRoom.value = '';
        //document.frm1.ddstyle.value = '';
        document.frm1.ddpiece.value = '';
        document.frm1.ddbrand.value = '';
        document.frm1.ddmaterial.value = material;
        document.frm1.submit();
    }
    
    
        // Below functions for changing using footer on Home Page
    
    function changeStyleHomeFooter(style)
    {
        document.frmtxt[1].ddRoom.value = '';
        document.frmtxt[1].ddstyle.value = style;
        document.frmtxt[1].ddbrand.value = '';
        document.frmtxt[1].submit();
    }
    function changepieceHomeFooter(piece)
    {
        document.frmtxt[1].ddRoom.value = '';
        document.frmtxt[1].ddpiece.value = piece;
        document.frmtxt[1].ddbrand.value = '';
        document.frmtxt[1].submit();
    }
    function changeRoomHomeFooter(room)
    {
        document.frmtxt[1].ddRoom.value = room;
        //document.frmtxt[1].ddstyle.value = '';
        document.frmtxt[1].ddpiece.value = '';
        document.frmtxt[1].ddbrand.value = '';
        document.frmtxt[1].submit();
    }
     function changeBrandHomeFooter(brand)
    {
        document.frmtxt[1].ddRoom.value = '';
        //document.frmtxt[1].ddstyle.value = '';
        document.frmtxt[1].ddpiece.value = '';
        document.frmtxt[1].ddbrand.value = brand;
        document.frmtxt[1].submit();
    }
    
    function validateHomeKeywords( ){
      if (document.getElementById( "TxtSearch").value =="" ){
        document.getElementById( "TxtSearch").value = " ";
      } 
    }
    
    
    
    
var xmlhttp;

function addFav(spanobj, str)
{
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }
  var url="addfav.php";
  url=url+"?"+str;
 
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);


function stateChanged()
{
  if (xmlhttp.readyState==4)
  {
    if(spanobj.innerHTML == "Remove from Favorites"){
      spanobj.innerHTML="Add to Favorites";
      spanobj.className = "addtofavlink";
    } else {
      spanobj.innerHTML="Remove from Favorites";
      spanobj.className = "remfromfavlink";
    }
  }
}
}


function addFavDisplayImage(spanobj, str)
{
  xmlhttp=GetXmlHttpObject();
 
  if (xmlhttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }
  var url="addfav.php";
  url=url+"?"+str;
 
  xmlhttp.onreadystatechange=stateChangedDisplayImage;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);


function stateChangedDisplayImage()
{
  if (xmlhttp.readyState==4)
  {
    if(spanobj.innerHTML == "Remove from Favorites"){
      spanobj.innerHTML="Add to Favorites";
      spanobj.className = "addtofavlinkDisplayImage";
    } else {
      spanobj.innerHTML="Remove from Favorites";
      spanobj.className = "remfromfavlinkDisplayImage";
    }
  }
}
}
function GetXmlHttpObject()
{
  if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject)
  {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

