//<script>
//****************************************************************
// DHTML Detection
var isDHTMLw3c = false;
var isDHTMLie4 = false;
var isDHTMLns4 = false;
if (document.getElementById){
	isDHTMLw3c=true;
}else if (document.all) {
	isDHTMLie4=true;
}else if (document.layers) {
	isDHTMLns4=true;
}
//****************************************************************


function isblank(s) {
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}
function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}
function encodeSpecialChars(s) {
	var o;
	o = s;
/*	// Having problems with javascript errors

	o = replace(o,'$','&#36;');
	o = replace(o,'ß','&#223;');
	o = replace(o,'ä','&#228;');
	o = replace(o,'¢','&#162;');
	o = replace(o,'£','&#163;');
	o = replace(o,'¤','&#164;');
	o = replace(o,'¥','&#165;');
	o = replace(o,'¦','&#166;');
	o = replace(o,'§','&#167;');
	o = replace(o,'¨','&#168;');
	o = replace(o,'©','&#169;');
	o = replace(o,'ª','&#170;');
	o = replace(o,'«','&#171;');
	o = replace(o,'®','&#174;');
	o = replace(o,'¯','&#175;');
	o = replace(o,'°','&#176;');
	o = replace(o,'±','&#177;');
	o = replace(o,'²','&#178;');
	o = replace(o,'³','&#179;');
	o = replace(o,'´','&#180;');
	o = replace(o,'µ','&#181;');
	o = replace(o,'·','&#183;');
	o = replace(o,'¸','&#184;');
	o = replace(o,'¹','&#185;');
	o = replace(o,'º','&#186;');
	o = replace(o,'»','&#187;');
	o = replace(o,'¼','&#188;');
	o = replace(o,'½','&#189;');
	o = replace(o,'¾','&#190;');
	o = replace(o,'¿','&#191;');
	o = replace(o,'À','&#192;');
	o = replace(o,'Á','&#193;');
	o = replace(o,'Â','&#194;');
	o = replace(o,'Ã','&#195;');
	o = replace(o,'Ä','&#196;');
	o = replace(o,'Å','&#197;');
	o = replace(o,'Æ','&#198;');
	o = replace(o,'Ç','&#199;');
	o = replace(o,'È','&#200;');
	o = replace(o,'É','&#201;');
	o = replace(o,'Ê','&#202;');
	o = replace(o,'Ë','&#203;');
	o = replace(o,'Ì','&#204;');
	o = replace(o,'Í','&#205;');
	o = replace(o,'Î','&#206;');
	o = replace(o,'Ï','&#207;');
	o = replace(o,'Ð','&#208;');
	o = replace(o,'Ñ','&#209;');
	o = replace(o,'Ò','&#210;');
	o = replace(o,'Ó','&#211;');
	o = replace(o,'Ô','&#212;');
	o = replace(o,'Õ','&#213;');
	o = replace(o,'Ö','&#214;');
	o = replace(o,'×','&#215;');
	o = replace(o,'Ø','&#216;');
	o = replace(o,'Ù','&#217;');
	o = replace(o,'Ú','&#218;');
	o = replace(o,'Û','&#219;');
	o = replace(o,'Ü','&#220;');
	o = replace(o,'Ý','&#221;');
	o = replace(o,'Þ','&#222;');
	o = replace(o,'ß','&#223;');
	o = replace(o,'à','&#224;');
	o = replace(o,'á','&#225;');
	o = replace(o,'â','&#226;');
	o = replace(o,'ã','&#227;');
	o = replace(o,'ä','&#228;');
	o = replace(o,'å','&#229;');
	o = replace(o,'æ','&#230;');
	o = replace(o,'ç','&#231;');
	o = replace(o,'è','&#232;');
	o = replace(o,'é','&#233;');
	o = replace(o,'ê','&#234;');
	o = replace(o,'ë','&#235;');
	o = replace(o,'ì','&#236;');
	o = replace(o,'í','&#237;');
	o = replace(o,'î','&#238;');
	o = replace(o,'ï','&#239;');
	o = replace(o,'ð','&#240;');
	o = replace(o,'ñ','&#241;');
	o = replace(o,'ò','&#242;');
	o = replace(o,'ó','&#243;');
	o = replace(o,'ô','&#244;');
	o = replace(o,'õ','&#245;');
	o = replace(o,'ö','&#246;');
	o = replace(o,'÷','&#247;');
	o = replace(o,'ø','&#248;');
	o = replace(o,'ù','&#249;');
	o = replace(o,'ú','&#250;');
	o = replace(o,'û','&#251;');
	o = replace(o,'ü','&#252;');
	o = replace(o,'ý','&#253;');
	o = replace(o,'þ','&#254;');
	o = replace(o,'ÿ','&#255;');
*/
	return o;
}

