<!--
function displayWindowViewImage() { window.open(document.transfer.transfer1.value+'','view_image','width=655,height=580,scrollbars=yes,resizable=yes'); }
function displayWindowStoProductDetail() { window.open(document.transfer.transfer1.value+'','product_detail','width=350,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowThemeBrowser() { window.open(document.transfer.transfer1.value+'','theme_browser','width=580,height=450,scrollbars=yes,resizable=yes'); }
function displayWindowNewsMaker() { window.open(document.transfer.transfer1.value+'','news_maker','width=500,height=500,scrollbars=yes,resizable=yes'); }
function displayWindowSiteSetup() { window.open(document.transfer.transfer1.value+'','site_setup','width=520,height=595,scrollbars=yes,resizable=yes'); }
function displayWindowSiteMap() { window.open(document.transfer.transfer1.value+'','site_map','width=575,height=600,scrollbars=yes,resizable=yes'); }
function displayWindowPageSetup() { window.open(document.transfer.transfer1.value+'','page_setup','width=550,height=370,scrollbars=yes,resizable=yes'); }
function displayWindowContainerSetup() { window.open(document.transfer.transfer1.value+'','container_setup','width=600,height=450,scrollbars=yes,resizable=yes'); }
function displayWindowContentSetup() { window.open(document.transfer.transfer1.value+'','content_setup','width=520,height=560,scrollbars=yes,resizable=yes'); }
function displayWindowOrderSetup() { window.open(document.transfer.transfer1.value+'','order_setup','width=450,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowViewLog() { window.open(document.transfer.transfer1.value+'','log_view','width=500,height=400,scrollbars=yes,resizable=yes'); }
function displayWindowUserSetup() { window.open(document.transfer.transfer1.value+'','user_setup','width=650,height=600,scrollbars=yes,resizable=yes'); }
function displayWindowUserSearch() { window.open(document.transfer.transfer1.value+'','user_search','width=650,height=600,scrollbars=yes,resizable=yes'); }
function displayWindowHelp() { window.open(document.transfer.transfer1.value+'','help','width=500,height=400,scrollbars=yes,resizable=yes'); }
function displayWindowPhotoSetup() { window.open(document.transfer.transfer1.value+'','photo_setup','width=500,height=400,scrollbars=yes,resizable=yes'); }
function displayWindowTopicSetup() { window.open(document.transfer.transfer1.value+'','topic_setup','width=540,height=500,scrollbars=yes,resizable=yes'); }
function displayWindowPersonSetup() { window.open(document.transfer.transfer1.value+'','person_setup','width=540,height=500,scrollbars=yes,resizable=yes'); }
function displayWindowSecuritySetup() { window.open(document.transfer.transfer1.value+'','security_setup','width=525,height=400,scrollbars=yes,resizable=yes'); }
function displayWindowQuickPollItemSetup() { window.open(document.transfer.transfer1.value+'','quickpollitem_setup','width=450,height=250,scrollbars=yes,resizable=yes'); }
function displayWindowPollSetup() { window.open(document.transfer.transfer1.value+'','poll_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowAreaManager() { window.open(document.transfer.transfer1.value+'','area_manager','width=530,height=675,scrollbars=yes,resizable=yes'); }
function displayWindowPageAreaManager() { window.open(document.transfer.transfer1.value+'','page_area_manager','width=530,height=560,scrollbars=yes,resizable=yes'); }
function displayWindowSubcustomer() { window.open(document.transfer.transfer1.value+'','subcustomer','width=500,height=450,scrollbars=yes,resizable=yes'); }
function displayWindowCustomer() { window.open(document.transfer.transfer1.value+'','customer','width=500,height=450,scrollbars=yes,resizable=yes'); }
function displayWindowRatingManager() { window.open(document.transfer.transfer1.value+'','rating_manager','width=500,height=500,scrollbars=yes,resizable=yes'); }
function displayWindowPopupManager() { window.open(document.transfer.transfer1.value+'','popup_manager','width=580,height=330,scrollbars=yes,resizable=yes'); }
function displayWindowStoSetup() { window.open(document.transfer.transfer1.value+'','sto_setup','width=605,height=605,scrollbars=yes,resizable=yes'); }
function displayWindowStoreMap() { window.open(document.transfer.transfer1.value+'','store_map','width=550,height=520,scrollbars=yes,resizable=yes'); }
function displayWindowProductSearch() { window.open(document.transfer.transfer1.value+'','sto_product_search','width=550,height=550,scrollbars=yes,resizable=yes'); }
function displayWindowDepartmentManager() { window.open(document.transfer.transfer1.value+'','sto_department_manager','width=550,height=550,scrollbars=yes,resizable=yes'); }
function displayWindowProductManager() { window.open(document.transfer.transfer1.value+'','sto_product_manager','width=550,height=550,scrollbars=yes,resizable=yes'); }
function displayWindowDeptSetup() { window.open(document.transfer.transfer1.value+'','dept_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowProductSetup() { window.open(document.transfer.transfer1.value+'','product_setup','width=520,height=480,scrollbars=yes,resizable=yes'); }
function displayWindowFeaturedSetup() { window.open(document.transfer.transfer1.value+'','sto_featured_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowStoColorSetup() { window.open(document.transfer.transfer1.value+'','sto_color_setup','width=400,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowStoSizeSetup() { window.open(document.transfer.transfer1.value+'','sto_size_setup','width=400,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowStoWidthSetup() { window.open(document.transfer.transfer1.value+'','sto_width_setup','width=400,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowStoCouponSetup() { window.open(document.transfer.transfer1.value+'','sto_coupon_setup','width=525,height=400,scrollbars=yes,resizable=yes'); }
function displayWindowStoSalesTaxSetup() { window.open(document.transfer.transfer1.value+'','sto_sales_tax_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowStoSalesReports() { window.open(document.transfer.transfer1.value+'','sto_sales_reports','width=520,height=580,scrollbars=yes,resizable=yes'); }
function displayWindowFormManager() { window.open(document.transfer.transfer1.value+'','form_manager','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowCalendarManager() { window.open(document.transfer.transfer1.value+'','divcal_date_admin','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindoweCardSetup() { window.open(document.transfer.transfer1.value+'','ecard_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowScheduleSetup() { window.open(document.transfer.transfer1.value+'','schedule_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowFeedList() { window.open(document.transfer.transfer1.value+'','schedule_setup','width=600,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowContactGroupEdit() { window.open(document.transfer.transfer1.value+'','contact_group_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowContactEdit() { window.open(document.transfer.transfer1.value+'','contact_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowECardEdit() { window.open(document.transfer.transfer1.value+'','ecard_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowAssetManager() { window.open(document.transfer.transfer1.value+'','ass_man','width=550,height=400,scrollbars=yes,resizable=yes'); }
function displayWindowKeywordSetup() { window.open(document.transfer.transfer1.value+'','keyword_setup','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowForumManager() { window.open(document.transfer.transfer1.value+'','forum_manager','width=500,height=350,scrollbars=yes,resizable=yes'); }
function displayWindowForumPost() { window.open(document.transfer.transfer1.value+'','forum_post','width=510,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowDropDownManager() { window.open(document.transfer.transfer1.value+'','forum_post','width=510,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowShippingSetup() { window.open(document.transfer.transfer1.value+'','shipping_setup','width=500,height=300,scrollbars=yes,resizable=yes'); }
function displayWindowColorChart() { window.open(document.transfer.transfer1.value+'','color_chart','width=420,height=550,scrollbars=yes,resizable=yes'); }
function displayWindowColorEdit() {window.open(document.transfer.transfer1.value+'','color_chart','width=420,height=550,scrollbars=yes,resizable=yes'); }
function displayWindowStyleChart() {window.open(document.transfer.transfer1.value+'','style_chart','width=500,height=500,scrollbars=yes,resizable=yes'); }
function displayWindowFileManager() {window.open(document.transfer.transfer1.value+'','file_manager','width=650,height=500,scrollbars=yes,resizable=yes'); }
function deleteConfirm(my_warning)
{
	if(!my_warning) { my_warning = 'Are you sure you want to do this?'; }
	return confirm(my_warning);
}

function displayWindow(theurl, thewindowname, doihavescrollbars, thewidth, theheight, amiresizable)
{
	if (!thewindowname) { thewindowname = 'Untitled'; }
	if (!doihavescrollbars) { doihavescrollbars = 'yes'; }
	if (!thewidth) { thewidth = 500; }
	if (!theheight) { theheight = 500; }
	if (!amiresizable) { amiresizable = 'yes'; }
	window.open(theurl, thewindowname, 'width='+thewidth+',height='+theheight+',scrollbars='+doihavescrollbars+',resizable='+amiresizable);
}

function setPointer(theRow, thePointerColor)
{
	if (thePointerColor == '' || typeof(theRow.style) == 'undefined') { return false; }
	if (typeof(document.getElementsByTagName) != 'undefined') { var theCells = theRow.getElementsByTagName('td'); }
	else if (typeof(theRow.cells) != 'undefined') { var theCells = theRow.cells; }
	else { return false; }
	var rowCellsCnt  = theCells.length;
	for (var c = 0; c < rowCellsCnt; c++) { theCells[c].style.backgroundColor = thePointerColor; }
	return true;
}

function hideObject(xObject)
{
	document.all ? document.all(xObject).style.visibility="hidden" : document.getElementById(xObject).style.visibility="hidden";
}

function showObject(xObject)
{
	document.all ? document.all(xObject).style.visibility="visible" : document.getElementById(xObject).style.visibility="visible";
}

function togglePane(xObject, xImage)
{
	if (document.getElementById(xObject).style.display == 'none')
	{
		document.getElementById(xObject).style.display = 'block';
		if(xImage) changeImg(xImage, disclosureDownGif.src);
	}
	else
	{
		document.getElementById(xObject).style.display = 'none';
		if(xImage) changeImg(xImage, disclosureRightGif.src);
	}
}

function toggleObjectDisplay(xObject)
{
	if (document.getElementById(xObject).style.display == 'none')
	{
		document.getElementById(xObject).style.display = '';
	}
	else
	{
		document.getElementById(xObject).style.display = 'none';
	}
}

// AJAX Code
// HTTP Request Object Generator
function createRequestObject()
{
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) {
		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {
			xmlhttp=null;
		}
	}
	if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
		xmlhttp=new XMLHttpRequest();
	}
	return xmlhttp;
}

var xmlhttp = createRequestObject();

// Sets the handler for the current request.
function setHandler(handler)
{
	if (handler && handler != '')
	{
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
			{
				handler();
			}
		}
	}
	else
	{
		xmlhttp.onreadystatechange = function()
		{
		}
	}
}

// Generic request/responce function using get request method.
function httpGet(url, getVars, handler)
{
	if (getVars && getVars != '')
	{
		url = url+'?'+getVars;
	}

	if (!handler)
	{
		handler = '';
	}

	xmlhttp.open('get', url);
	setHandler(handler);
	xmlhttp.send(null);
}

// Generic request/response function using post request method.
function httpPost(url, post, handler)
{
	if (!handler)
	{
		handler = '';
	}

	xmlhttp.open('post', url, true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	setHandler(handler);
	xmlhttp.send(post);
}

function getPos(elmnt, pos)
{
	var val = 0;
	var obj = elmnt;
	var safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;

	if (pos == 'top' || pos == 'bottom')
	{
		if (obj.y)
		{
			val = obj.y;
		}
		else
		{
			while (obj)
			{
				if (obj.offsetTop == 0 && obj.offsetLeft == 0 && safari)
				{
					obj = obj.parentNode;
				}
				else
				{
					val += obj.offsetTop || 0;
					obj = obj.offsetParent;
				}
			}
		}
		if (pos == 'bottom')
		{
			val += elmnt.offsetHeight || elmnt.height || 0;
		}
	}
	else if (pos == 'left' || pos == 'right')
	{
		if (obj.x)
		{
			val = obj.x;
		}
		else
		{
			while (obj)
			{
				if (obj.offsetLeft == 0 && obj.offsetTop == 0 && safari)
				{
					obj = obj.parentNode;
				}
				else
				{
					val += obj.offsetLeft || 0;
					obj = obj.offsetParent;
				}
			}
		}
		if (pos == 'right')
		{
			val += elmnt.offsetWidth || elmnt.width || 0;
		}
	}

	return val;
}

function hide_menu(elmnt)
{
	if (typeof elmnt == 'string')
	{
		elmnt = '#'+elmnt;
	}
	elmnt = jQuery(elmnt);

	elmnt.css('visibility', 'hidden');
}

function show_menu(elmnt, horizontal, relative)
{
	if (typeof elmnt == 'string')
	{
		elmnt = '#'+elmnt;
	}
	elmnt = jQuery(elmnt);

	if (relative)
	{
		if (typeof relative == 'string')
		{
			relative = '#'+relative;
		}
		relative = jQuery(relative);

		var coords = relative.offset();
		if (horizontal)
		{
			topshift = 0;
			leftshift = relative.width();
		} else {
			topshift = relative.height();
			leftshift = 0;
		}
		elmnt.css('top', coords.top + topshift);
		elmnt.css('left', coords.left + leftshift);
	}
	elmnt.css('visibility', 'visible');
}

// "drag" code
//browser detection
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
	&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

var dragapproved=false
var z,x,y
var maxleft,maxtop,maxright,maxbottom;

function setdragBounds(){
    //you can set the bounds of the draggable area here
    maxleft = 10;
    maxtop = 10;
    maxright = document.body.clientWidth - 10;
    maxbottom = document.body.clientHeight - 100;
}

function move(e){
    var tmpXpos = (!is_ie)? temp1+e.clientX-x: temp1+event.clientX-x;
    var tmpYpos = (!is_ie)? temp2+e.clientY-y : temp2+event.clientY-y;
    if (dragapproved){
            z.style.left = tmpXpos;
            z.style.top = tmpYpos;

        if(tmpXpos < maxleft)z.style.left = maxleft;
            if(tmpXpos > maxright)z.style.left = maxright;

        if(tmpYpos < maxtop)z.style.top = maxtop;
        if(tmpYpos > maxbottom)z.style.top = maxbottom;
        return false
    }
}

function drags(e){
    if (!(is_ie)&&!(!is_ie))
    return
    var firedobj=(!is_ie)? e.target : event.srcElement
    var topelement=(!is_ie)? "HTML" : "BODY"

    while (firedobj.tagName!=topelement && firedobj.className!="drag" && firedobj.tagName!='SELECT' && firedobj.tagName!='TEXTAREA' && firedobj.tagName!='INPUT' && firedobj.tagName!='IMG'){
        //you can add the elements that cannot be used for drag here. using their class name or id or tag names
        firedobj=(!is_ie)? firedobj.parentNode : firedobj.parentElement
    }

    if (firedobj.className=="drag"){
        dragapproved=true
        z=firedobj
        var tmpheight = z.style.height.split("px")
        maxbottom = (tmpheight[0])?document.body.clientHeight - tmpheight[0]:document.body.clientHeight - 20;

        temp1=parseInt(z.style.left+0)
        temp2=parseInt(z.style.top+0)
        x=(!is_ie)? e.clientX: event.clientX
        y=(!is_ie)? e.clientY: event.clientY
        document.onmousemove=move
        return false
    }
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")


js = document.createElement('script');
js.setAttribute('language', 'javascript');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', '/site/core_javascript.js');
document.getElementsByTagName('head').item(0).appendChild(js);

var blur_timers = new Array();
var focus_timers = new Array();

function addBlur(id, f, time)
{
	if (!time) time = 1000;

	if (focus_timers[id])
	{
		clearTimeout(focus_timers[id]);
	}
	blur_timers[id] = setTimeout(f, time);
}

function addFocus(id, f, time)
{
	if (!time) time = 100;

	if (blur_timers[id])
	{
		clearTimeout(blur_timers[id]);
	}
	focus_timers[id] = setTimeout(f, time);
}

function containerColumnActive(obj, id, col)
{
	if (obj)
	{
		var column_root = 'co'+id+'_col'+col;
		addFocus
		(
			column_root,
			function ()
			{
				obj.className = 'container_column_active';
			},
			101	// Slightly longer delay to make sure it's not overridden by the container active function
		);
	}
}

function containerColumnInactive(obj, id, col)
{
	if (obj)
	{
		var column_root = 'co'+id+'_col'+col;
		addBlur
		(
			column_root,
			function ()
			{
				obj.className = 'container_column_inactive';
			},
			999	// Make the delay shorter, so this doesn't override the container mouse-out
		);
	}
}

function containerActive(container_obj, container_id, container_cols, title, tools, borders)
{
	if (container_obj)
	{
		var container_root = 'co'+container_id;
		addFocus
		(
			container_root,
			function ()
			{
				var container_title = document.getElementById(container_root+'_title');
				var container_tabs = document.getElementById(container_root+'_tabs');
				var container_tools = document.getElementById(container_root+'_tools')

				container_obj.className = 'container_active';
				if (container_title)
				{
					container_title.style.backgroundColor = '#e5b673';
				}
				if (title)
				{
					if (container_title)
					{
						container_title.style.display = '';
					}
					if (container_tabs)
					{
						container_tabs.style.display = '';
					}
				}
				if (tools && container_tools)
				{
					container_tools.style.display = '';
				}

				for (col in container_cols)
				{
					col = container_cols[col];
					var col_root = container_root+'_col'+col;
					column = document.getElementById(col_root);

					if (column)
					{
						var column_add = document.getElementById(col_root+'_add');

						column.className = 'container_column_inactive';
						if (tools && column_add)
						{
							column_add.style.display = 'block';
						}
					}
				}
			}
		);
	}
}

function containerInactive(container_obj, container_id, container_cols, title, tools, borders)
{
	if (container_obj)
	{
		var container_root = 'co'+container_id;
		addBlur
		(
			container_root,
			function ()
			{
				var container_title = document.getElementById(container_root+'_title');
				var container_tabs = document.getElementById(container_root+'_tabs');
				var container_tools = document.getElementById(container_root+'_tools')

				if (borders) container_obj.className = 'container_hidden';
				else container_obj.className = 'container_inactive';
				if (container_title)
				{
					container_title.style.backgroundColor = '#e5b673';
				}
				if (title)
				{
					if (container_title)
					{
						container_title.style.display = 'none';
					}
					if (container_tabs)
					{
						container_tabs.style.display = 'none';
					}
				}
				if (tools && container_tools)
				{
					container_tools.style.display = 'none';
				}

				for (col in container_cols)
				{
					col = container_cols[col];
					var col_root = container_root+'_col'+col;
					column = document.getElementById(col_root);

					if (column)
					{
						var column_add = document.getElementById(col_root+'_add');

						if (borders) column.className = 'container_column_hidden';
						if (tools && column_add)
						{
							column_add.style.display = 'none';
						}
					}
				}
			}
		);
	}
}

function areaActive(area_obj, area_id, title, tools)
{
	if (area_obj)
	{
		var area_root = 'ar'+area_id;
		addFocus
		(
			area_root,
			function()
			{
				var area_title = document.getElementById(area_root+'_title');
				var area_tools = document.getElementById(area_root+'_tools');

				area_obj.className = 'area_active';
				if (title && area_title)
				{
					area_title.style.display = '';
				}
				if (tools && area_tools)
				{
					area_tools.style.display = '';
				}
			}
		);
	}
}

function areaInactive(area_obj, area_id, title, tools, borders)
{
	if (area_obj)
	{
		var area_root = 'ar'+area_id;
		addBlur
		(
			area_root,
			function()
			{
				var area_title = document.getElementById(area_root+'_title');
				var area_tools = document.getElementById(area_root+'_tools');

				if (borders) area_obj.className = 'area_hidden';
				else area_obj.className = 'area_inactive';
				if (title && area_title)
				{
					area_title.style.display = 'none';
				}
				if (tools && area_tools)
				{
					area_tools.style.display = 'none';
				}
			}
		);
	}
}

function areaColumnActive(obj, id, tools)
{
	if (obj)
	{
		var column_root = 'ar'+id;
		addFocus
		(
			column_root+'_col',
			function ()
			{
				var column_add = document.getElementById(column_root+'_add');

				obj.className = 'area_containers_active';
				if (tools && column_add)
				{
					column_add.style.display = 'block';
				}
			}
		);
	}
}

function areaColumnInactive(obj, id, tools, borders)
{
	if (obj)
	{
		var column_root = 'ar'+id;
		addBlur
		(
			column_root+'_col',
			function ()
			{
				var column_add = document.getElementById(column_root+'_add');

				if (borders) obj.className = 'area_containers_hidden';
				else obj.className = 'area_containers_inactive';
				if (tools && column_add)
				{
					column_add.style.display = 'none';
				}
			}
		);
	}
}

function searchformRangeToggle(value, id)
{
	var root = 'searchop_'+id;
	var start = document.getElementById(root+'_start');
	var both = document.getElementById(root+'_both');
	var end = document.getElementById(root+'_end');

	if (value == '' || value == '<' || value == '<=')
	{
		start.style.display = 'none';
	}
	else
	{
		start.style.display = '';
	}
	if (value == '<>')
	{
		both.style.display = '';
	}
	else
	{
		both.style.display = 'none';
	}
	if (value == '<' || value == '<=' || value == '<>')
	{
		end.style.display = '';
	}
	else
	{
		end.style.display = 'none';
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function tryPageLoad() { if (typeof(hsPageLoad) != 'undefined') { hsPageLoad(); } }  // allow admin override of page onLoad
function tryPageUnload() { if (typeof(hsPageUnload) != 'undefined') { hsPageUnload(); } }  // allow admin override of page onUnload

//use browser sniffing to determine if IE or Opera (ugly, but required)
var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true;}

//fix both IE and Opera (adjust when they implement this method properly)
if(isOpera || isIE)
{
  document.nativeGetElementById = document.getElementById;
  //redefine it!
  document.getElementById = function(id){
    var elem = document.nativeGetElementById(id);
    if(elem){
      //verify it is a valid match!
      if(elem.attributes['id'] && elem.attributes['id'].value == id){
        //valid match!
        return elem;
      } else {
        //not a valid match!
        //the non-standard, document.all array has keys for all name'd, and id'd elements
        //start at one, because we know the first match, is wrong!
        for(var i=1;i<document.all[id].length;i++){
          if(document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id){
            return document.all[id][i];
          }
        }
      }
    }
    return null;
  };
}

function updateAjaxDropdown(o)
{
	o = jQuery(o);
	o.data('updating', true);
	var last_updated = parseInt(o.attr('lastUpdated'));
	var data = jQuery.parseJSON(o.attr('data'));
	data.last_updated = last_updated;
	jQuery.ajax(
	{
		async:			false,
		context:		o,
		contentType:	'application/x-www-form-urlencoded;charset=ISO-8859-15',
		data:			data,
		success:		function(data, status, request)
		{
			var most_recent = parseInt(request.getResponseHeader('X-LastUpdated'));

			if (most_recent > last_updated)
			{
				selected = o.val();
				o.html(data);
				o.val(selected);

				if (jQuery('option:selected', o).length == 0)
				{
					o.val(jQuery('option', o).first().attr('value'));
				}
				o.attr('lastUpdated', most_recent);
			}
		},
		url:			o.attr('url')
	});
}

function databaseGetRecordIds(apikey, database, table, form, callback)
{
	var data = {};
	jQuery.map(jQuery(form).serializeArray(), function(n, i)
	{
		data[n['name']] = n['value'];
	});
	jQuery.ajax(
	{
		complete:		function(xhr, status)
		{
			if (status === 'success' || status === 'parsererror')	// In testing, valid XML was getting parsererrors. We don't need it parsed.
			{
				var ids = [];
				jQuery(xhr.responseText).find('record').each(function()
				{
					ids.push({ as: jQuery(this).attr('id') });
				});
				callback(ids);
			}
			var ids = [];
		},
		contentType:	'application/x-www-form-urlencoded;charset=utf-8',
		data:			data,
		dataType:		'xml',
		url:			'/databases/'+database+'/tables/'+table+'/records/'+apikey+'?fields=__h5_id'
	});
}

function refreshRepeaterWithIds(container_id, ids, baseList)
{
	jQuery.ajax(
	{
		contentType:	'application/x-www-form-urlencoded;charset=ISO-8859-15',
		data:
		{
			dynamic_display_ids:	ids
		},
		success:		function(data, status, request)
		{
			var newContent = jQuery('<div></div>');
			newContent.html(data);
			var x = newContent.find('#hs_container_'+container_id+'_tools');	// New
			var y = jQuery('#hs_container_'+container_id+'_tools');				// Old
			if (x.length > 0 && y.length > 0)
			{
				y.replaceWith(x);
			} else {
				x = newContent.find('#hs_container_'+container_id);	// New
				y = jQuery('#hs_container_'+container_id);			// Old
				if (x.length > 0 && y.length > 0)
				{
					y.replaceWith(x);
				}
			}
			if (baseList !== null)
			{
				$('#hs_container_'+container_id).attr('data-list', baseList);
			}
		},
		url:			'/api/load_container.php?co='+container_id
	});
}

function refreshRepeaterFromSearch(apikey, database, table, form, destination_container_id, filter)
{
	databaseGetRecordIds(apikey, database, table, form, function(ids)
	{
		var $destination = jQuery('#hs_container_'+destination_container_id),
			$baseListHolder = ($destination.attr('data-list') === undefined ? $destination.find('[data-list]') : $destination),
			baseList = $baseListHolder.length > 0 ? $baseListHolder.attr('data-list') : null,
			baseArray = baseList === null ? null : baseList.split(','),
			finalIds;
		if (filter && baseArray !== null)
		{
			finalIds = [];
			jQuery.each(ids, function()
			{
				if (jQuery.inArray(this.as, baseArray) !== -1)
				{
					finalIds.push(this);
				}
			});
		} else {
			finalIds = ids;
		}
		refreshRepeaterWithIds(destination_container_id, finalIds, filter ? baseList : null);
	});
}

// Site-wide jQuery code goes here. Anything inside this block gets executed only once the page is fully loaded (so this is where things like event handlers go).
jQuery(function()
{
	// Ajax updated dropdowns.
	var ajaxDropdowns = jQuery('select.ajax_updated');
	var dropdownDatas = new Array();
	ajaxDropdowns.each(function()
	{
		var o = jQuery(this);
		var newData = true;
		jQuery.each(dropdownDatas, function()
		{
			if (this[0] == o.attr('url') && this[1] == o.attr('data'))
			{
				newData = false;
			}
		});
		if (newData)
		{
			dropdownDatas[dropdownDatas.length] = [o.attr('url'), o.attr('data')];
		}
	});

	ajaxDropdowns.mouseover(function()
	{
		updateAjaxDropdown(this);
	});

	ajaxDropdowns.click(function()
	{
		jQuery(this).data('clicked', true);
	});

	ajaxDropdowns.focus(function()
	{
		if (!jQuery(this).data('clicked'))
		{
			updateAjaxDropdown(this);
		}
		jQuery(this).data('clicked', false);
	});

	jQuery.unique(ajaxDropdowns.closest('form')).submit(function()
	{
		var errorObjs = [];
		var f = jQuery(this);

		jQuery.each(dropdownDatas, function()
		{
			jQuery.ajax(
			{
				async:			false,
				context:		this,
				contentType:	'application/x-www-form-urlencoded;charset=ISO-8859-15',
				data:			jQuery.parseJSON(this[1]),
				success:		function(data, status, request)
				{
					var validValues = [];
					var s = jQuery('<select></select>').html(data);
					jQuery('option', s).each(function()
					{
						validValues[validValues.length] = jQuery(this).attr('value');
					});
					ajaxDropdowns.filter("[url='"+this[0]+"'][data='"+this[1]+"']").each(function()
					{
						o = jQuery(this);
						if (jQuery.inArray(o.val(), validValues) == -1)
						{
							errorObjs[errorObjs.length] = o;
							o.closest('tr').children('td').first().children('img').attr('src', '/site/images/forms/arrow_red.gif');
						} else {
							o.closest('tr').children('td').first().children('img').attr('src', '/site/images/spacer.gif');
						}
					});
				},
				url:			this[0]
			});
		});

		// When this code is used in a public interface, this will not work
		// - we need to update the error hypercode to use a named span (a la
		// dialog_error, or possibly rename dialog error to something agnostic),
		// and then add functionality here for that case.
		var o = jQuery('span#dialog_error');
		var ajaxDropdownError = '<span class="serror" id="ajax_dropdown_error">Values for some options have changed since this window was originally loaded. Please verify values marked with <img src="/site/images/forms/arrow_red.gif" /> before proceeding.</span>';

		jQuery('span#ajax_dropdown_error').remove();	// Whether there's an error or not, remove old dropdown errors.
		o.children('br:last-child').remove();
		if (errorObjs.length > 0)
		{
			if (o.length == 0)
			{
				// This html is INTENTIONALLY duplicated inside HSForms:buildErrorDialog
				jQuery('table#dialog_header').append('<tr bgcolor="#e9afaf"><td colspan="2" valign="middle" align="center"><span id="dialog_error" style="display: block; padding: 5px;" class="serrordark">'+ajaxDropdownError+'</span></td></tr>');
			} else if (o.children('span').length > 0) {
				o.append(jQuery(ajaxDropdownError).prepend('<br />'));
			} else {
				o.append(ajaxDropdownError);
			}
			return false;
		} else {
			if (jQuery.trim(o.html()) == '')
			{
				o.parents('tr').first().remove();
			}
		}
	});
});
-->
