<!--
/** Base64 encodes a string into a base64 or UTF-8 encoded string
	and also decodes the encoded string. Interchangeable with
	Usage Examples:
	  Base 64:
		encoded_str = Base64.encode("input");
			or
		decoded_str = Base64.decode("input");
	  UTF-8:
	  	encoded_utf_str = Base64.utf8_encode(input);
	  		or
	  	decoded_utf_str = Base64.utf8_decode(input);
*/
var Base64 = {
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64.utf8_encode(input);

		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = Base64.utf8_decode(output);
		return output;
	},

	// public method for UTF-8 encoding
	utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},

	// public method for UTF-8 decoding
	utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}


var submitcount=0;
function submitonce()
{
	if(submitcount == 0)
	{
		submitcount++;
		return true;
	}
	else
	{
		alert("This form has already been submitted.  Thanks!");
		return false;
	}
}

function popUp (url,width,height,elements,newWindowName)
{
	newWindowName = (typeof(newWindowName) != 'undefined')? newWindowName : "newWindow";
	elements = (typeof(elements) != 'undefined')? elements : 1;

	newWindowName = newWindowName.replace(/ /g,"_");

	if (elements==0)
		elements = 'width='+width+',height='+height;
	else
		elements = 'width='+width+',height='+height+',location=no,menubar=no,resizable=yes,screenX=30,left=30,screenY=30,top=30,scrollbars=yes,status=no,toolbar=no';

	ElementWindow = window.open(url,newWindowName,elements);
}

function helpPop(type)
{
	ElementWindow = window.open('/admin/help/helpPop.php?type=' + type,'popNewPoint','width=400,height=425,location=no,menubar=no,resizable=yes,screenX=30,left=30,screenY=30,top=30,scrollbars=yes,status=no,toolbar=no');
}

function changeVisibility(show,divElementName)
{
	changeVisibilty(show,divElementName);
}
function changeVisibilty(show,divElementName)
{
	if (divElementName != "" && document.getElementById(divElementName))
	{
		divElement=document.getElementById(divElementName);

		if (show)
		{
			//alert ("Show: "+divElementName);
			divElement.style.visibility='visible';
			divElement.style.display='inline';
		}
		else
		{
			//alert ("Hide: "+divElementName);
			divElement.style.visibility='hidden';
			divElement.style.display='none';
		}
	}
}

function showColapse(show,tdElementName)
{
	element=document.getElementById(tdElementName);
	if (show)
	{
		//alert ("Show: "+divElementName);
		element.style.visibility='visible';
		divElement.style.display='table-row';
	}
	else
	{
		//alert ("Hide: "+divElementName);
		element.style.visibility='hidden';
		divElement.style.display='none';
	}
}

function toggleVisibilty(divElementName)
{
	divElement=document.getElementById(divElementName);
	if (divElement.style.display == 'none' || divElement.style.visibility =='hidden')
	{
		//alert ("Show: "+divElementName);
		divElement.style.visibility='visible';
		divElement.style.display='inline';
	}
	else
	{
		//alert ("Hide: "+divElementName);
		divElement.style.visibility='hidden';
		divElement.style.display='none';
	}
}

function highLight(element,color)
{
	if(document.defaultView)
	{
		currentStyle=document.defaultView.getComputedStyle(element,'');
		element.oldColor=currentStyle.getPropertyValue('background-color');
		element.style.backgroundColor=color;
	}
	else if( element.currentStyle)
	{
		element.oldColor=element.currentStyle.backgroundColor;
		element.style.backgroundColor=color;
	}

}

function closeWindow(message)
{
	//		var message;
	//		message = \"Would you like to refresh the category list page with any changes?\";
	if (confirm(message))
	{
		opener.location.href = opener.location+"&reloadMe=1";
	}
	window.close();
}

function deHighLight(element)
{

	if (element.oldColor)
	{
		element.style.backgroundColor=element.oldColor;
	}
	else
	{
		element.style.backgroundColor='white';
	}
}

// Used in admin side... may be used in front end too.
//path added 20110302 and is optional; gets set to ''
function viewImage (varname,id,type,sid,path)
{
	if (id<=0 || id=='' ||
	varname<=0 || varname=='' ||
	type<=0 || type=='' ||
	sid<=0 || sid==''){ alert ('missing information!'); return false; }
	if (path == undefined) path = '';
	url = path+"viewPop.php?"+sid+"&"+varname+"="+id+"&type="+type;
	elements = 'width=750,height=590,location=yes,menubar=yes,resizable=yes,screenX=30,left=30,screenY=30,top=30,scrollbars=yes,status=yes,toolbar=no';
	ElementWindow = window.open(url,'popView',elements);
}

function Trim(s)
{
	// Remove leading spaces and carriage returns

	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{
		s = s.substring(1,s.length);
	}

	// Remove trailing spaces and carriage returns

	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}


function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}


function xTableRowDisplay(bShow, sec, nRow)
{
  sec = xGetElementById(sec);
  if (sec && nRow < sec.rows.length) {
    sec.rows[nRow].style.display = bShow ? '' : 'none';
  }
}
//var longtext;
//longtext = "     test     \n";
//longtext = Trim(longtext);
//alert (">"+longtext+"<");