function FormByIndex(idx) {
	if (isDHTMLw3c || isDHTMLie4) {
		var f = eval('document.forms[idx]');
    } else if (isDHTMLns4) {
        var f = eval('document.layers[idx]' + '.document.forms[0]');
    }
    return f;
}
function SetSubmitFlag(f) {
	f.elements["hidFormSubmited"].value = "1";
	return (true);
}
function SelectAllOptions(f,sListBox) {
	var oSelect = f.elements[sListBox];
	for (var i = 0; i < oSelect.options.length; i++) {
		oSelect.options[i].selected = true;
	}
}
function URLencode(s) {
	//var sOut = s.replace(/\./g,'%25E');
	//sOut = escape(sOut);
	//return sOut;
	
	return escape(s);
}
function setPicGroup(lst) {
	switch (lst.value) {
		case "NEW" :
			var sHref = location.href;
			var sHrefNew = sHref.substr(0,sHref.lastIndexOf('/')+1) + "AlbumAdd.asp?from=";
			var sFileFrom = sHref.substr(sHref.lastIndexOf('/')+1,sHref.length);
			location.href = sHrefNew + escape(sFileFrom);
	}
}
function gotolastmodify(sKeyPath) {
	var aryID
	if (sKeyPath != '') {
		aryID = sKeyPath.split('|');
		if(aryID.length>1){
			var sHref = location.href;
			var sHrefNew = sHref.substr(0,sHref.lastIndexOf('/')+1) + "PageOptions.asp?keypath=";
			var sKeyPath = sKeyPath.substr(0,sKeyPath.lastIndexOf('|'));
			location.href = sHrefNew + sKeyPath;
		} else {
		}
	}
}
function preview(sMode, sListBoxName) {
	//  INPUT: name of listbox containing image files
	// ACTION: Opens a modal window to display chosen item in <SELECT id=select1 name=select1>
	//         element that is named "lstAssets.
	// NOTE 1: <OPTION> values contain four fields each, delimted by "^"
	//				Field 1 - Asset ID
	//				Field 2 - Image Width
	//				Field 3 - Image Height
	//				Field 4 - File Name
	// NOTE 2: Works in conjunction with Cassets.HTMLAssetList()
	var f = document.form;
    var e = f.elements[sListBoxName];
    if (e.selectedIndex >= 0) {
		var sValSelect = e.options[e.selectedIndex].value;
		var aryAssetInfo = sValSelect.split('^');
		var nIDasset = aryAssetInfo[0];
		var nImgWidth = aryAssetInfo[1];
		var nImgHeight = aryAssetInfo[2];
		if (sMode == 'ASSET') {
			openDialog('FilePreview.asp?id='+nIDasset+','+nImgWidth+','+nImgHeight,nImgWidth,nImgHeight);
		} else if (sMode == 'TEMPLATEIMAGE') {
			openDialog('TemplateVisualPreview.asp?id='+nIDasset,nImgWidth,nImgHeight);
		}
	}
}
function resetSessionCountdown() {
	// reset session timer
	var ftop = eval('window.parent.frames["topFrame"]');
	if (ftop) {
		if (ftop.document) {
			var sURL = ftop.document.URL.toLowerCase();
			if (sURL.indexOf('top.asp',0)!= -1) {
				if(ftop.PageLoaded)	{
					// reset session countdown timer
					ftop.InitializeTimer();
				} else {
					// wait a second, then try again.
					setTimeout("resetSessionCountdown()",1000);
				}
			}
		}
	}
	return;
}
function displayUndefinedErrorMsg() {
	alert('WARNING: The popup editor experienced an error during close operations.  Changes could NOT be saved.  \n\n\t HINT: Always close the editor with the [Cancel] or [Save] buttons and, do not use or re-size the pop-up editor until it has completed loading');
}
