var openmenu = '';
var state = false;

function doRollovr(a,b) {
	document.images[b].src = a;
}
function goback() {
	window.history.back();
}
function popUP(mypage, myname, w, h, scroll, titlebar) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=0'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}
function checkList(newlist,prefix) {
	var newlist1 = new Array();
	var returnobj = new Object();
	returnobj.found = null;
	returnobj.remove = null;

	for (x in newlist) {
		var str = newlist[x].toString();
		var arr = str.split(':',3);
	
		if (arr[0] == 'tracklist') {
			returnobj.found = arr[2];
			returnobj.remove = prefix + newlist[x];
		} else {
			newlist1[arr[2]] = '';
		}
	}
					
	if (returnobj.found in newlist1) {
		return returnobj;
	}

	return false;
}
function confirmDelete(webroot,model,row_id) {
	var conf = confirm('Do you really want to delete this? This CANNOT be undone.');
	if (conf === true) {
		window.location = webroot + 'remove.php?m=' + model + '&i=' + row_id;
	}
}
function ajaxUpdateNoBlind(script, elemid, pid, num) {
	updater2 = new Ajax.Updater(
		elemid,
		script + '.php',
		{
			method:'get',
			parameters:{pid:pid,pn:num}
		}
	);
}
function ajaxGallThumbMenu(script, elemid, gall, page, ogid) {
	updater2 = new Ajax.Updater(
		elemid,
		script,
		{
			method:'get',
			parameters:{gid:gall, page:page, ogid:ogid}
		}
	);
}
function justOpenClose(elemid, dur) {
	if ($(elemid).style.display == 'none') {
		state = false;
		Effect.BlindDown(elemid,{ duration:dur });
	} else {
		state = true;
		Effect.BlindUp(elemid,{ duration:dur });
	}
}
function OpenClose(elemid,dur) {
	if (openmenu != '' && openmenu != elemid) {
		Effect.BlindUp(openmenu,{ duration:dur });
	}

	if (state) {
		state = false;
		Effect.BlindUp(elemid,{ duration:dur });
	} else {
		state = true;
		Effect.BlindDown(elemid,{ duration:dur });
	}

	openmenu = elemid;
}
function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}
