﻿
function doGalleryPopUP(divobj, displayBox, title, pid, spid ) {
    this.divobj = divobj;
    divobj.style.cursor = 'wait';
    displayBoxPos = findElementPos(document.getElementById(displayBox));
    PopupCallback("AddItem", "&disp=Gallery&pid=" + pid + "&spid=" + spid + "&title=" + title);
}

function doWLPopUP(divobj, displayBox, title, pid, spid ) {
    this.divobj = divobj;
    divobj.style.cursor = 'wait';
    displayBoxPos = findElementPos(document.getElementById(displayBox)); 
    PopupCallback("AddItem", "&disp=Wish%20List&pid=" + pid + "&spid=" + spid + "&title=" + title);
}

function doDeleteItem(divobj, event, xoff, yoff, gname, title, gtype, url)
{
    this.divobj = divobj;
    divobj.style.cursor = 'wait';
    findMousePos(event);
    displayBoxPos = [x+xoff, y+yoff];
    url = replaceDashDash(url);
    PopupCallback("DeleteItem", "&gname=" + gname + "&gtype=" + gtype + "&title=" + title + "&url=" + escape(url));
}

function doMoveItem(divobj, event, xoff, yoff, oid, galleryid, gt, startAt, grid, count)
{
    this.divobj = divobj;
    divobj.style.cursor = 'wait';
    findMousePos(event);
    displayBoxPos = [x+xoff, y+yoff];
    PopupCallback("MoveItem", "&oid=" + oid + "&galleryid=" + galleryid + "&gt=" + gt + "&startAt=" + startAt + "&grid=" + grid + "&count=" + count);
}

function doDeleteWLLising(divobj, event, xoff, yoff, gtype, url, gname)
{
    this.divobj = divobj;
    divobj.style.cursor = 'wait';
    findMousePos(event);
    displayBoxPos = [x+xoff, y+yoff];
    url = replaceDashDash(url);
    PopupCallback("DeleteWLListing", "&gtype=" + gtype + "&gname=" + gname + "&url=" + escape(url));
}

function replaceDashDash(url)
{
   return url = url.replace(/--/g,"@dashdash");
}

function getRadioButtonValue(radiobutton)
{
	for (i=0; i<radiobutton.length; i++){
		if(radiobutton[i].checked) return radiobutton[i].value;
	}
	return "not found";
}

function lightencryption(str)
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var key = "";
    for (var i=0; i<str.length; i++)
    {
		var rnum = Math.floor(Math.random() * chars.length);
        key += str.substring(i, i+1) + chars.substring(rnum, rnum+1);
    }
    var len = key.length/2;
    return "&dw=" + escape(reverseString(key.substring(len, 2*len))) + "&sp=" + escape(reverseString(key.substring(0, len)));
}
      
function reverseString(theString) {
    theString = theString.replace(/%/g, "@(percent)");
    var counter = theString.length;
    var newString = "";

    for (counter  ;counter > 0 ;counter -- ) { 
     newString += theString.substring(counter-1, counter); 
    } 
    return newString;
}

function replaceSingleQuote(str)
{
    return str.replace(/'/g, "@(singlequote)");
}

function removeSingleQuote(str)
{
    return str.replace(/'/g, "");
}

function checkFavorites(name)
{
    var createLabel = document.getElementById("createLabel");
    var createText = document.getElementById("createText");
    var createRadio = document.getElementById("createRadio");
    if(createRadio.checked)
    {
        createLabel.innerHTML = "<br />e.g. Favorites, Living Room, For Mom <br />";
        createText.style.display = 'block';
    }
    else
    {
        createLabel.innerHTML = "&nbsp;<br />Create a New " + name + "<br /><br />";
        createText.style.display = 'none';
    }
    document.getElementById('error1').style.display = 'none';
    document.getElementById('error2').style.display = 'none';
}