var oiProofConfirm = false;
function launchViewer(loc1,loc2){
	loc2 = Base64.decode(loc2);
	var browser=navigator.userAgent;
	re = /(MSIE 7)/i;
	if (browser.match(re)){
		if (!(oiProofConfirm)){
			if (confirm("Popups are required for this feature.\nHave you enabled Popups?")){
				oiProofConfirm = true;
			}
		}
		if (oiProofConfirm){
			var lvTimerID01 = setTimeout("proofwin=window.open('" + loc1 + "','OIProof','toolbar=0,location=0,menubar=0,resizable=1,status=0,statusbar=0,scrollbars=0,width=5,height=5')", 50);
			var lvTimerID02 = setTimeout("proofwin.moveTo(100000,100000)", 150);
			var lvTimerID03 = setTimeout("location.href='" + loc2 + "'", 5000);
			var lvTimerID04 = setTimeout("proofwin.close()",15000);
			oiProofConfirm = true;
		}
	}else{
		document.getElementById("fra_oiproof").src = loc1;
		var lvTimerID01 = setTimeout("location.href='" + loc2 + "'", 5000);
	}
}

x = -260;
y = -50;
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible')?'hidden':'visible';
}

function placeIt(obj, e)
{
	var x = -220;
	var y = -50;
	obj = document.getElementById(obj);
	if(typeof( window.pageYOffset) == "number") {
		//Netscape compliant
		// scrOfY = e.pageY + window.pageYOffset; // Add horizontal scroll
		// scrOfX = e.pageX + window.pageXOffset; // Add vertical scroll
		scrOfY = e.pageY;
		scrOfX = e.pageX;
		x = x - 40;
	}else if( document.body && ( document.body.scrollLeft || document.body.scrollTop )){
		//DOM compliant
		scrOfY = event.clientY + document.body.scrollTop;
		scrOfX = event.clientX + document.body.scrollLeft;
	}else if( document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop )){
		//IE6 standards compliant mode
		scrOfY = event.clientY + document.documentElement.scrollTop;
		scrOfX = event.clientX + document.documentElement.scrollLeft;
	}else{
		//IE7 standards compliant
		scrOfY = event.clientY + document.documentElement.scrollTop;
		scrOfX = event.clientX + document.documentElement.scrollLeft;
	}
	scrOfX += x;
	scrOfY += y;
	obj.style.left = scrOfX + 'px' ;
	obj.style.top = scrOfY + 'px' ;
}

function getWindowSize()
{
	var winWidth = 0
	var winHeight = 0;
	var winSize = new Array();

	if (typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}

	winSize["Width"] = winWidth;
	winSize["Height"] = winHeight;

	return winSize;
}

function centerDiv(zLayer,zLayerWidth,zLayerHeight,zVisible,zRefresh,zRefreshRate,zPosition)
{
	zRefresh = (typeof(zRefresh) != 'undefined')? zRefresh : "yes";
	zRefreshRate = (typeof(zRefreshRate) != 'undefined')? zRefreshRate : 25;
	zRefreshRate = (isNaN(zRefreshRate))? 25 : zRefreshRate;
	zPosition = (typeof(zPosition) != 'undefined')? zPosition : "center";

	var obj = document.getElementById(zLayer);
	var winSize = getWindowSize();

	var divWidth = winSize["Width"];
	var divHeight = winSize["Height"];

	if(typeof( window.pageYOffset) == "number")
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ))
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop ))
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}else{
		//IE7 standards compliant, I guess
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}

	switch (zPosition)
	{
		case ("bottom"):
			posx = 0;
			posy = ((divHeight+scrOfY) - zLayerHeight);
			break;

		default:
		case ("center"):
			// Use this setting if your div is already centered and taking up 100% width.
			if (zLayerHeight == 0 && zLayerWidth == 0)
			{
				posx = 0;
				posy = scrOfY;
			}
			else
			{
				posx = ((Number(divWidth)/2) - (Number(zLayerWidth)/2)) + scrOfX;
				posy = ((Number(divHeight)/2) - (Number(zLayerHeight)/2)) + scrOfY;
			}
		break;
	}
/*
alert("posx: " + posx + " \n posy:" + posy + " \n divWidth:" + divWidth +
		" \n divHeight:" + divHeight + " \n zLayerWidth:" + zLayerWidth +
		" \n zLayerHeight:" + zLayerHeight + " \n scrOfX:" + scrOfX +
		" \n scrOfY:" + scrOfY);
*/
	obj.style.left = posx + 'px';
	obj.style.top = posy + 'px';

	if (zVisible == "yes")
		changeVisibilty(true,zLayer);

	if (zRefresh == "yes")
	{
		// We are hardcoding zVisible to no when we call the function again. If zVisible is always yes then the div will never be hidden.
		var params = "'"+zLayer+"',"+zLayerWidth+","+zLayerHeight+",'no','"+zRefresh+"',"+zRefreshRate+",'"+zPosition+"'";
		setTimeout("centerDiv("+params+")", 25);
	}
}

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
  	}
}

function setPulldown(pd_id,newVal)
{
	var mypd=document.getElementById(pd_id)
	for (var i=0; i<mypd.options.length; i++)
	{
		if (mypd.options[i].value==newVal)
		{
			mypd.options[i].selected = true;
			break;
		}
	}
	mypd.value = newVal;
}

function checkObjValue(obj)
{
	var re = /^[a-zA-Z_0-9]+$/;
	if (!(re.test(obj.value)))
	{
		alert("Please enter alphanumeric characters only.");
		obj.value = obj.value.replace(/([^a-zA-Z0-9])/g,"");
	}
}
// -->
