var _editor_url="http://www.gouae.com".replace(/^http:/,window.location.protocol)+"/data/areaedit/";
var _editor_backend=null;
var _editor_lang=(window.ocp_lang)?ocp_lang.toLowerCase():'en';


var pageLoaded=false;
function scriptLoadStuff()
{
	var i;

	if (window==window.top) window.name='_site_opener';

	
	var preloader=new Image();
	var images=[];
	images[0]="http://www.gouae.com/themes/default/images/menus/menu_bullet_hover.png";
	images[1]="http://www.gouae.com/themes/default/images/expand.png";
	images[2]="http://www.gouae.com/themes/default/images/contract.png";
	images[2]="http://www.gouae.com/themes/default/images/exp_con.png";
	for(i=0;i<images.length;i++) preloader.src=images[i];

	
	if (!document.images) document.images=document.getElementsByTagName('img');
	if (!document.forms) document.forms=document.getElementsByTagName('forms');
	if (!document.links) document.links=document.getElementsByTagName('a');
	if (window.expandImages) expandImages();
	for (i=0;i<document.images.length;i++)
	{
		var j=document.images[i];
		if ((firstClassName(j.className)=='img_thumb') || (j.className.indexOf(' img_thumb')!=-1))
		{
			setOpacity(j,0.7);
		}
		if ((firstClassName(j.className)=='scale_down') || (j.className.indexOf(' scale_down')!=-1))
		{
			j.onclick=function() { if (document.images[i].className=='scale_down') { document.images[i].className='dont_scale_down'; document.images[i].setAttribute('title',''); } else { document.images[i].className='scale_down'; document.images[i].setAttribute('title','Click the image to see it full-size (if it\'s not already).'); } }
		}
	}

	
	var helper_pic=document.getElementById('global_helper_panel_pic');
	if (helper_pic) setOpacity(helper_pic,0.2);
	fixImages();
	
	
	handleTextareaScrolling();

	
	SetCookie('js_on',1,120);
	SetCookie('screen_width',getWindowWidth(),120);
	if (window.server_timestamp)
	{
		SetCookie('client_time',new Date().toString(),120);
		SetCookie('client_time_ref',window.server_timestamp,120);
	}

	for (i=0;i<document.forms.length;i++)
	{
		if (document.forms[i].className.indexOf('autocomplete')!=-1)
		{
			document.forms[i].setAttribute('autocomplete','on');
		} else
		{
			var dont_autocomplete=['email_address','email','username','password','edit_username','edit_password'];
			for (var j=0;j<dont_autocomplete.length;j++) 
				if (document.forms[i].elements[dont_autocomplete[j]]) document.forms[i].elements[dont_autocomplete[j]].setAttribute('autocomplete','off');
		}
		
		
		if (window.load_html_edit)
		{
			load_html_edit(document.forms[i]);
		}
	}

	
	if (window.scriptLoadStuffStaff) scriptLoadStuffStaff();

	
	window.mouseX=0;
	window.mouseY=0;
	addEventListenerAbstract(window,'mousemove',getMouseXY);
	if (window.addEventListener)
		window.addEventListener('click',captureClickKeyStates,true); 

	
	if (document.getElementsByTagName('base')[0])
	{
		for (i=0;i<document.links.length;i++)
		{
			var href=document.links[i].getAttribute('href');
			if ((href) && (href.substr(0,1)=='#'))
			{
				document.links[i].setAttribute('href',window.location.href.replace(/#.*$/,'')+href);
			}
		}
	}

	
	if (window.want_form_saving)
	{
		window.setTimeout(init_form_saving,4000);
	}

	pageLoaded=true;
}

function initialise_error_mechanism()
{
	window.onerror=function(msg,file,code)
		{
			if ((msg.indexOf('TODO: FIXME')!=-1) || (msg.indexOf('Array.constructor')!=-1) || (msg.indexOf('Error loading script')!=-1) || (msg.indexOf('NS_ERROR_FAILURE')!=-1)) return null; 
			
			if (!window.done_one_error)
			{
				window.done_one_error=true;
				window.alert('An error occurred when loading this screen onto the web browser. You are being notified of this as you are staff. If you believe this is a bug in the website software, please contact ocProducts with full details. More details are available in your browser\'s error console. The error was:\n\n'+code+': '+msg+'\n'+file);
			}
			return false;
		};
	window.onunload=function() { window.onerror=null; };
}
if (window.take_errors) initialise_error_mechanism();

// 'Cancel' should come as index 0 and Ok/default-option should come as index 1. This is so that the fallback works right.
function generate_question_ui(message,button_set,window_title,fallback_message)
{
	if (window.showModalDialog)
	{
		var result=window.showModalDialog('http://www.gouae.com/data/question_ui.php?message='+window.encodeURIComponent(message)+'&button_set='+window.encodeURIComponent(button_set.join(','))+'&window_title='+window.encodeURIComponent(window_title)+keep_stub(),null,'dialogWidth=400;dialogHeight=160;status=no;unadorned=yes');
		if ((typeof result=="undefined") || (result===null)) return button_set[0]; // just pressed 'cancel', so assume option 0
		return result;
	} else
	{
		if (button_set.length==1)
		{
			window.alert(fallback_message?fallback_message:message);
			return button_set[0];
		} else
		if (button_set.length==2)
		{
			var result=window.confirm(fallback_message?fallback_message:message);
			return result?button_set[1]:button_set[0];
		} else
		{
			if (!fallback_message)
			{
				message+="\n\nType either: ";
				for (var i=0;i<button_set.length;i++)
				{
					message+=button_set[i]+',';
				}
				message=message.substr(0,message.length-1);
			} else message=fallback_message;
			var result=window.prompt(message,'');
			if ((typeof result=="undefined") || (result===null)) return button_set[0]; // just pressed 'cancel', so assume option 0
			if (result=='') return button_set[1]; // just pressed 'ok', so assume option 1
			for (var i=0;i<button_set.length;i++)
			{
				if (result.toLowerCase()==button_set[i].toLowerCase()) return result; // match
			}
			return button_set[0]; // unknown
		}
	}
	return null;
}

function doc_onmouseout()
{
	if (window.orig_helper_text)
	{
		var help=document.getElementById('help');
		if (!help) return; // In zone editor, probably
		setInnerHTML(help,window.orig_helper_text);
		help.className='global_helper_panel_text';
	}
}

function doc_onmouseover(i)
{
	var doc=document.getElementById('doc_'+i);
	if ((doc) && (getInnerHTML(doc)!=''))
	{
		var help=document.getElementById('help');
		if (!help) return; // In zone editor, probably
		window.orig_helper_text=getInnerHTML(help);
		setInnerHTML(help,getInnerHTML(doc));
		help.className='global_helper_panel_text_over';
	}
}

function handleTextareaScrolling()
{
	var i;
	var elements=document.getElementsByTagName('textarea');
	for (i=0;i<elements.length;i++)
	{
		if (elements[i].className.indexOf('textarea_scroll')!=-1)
		{
			elements[i].setAttribute('wrap','off');
			elements[i].style.overflow='auto'; 
		}
	}
}

function scriptPageRendered()
{
	
	if (getWindowWidth()<990)
	{
		var panel_right=document.getElementById('panel_right');
		var global_div=document.getElementById('global_div');
		if (panel_right)
		{
			var divs=panel_right.getElementsByTagName('div');
			if ((divs[0]) && (divs[0].className=='global_helper_panel'))
			{
				var middle=get_elements_by_class_name(panel_right.parentNode,'global_middle')[0];
				if (middle)
				{
					middle.style.marginRight='0';
					var boxes=get_elements_by_class_name(panel_right,'standardbox_curved'),i;
					for (i=0;i<boxes.length;i++)
					{
						boxes[i].style.width='360px';
					}
					panel_right.className+=' horiz_help_panel';
					panel_right.parentNode.removeChild(panel_right);
					middle.parentNode.appendChild(panel_right);
				}
			}
		}
	}
}

function help_panel(show)
{
	var panel_right=document.getElementById('panel_right');
	var middles=document.getElementsByClassName('global_middle');
	var global_message=document.getElementById('global_message');
	var helper_panel_contents=document.getElementById('helper_panel_contents');
	var helper_panel_toggle=document.getElementById('helper_panel_toggle');
	var i;
	if (show)
	{
		panel_right.style.width='425px';
		if (global_message) global_message.style.marginRight='425px';
		for (i=0;i<middles.length;i++)
		{
			middles[i].style.marginRight='425px';
		}
		helper_panel_contents.style.display='block';
		SetCookie('hide_help_panel','0',100);
		helper_panel_toggle.onclick=function() { return help_panel(false); };
		helper_panel_toggle.childNodes[0].setAttribute('src','http://www.gouae.com/themes/default/images/help_panel_hide.png');
	} else
	{
		if (ReadCookie('hide_help_panel')=='')
		{
			if (!window.confirm('You have chosen to contract the help panel, and it will remain so until you expand it again. It is not advised that you leave the panel contracted, as you may miss program help. Confirm if you sure you wish to contract the help panel.')) return false;
		}
		panel_right.style.width='16px';
		if (global_message) global_message.style.marginRight='16px';
		for (i=0;i<middles.length;i++)
		{
			middles[i].style.marginRight='16px';
		}
		helper_panel_contents.style.display='none';
		SetCookie('hide_help_panel','1',100);
		helper_panel_toggle.onclick=function() { return help_panel(true); };
		helper_panel_toggle.childNodes[0].setAttribute('src','http://www.gouae.com/themes/default/images/help_panel_show.png');
	}
	return false;
}

function sts(src)
{
	if (!src) return 0;
	if (src.indexOf('px')==-1) return 0;
	return window.parseInt(src.replace('px',''));
}

function captureClickKeyStates(event)
{
	window.capture_event=event;
}

function magicKeypress(event)
{
	
	if (window.capture_event) event=window.capture_event;
	var count=0;
	if (event.shiftKey) count++;
	if (event.ctrlKey) count++;
	if (event.metaKey) count++;
	if (event.altKey) count++;
	return (count>=2);
}

function window_r(expr)
{
	var win=window.open('','format','width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');
	win.document.open();
	win.document.write('<pre>'+((window.format_r)?format_r(expr):expr)+'</pre>');
	win.document.close()
	win.focus();
}

function escape_html(value)
{
	if (!value) return '';
	return value.replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(new RegExp('<','g')/* For CDATA embedding else causes weird error */,'&lt;').replace(/>/g,'&gt;');
}

function escape_comcode(value)
{
	return value.replace(/\\/g,'\\\\').replace(/"/g,'\\"');
}

function setOpacity(element,fraction)
{
	element.style.opacity=fraction;
	element.style.filter='';
	if (element.src) fixImage(element,true);
	element.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity='"+parseInt(fraction*100)+"')";
}

function create_rollover(rand,rollover)
{
	var img=document.getElementById(rand);
	if (!img) return;
	new Image().src=rollover; 
	addEventListenerAbstract(img,"mouseover",function()
	{
		img.old_src=img.getAttribute('src');
		if (img.origsrc) img.old_src=img.origsrc;
		img.setAttribute('src',rollover);
		fixImage(img);
	});
	addEventListenerAbstract(img,"mouseout",function()
	{
		img.setAttribute('src',img.old_src);
		fixImage(img);
	});
}


function SetCookie(cookieName,cookieValue,nDays)
{
	var today=new Date();
	var expire=new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime()+3600000*24*nDays);
	var extra="";
	if ("/"!="") extra=extra+";path=/";
	if (""!="") extra=extra+";domain=";
	document.cookie=cookieName+"="+encodeURIComponent(cookieValue)+";expires="+expire.toUTCString()+extra;
	if ((ReadCookie(cookieName)!=cookieValue) && (ReadCookie(cookieName)))
	{
		//if (!window.done_cookie_alert) window.alert('You have conflicting cookies on your computer. The website can not set cookies as others are stuck in place. Please delete all cookies for this website in your web browser.');
		window.done_cookie_alert=true;
	}
}
function ReadCookie(cookieName)
{
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(' '+cookieName+'=');
	if ((ind==-1) && (theCookie.substr(0,cookieName.length+1)==cookieName+'=')) ind=0; else if (ind!=-1) ind++;
	if (ind==-1 || cookieName=="") return "";
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return window.decodeURIComponent(theCookie.substring(ind+cookieName.length+1,ind1));
}


function firstClassName(className)
{
	var p=className.indexOf(' ');
	if (p!=-1)
	{
		return className.substr(0,p);
	}
	return className;
}

function get_elements_by_class_name(node,classname)
{
	if (node)
	{
		var a=[];
		var re=new RegExp('(^| )'+classname+'( |$)');
		var els=node.getElementsByTagName("*");

		for(var i=0,j=els.length; i<j; i++)
		{
			if (re.test(els[i].className)) a.push(els[i]);
		}

		return a;
	}
	else return []; 
}

document.getElementsByClassName=function(cl) 
{
	return get_elements_by_class_name(this,cl);
};


function isInteger(val)
{
	if (val=="") return false;
	var c;
	for (var i=0;i<val.length;i++)
	{
		c=val.charAt(i);
		if ((c!="0") && (c!="1") && (c!="2") && (c!="3") && (c!="4") && (c!="5") && (c!="6") && (c!="7") && (c!="8") && (c!="9"))
			return false;
	}
	return true;
}


function is_opera()
{
	return browser_matches('opera');
}
function is_ie()
{
	return browser_matches('ie');
}
function browser_matches(code)
{
	var browser=navigator.userAgent.toLowerCase();
	var os=navigator.platform.toLowerCase()+' '+browser;

	var _is_opera=browser.indexOf('opera')!=-1;
	var is_konqueror=browser.indexOf('konqueror')!=-1;
	var is_safari=browser.indexOf('applewebkit')!=-1;
	var is_gecko=(browser.indexOf('gecko')!=-1) && !_is_opera && !is_konqueror && !is_safari;
	var _is_ie=(browser.indexOf('msie')!=-1) && !_is_opera;
	var is_ie_old=((browser.indexOf('msie 6')!=-1) || (browser.indexOf('msie 5')!=-1)) && _is_ie;
	var is_ie_decent=(!is_ie_old) && (browser.indexOf('msie 7')==-1) && _is_ie;
	var is_ie5=(browser.indexOf('msie 5')!=-1) && _is_ie;
	var is_ie_new=(!is_ie_old) && _is_ie;
	var is_iceweasel=browser.indexOf('iceweasel')!=-1;

	switch (code)
	{
		case 'no_alpha_ie':
			
			return ((/MSIE ((5\.5)|[6])/.test(navigator.userAgent)) && (navigator.platform=="Win32") && (!_is_opera));
		case 'no_alpha_ie_with_opacity':
			return ((/MSIE ((5\.5)|[678])/.test(navigator.userAgent)) && (navigator.platform=="Win32") && (!_is_opera));
		case 'wysiwyg':
			return (_is_ie || is_gecko) && !is_iceweasel;
		case 'windows':
			return os.indexOf('windows')!=-1 || os.indexOf('win32')!=-1;
		case 'mac':
			return os.indexOf('mac')!=-1;
		case 'linux':
			return os.indexOf('linux')!=-1;
		case 'opera':
			return _is_opera;
		case 'ie':
			return _is_ie;
		case 'ie5':
			return is_ie5;
		case 'ie_old':
			return is_ie_old;
		case 'ie_new':
			return is_ie_new;
		case 'ie_decent':
			return is_ie_decent;
		case 'gecko':
			return is_gecko;
		case 'konqueror':
			return is_konqueror;
		case 'safari':
			return is_safari;
	}

	
	return false;
}


function confirm_session(jump_initial_test)
{
	if (!window.load_XML_doc) return false;

	var url='/data/confirm_session.php';
	var ret=null;
	if (!jump_initial_test)
	{
		require_javascript("javascript_ajax");
		if (window.load_XML_doc) ret=load_XML_doc(url+keep_stub(true),false);
		if (!ret) return false;
	}
	var promptt="!";
	while (((!ret) || ((ret.responseText!='') && (ret.responseText))) && (promptt!='') && (promptt))
	{
		promptt=window.prompt('Enter your password (please make sure nobody is watching first)','');
		if ((window.load_XML_doc) && (promptt) && (promptt!=''))
			ret=load_XML_doc(url,false,'login_username='+ret.responseText+'&password='+promptt+keep_stub());
	}
	return ret.responseText=='' || (!ret.responseText);
}


function load_snippet(code)
{
	var title=getInnerHTML(document.getElementsByTagName('title')[0]);
	var metas=document.getElementsByTagName('meta');
	var i;
	var url=window.location.href;
	for (i=0;i<metas.length;i++)
	{
		if (metas[i].getAttribute('name')=='self_url') url=metas[i].getAttribute('content');
	}
	if (!url) url=window.location.href;
	var html;
	if (window.load_XML_doc)
	{
		var url2="/data/snippet.php?snippet="+code+"&url="+window.encodeURIComponent(url)+'&title='+window.encodeURIComponent(title)+keep_stub();
		html=load_XML_doc(url2);
	}
	return html.responseText;
}
function require_css(sheet)
{
	if (document.getElementById('loading_css_'+sheet)) return;
	var link=document.createElement('link');
	link.setAttribute('id','loading_css_'+sheet);
	link.setAttribute('type',"text/css");
	link.setAttribute('rel',"stylesheet");
	link.setAttribute('href',"http://www.gouae.com".replace(/^http:/,window.location.protocol)+"/data/sheet.php?sheet="+sheet+keep_stub());
	document.getElementsByTagName('head')[0].appendChild(link);
}
function require_javascript(script,lang)
{
	if (document.getElementById('loading_js_'+script)) return;
	var link=document.createElement('script');
	link.setAttribute('id','loading_js_'+script);
	link.setAttribute('type',"text/javascript");
	var url="http://www.gouae.com".replace(/^http:/,window.location.protocol)+"/data/javascript.php?script="+script+keep_stub();
	if (lang) url=url+"&lang="+lang;
	link.setAttribute('src',url);
	document.getElementsByTagName('head')[0].appendChild(link);
}


function hideTag(element,noAnimate)
{
	var pics=element.getElementsByTagName('img');
	var pic=pics[0];
	toggleSectionInline('','block',pic,get_elements_by_class_name(element,'hide_tag')[0],noAnimate);
}
function toggleSectionTable(id,noAnimate)
{
	toggleSectionInline(id,browser_matches('ie')?'block':'table',false,noAnimate);
}
function toggleSectionInline(id,type,pic,itm,noAnimate)
{
	if (!itm) itm=document.getElementById(id);
	if (!pic) pic=document.getElementById('e_'+id);

	if ((pic) && (pic.src=="http://www.gouae.com/themes/default/images/exp_con.png")) return;

	if (itm.style.display=='none')
	{
		itm.style.display=type;
		if ((type=='block') && (itm.nodeName.toLowerCase()=='div') && (!noAnimate) && ((!pic) || (pic.src.indexOf("themewizard.php")==-1)))
		{
			itm.style.visibility='hidden';
			itm.style.width=findWidth(itm,true)+'px';
			itm.style.position='absolute'; /* So things do not just around now it is visible */ 
			if (pic)
			{
				pic.src="http://www.gouae.com/themes/default/images/exp_con.png";
				fixImage(pic);
			}
			window.setTimeout(function() { beginAnimation(itm,20,70,-1,pic); } ,20);
		} else
		{
			if (pic)
			{
				pic.src=(pic.src.indexOf("themewizard.php")!=-1)?pic.src.replace("expand","contract"):"http://www.gouae.com/themes/default/images/contract.png";
				fixImage(pic);
			}
		}
	} else
	{
		if ((type=='block') && (itm.nodeName.toLowerCase()=='div') && (!noAnimate) && ((!pic) || (pic.src.indexOf("themewizard.php")==-1)))
		{
			if (pic)
			{
				pic.src="http://www.gouae.com/themes/default/images/exp_con.png";
				fixImage(pic);
			}
			window.setTimeout(function() { beginAnimation(itm,-20,70,0,pic); } ,20);
		} else
		{
			if (pic)
			{
				pic.src=(pic.src.indexOf("themewizard.php")!=-1)?pic.src.replace("contract","expand"):"http://www.gouae.com/themes/default/images/expand.png";
				fixImage(pic);
			}
			itm.style.display='none';
		}
	}

	trigger_resize();
}

function beginAnimation(itm,animateDif,animateTicks,finalHeight,pic)
{
	var fullHeight=findHeight(itm,true);
	if (finalHeight==-1) // We're animating to full height - not a fixed height
	{
		finalHeight=fullHeight;
		itm.style.height='0px';
		itm.style.visibility='visible';
		itm.style.position='static';
	}
	if (fullHeight>300) itm.style.height=finalHeight+'px'; 
	else itm.style.outline='1px dashed grey';
	var origOverflow=itm.style.overflow;
	itm.style.overflow='hidden';
	window.setTimeout(function () { animate(itm,finalHeight,animateDif,origOverflow,animateTicks,pic); } ,animateTicks);
}

function animate(itm,finalHeight,animateDif,origOverflow,animateTicks,pic)
{
	var currentHeight=((itm.style.height=='auto')||(itm.style.height==''))?(findHeight(itm)):sts(itm.style.height);
	/*if (Math.max(currentHeight-finalHeight,finalHeight-currentHeight)<70)
	{
		if (animateDif<0) animateDif=Math.min(animateDif*0.8,-3);
		else animateDif=Math.max(animateDif*0.85,3);
	}*/
	if (((currentHeight>finalHeight) && (animateDif<0)) || ((currentHeight<finalHeight) && (animateDif>0)))
	{
		var num=Math.max(currentHeight+animateDif,0);
		if (animateDif>0) num=Math.min(num,finalHeight);
		itm.style.height=num+'px';
		window.setTimeout(function () { animate(itm,finalHeight,animateDif,origOverflow,animateTicks,pic); } ,animateTicks);
	} else
	{
		itm.style.height='auto';
		if (animateDif<0)
		{
			itm.style.display='none';
		}
		itm.style.overflow=origOverflow;
		itm.style.outline='0';
		if (pic)
		{
			pic.src=(animateDif<0)?"http://www.gouae.com/themes/default/images/expand.png":"http://www.gouae.com/themes/default/images/contract.png";
			fixImage(pic);
		}
	}
}

function animateFrameLoad(pf,frame,leave_gap_top)
{
	if (!leave_gap_top) leave_gap_top=0;
	
	pf.style.height=window.top.getWindowHeight()+'px'; 
	var head='<style type="text/css">',cssText='';
	for (var i=0;i<document.styleSheets.length;i++)
	{
		var rules=[];
		try { rules=document.styleSheets[i].cssRules?document.styleSheets[i].cssRules:document.styleSheets[i].rules; }
		catch (e) {};
		for (var j=0;j<rules.length;j++)
		{
			if (rules[j].cssText)
				cssText+=rules[j].cssText+"\n\n";
			else
				cssText+=rules[j].selectorText+'{ '+rules[j].style.cssText+"}\n\n";
		}
	}
	head+=cssText+'<\/style>';

	var de=window.frames[frame].document.documentElement;
	var body=de.getElementsByTagName('body');
	if (body.length==0)
	{
		setInnerHTML(de,'<head>'+head+'<\/head><body class="re_body"><div class="spaced"><div class="ajax_tree_list_loading"><img class="inline_image_2" src="http://www.gouae.com/themes/default/images/bottom/loading.gif" /> Loading&hellip;<\/div><\/div><\/body>');
	} else
	{
		body[0].className='re_body';

		var head_element=de.getElementsByTagName('head')[0];
		if (!head_element)
		{
			head_element=document.createElement('head');
			de.appendChild(head_element);
		}

		if (de.getElementsByTagName('style').length==0) 
			setInnerHTML(head_element,head);
		setInnerHTML(body[0],'<div class="spaced"><div class="ajax_tree_list_loading"><img class="inline_image_2" src="http://www.gouae.com/themes/default/images/bottom/loading.gif" /> Loading&hellip;<\/div><\/div>');
	}
	var style=de.getElementsByTagName('style')[0];
	if ((style) && (style.styleSheet)) style.styleSheet.cssText=cssText; 
	var ifuob=window.top.document.getElementById('iframe_under');
	var extra=ifuob?((window!=window.top)?findPosY(ifuob):0):0;
	window.top.smoothScroll(findPosY(pf)+extra-leave_gap_top);
}

function smoothScroll(destY,expectedScrollY,dir)
{
	if (typeof destY=='string') destY=findPosY(document.getElementById(destY));
	
	if ((typeof expectedScrollY!="undefined") && (expectedScrollY!=window.scrollY)) return; 
	if (!dir) dir=((destY-window.scrollY)>0)?1:-1;
	var dist=dir*11;
	if (((dir==1) && (window.scrollY+dist>=destY)) || ((dir==-1) && (window.scrollY+dist<=destY)))
	{
		window.scrollTo(0,destY);
		return;
	}
	var old_scroll=window.scrollY;
	window.scrollBy(0,dist);
	window.setTimeout(function() { smoothScroll(destY,old_scroll+dist,dir); } , 30);
}

function abstractGetComputedStyle(obj,property)
{
	if (obj.currentStyle)
	{
		var index=property.indexOf('-');
		if (index!=-1)
		{
			property=property.substring(0,index)+property.substring(index+1,index+2).toUpperCase()+property.substring(index+2,property.length);
		}
		return obj.currentStyle[property];
	}

	var ret=null;
	try {
		ret=document.defaultView.getComputedStyle(obj,null).getPropertyValue(property);
	}
	catch(e) {  }

	return ret;
}


function changeClass(box,theId,to,from)
{
	var cell=document.getElementById(theId);
	if (!cell) cell=theId;
	cell.className=(box.checked)?to:from;
}


function getMouseXY(e)
{
	window.mouseX=getMouseX(e);
	window.mouseY=getMouseY(e);
	return true
}
function getMouseX(event)
{
	try
	{
		if ((typeof event.pageX!='undefined') && (event.pageX))
		{
			return event.pageX;
		} else if ((typeof event.clientX!='undefined')&& (event.clientX))
		{
			return event.clientX+getWindowScrollX()
		}
	}
	catch (err) {}
	return 0;
}
function getMouseY(event)
{
	try
	{
		if ((typeof event.pageY!='undefined') && (event.pageY))
		{
			return event.pageY;
		} else if ((typeof event.clientY!='undefined') && (event.clientY))
		{
			return event.clientY+getWindowScrollY()
		}
	}
	catch (err) {}
	return 0;
}
function getWindowWidth()
{
	if (window.innerWidth) return window.innerWidth-18;
	if ((document.documentElement) && (document.documentElement.clientWidth)) return document.documentElement.clientWidth;
	if ((document.body) && (document.body.clientWidth)) return document.body.clientWidth;
	return 0;
}
function getWindowHeight()
{
	if (window.innerHeight) return window.innerHeight-18;
	if ((document.documentElement) && (document.documentElement.clientHeight)) return document.documentElement.clientHeight;
	if ((document.body) && (document.body.clientHeight)) return document.body.clientHeight;
	return 0;
}
function getWindowScrollWidth(win)
{
	if (!win) win=window;
	return win.document.body.scrollWidth;
}
function getWindowScrollHeight(win)
{
	if (!win) win=window;
	var best=win.document.body.parentNode.offsetHeight;
	if (best>win.document.body.scrollHeight) return best;
	return win.document.body.scrollHeight;
}
function getWindowScrollX()
{
  	if (window.pageXOffset) return window.pageXOffset;
  	if ((document.documentElement) && (document.documentElement.scrollLeft)) return document.documentElement.scrollLeft;
  	if ((document.body) && (document.body.scrollLeft)) return document.body.scrollLeft;
  	if (window.scrollX) return window.scrollX;
	return 0;
}
function getWindowScrollY()
{
  	if (window.pageYOffset) return window.pageYOffset;
  	if ((document.documentElement) && (document.documentElement.scrollTop)) return document.documentElement.scrollTop;
  	if ((document.body) && (document.body.scrollTop)) return document.body.scrollTop;
  	if (window.scrollTop) return window.scrollTop;
	return 0;
}
function findPosX(obj,notRelative) 
{
	if (!obj) window.alert(findPosX.caller);

	var curleft=0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if ((abstractGetComputedStyle(obj,'position')=='absolute') && (!notRelative) && (obj.style.left.indexOf('px')!=-1))
			{
				curleft+=sts(obj.style.left);
				break;
			}
			curleft+=obj.offsetLeft
			if ((abstractGetComputedStyle(obj,'position')=='relative') && (!notRelative)) break;
			obj=obj.offsetParent;
		}
	}
	else if (obj.x) curleft+=obj.x;
	return curleft;
}
function findPosY(obj,notRelative) 
{
	if (!obj) window.alert(findPosY.caller);

	var curtop=0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if ((abstractGetComputedStyle(obj,'position')=='absolute') && (!notRelative) && (obj.style.left.indexOf('px')!=-1))
			{
				curtop+=sts(obj.style.top);
				break;
			}
			curtop+=obj.offsetTop
			if ((abstractGetComputedStyle(obj,'position')=='relative') && (!notRelative)) break;
			obj=obj.offsetParent;
		}
	}
	else if (obj.y) curtop+=obj.y;
	return curtop;
}
function findWidth(obj,takePadding)
{
	if (!obj) return 0;
	var ret=obj.offsetWidth;
	if (takePadding)
	{
		ret-=sts(abstractGetComputedStyle(obj,'padding-left'));
		ret-=sts(abstractGetComputedStyle(obj,'padding-right'));
	}
	return ret;
}
function findHeight(obj,takePadding)
{
	if (!obj) return 0;
	var ret=obj.offsetHeight;
	if (takePadding)
	{
		ret-=sts(abstractGetComputedStyle(obj,'padding-top'));
		ret-=sts(abstractGetComputedStyle(obj,'padding-bottom'));
	}
	return ret;
}

function enter_pressed(event,altChar)
{
	if (!event) event=window.event;
	if ((altChar) && (((event.which) && (event.which==altChar.charCodeAt(0))) || ((event.keyCode) && (event.keyCode==altChar.charCodeAt(0))))) return true;
	return (((event.which) && (event.which==13)) || ((event.keyCode) && (event.keyCode==13)));
}


function key_pressed(event,key)
{
	if (!event) event=window.event;

	if (key.constructor==Array)
	{
		for (var i=0;i<key.length;i++)
		{
			if (key[i]==null) 
			{
				if ((event.keyCode) && (event.keyCode<48) && (event.keyCode!=32)) return true;
			} else
			{
				if (key_pressed(event,key[i])) return true;
			}
		}
		return false;
	}
	
	
	if (key=='-') key=109;
	if (key=='_') key=0; 

	
	if (key.constructor==String) 
	{
		if ((event.shiftKey) && (key.toUpperCase()==key.toLowerCase())) return false; 

		key=key.toUpperCase().charCodeAt(0);

		if ((event.keyCode) && (event.keyCode>=96) && (event.keyCode<106) && (key>=48) && (key<58)) key+=48; 
	}

	return ((typeof event.keyCode!="undefined") && (event.keyCode==key));
}


function activateTooltip(ac,myevent,tooltip,width,pic,height,bottom,no_delay)
{
	if (!pageLoaded) return;
	if ((typeof tooltip!='function') && (tooltip=='')) return;
	if (ac.getAttribute('title')) ac.setAttribute('title','');

	ac.is_over=true;
	ac.tooltip_on=false;

	var tooltipElement;
	if (ac.tooltipId)
	{
		tooltipElement=document.getElementById(ac.tooltipId);
		repositionTooltip(ac,myevent,bottom,true,tooltipElement);
	} else
	{
		tooltipElement=document.createElement("div");
		tooltipElement.style.display='none';
		tooltipElement.className="ocp_tooltip";
		if (pic)
		{
			var img=document.createElement('img');
			img.src=pic;
			img.style.position='absolute';
			img.style.right='0px';
			img.style.top='0px';
			tooltipElement.appendChild(img);
		}
		if ((browser_matches('ie_old')) || (width=='auto')) tooltipElement.style.width=width; else tooltipElement.style.maxWidth=width;
		if ((!browser_matches('ie_old')) && (height)) { tooltipElement.style.maxHeight=height; tooltipElement.style.overflow='auto'; }
		tooltipElement.style.position='absolute';
		tooltipElement.id=Math.floor(Math.random()*1000);
		ac.tooltipId=tooltipElement.id;
		repositionTooltip(ac,myevent,bottom,true,tooltipElement);
		document.body.appendChild(tooltipElement);
	}

	var myevent_copy={ 
		'pageX': myevent.pageX,
		'pageY': myevent.pageY,
		'clientX': myevent.clientX,
		'clientY': myevent.clientY,
		'type': myevent.type
	};

	window.setTimeout(function() {
		if (!ac.is_over) return;

		if (typeof tooltip=='function') tooltip=tooltip();
		if (tooltip=='') return;

		ac.tooltip_on=true;

		setInnerHTML(tooltipElement,tooltip);
		tooltipElement.style.display='block';

		repositionTooltip(ac,myevent_copy,bottom,true,tooltipElement);
	}, no_delay?10:666);
}
function repositionTooltip(ac,event,bottom,starting,tooltipElement)
{
	if (!pageLoaded) return;
	if (!ac.tooltipId) { if (ac.onmouseover) ac.onmouseover(event); return; };  

	if (!tooltipElement) tooltipElement=document.getElementById(ac.tooltipId);
	if (tooltipElement)
	{
		var width=findWidth(tooltipElement);
		if (width==0) width=window.parseInt(tooltipElement.style.width.replace('px',''));
		if ((!width) || ((tooltipElement.style.width=='auto') && (width<200))) width=200;
		var height=findHeight(tooltipElement);

		var x=(getMouseX(event)+10);
		var y=(getMouseY(event)+10);
		try
		{
			if (event.type)
			{
				if (event.type!='focus') ac.done_none_focus=true;
				if ((event.type=='focus') && (ac.done_none_focus)) return;
				x=(event.type=='focus')?(getWindowScrollX()+getWindowWidth()/2):(getMouseX(event)+10);
				y=(event.type=='focus')?(getWindowScrollY()+getWindowHeight()/2-40):(getMouseY(event)+10);
			}
		}
		catch(ignore) {};

		var x_excess=x-getWindowWidth()-getWindowScrollX()+width+20;
		if (x_excess>0) 
		{
			if (width-x_excess<200) 
			{
				x-=x_excess+20;
			} else
			{
				tooltipElement.style.width=(width-x_excess-20)+'px';
			}
		}
		if (bottom)
		{
			tooltipElement.style.top=(y-height)+'px';
		} else
		{
			var y_excess=y-getWindowHeight()-getWindowScrollY()+height+10;
			if (y_excess>0) y-=y_excess;
			tooltipElement.style.top=y+'px';
		}
		tooltipElement.style.left=x+'px';
		if (tooltipElement.style.width=='auto') tooltipElement.style.width=width+'px'; 
	}
}
function deactivateTooltip(ac,event)
{
	ac.is_over=false;

	if ((!pageLoaded) || (!ac.tooltipId)) return;

	var tooltipElement=document.getElementById(ac.tooltipId);
	if (tooltipElement) tooltipElement.style.display='none';
}

function resizeFrame(name,minHeight)
{
	if (!minHeight) minHeight=0;
	var frame_element=document.getElementById(name);
	var frame_window;
	if (top.frames[name]) frame_window=top.frames[name]; else if (window.frames[name]) frame_window=window.frames[name]; else return;
	if ((frame_element) && (frame_window) && (frame_window.document) && (frame_window.document.body))
	{
		var h=getWindowScrollHeight(frame_window);
		if (h+'px'!=frame_element.style.height)
		{
			frame_element.style.height=((h>=minHeight)?h:minHeight)+'px';
		}
	}
}
function trigger_resize()
{
	if (!window.parent) return;
	var frames=window.parent.document.getElementsByTagName('iframe');
	for (var i=0;i<frames.length;i++)
	{
		if ((frames[i].src==window.location.href) || (frames[i].contentWindow==window) || ((typeof window.parent.frames[frames[i].id]!="undefined") && (window.parent.frames[frames[i].id]==window)))
		{
			window.parent.resizeFrame(frames[i].name);
			window.setTimeout(function(frame_name) { return function() { window.parent.resizeFrame(frame_name); }; }(frames[i].name), 500); // Incase it had not quite renderered yet above
		}
	}
}


function addFormMarkedPosts(work_on,prefix)
{
	var get=work_on.getAttribute('method').toLowerCase()=='get';
	var elements=document.getElementsByTagName('input');
	var i;
	var append='';
	if (get)
	{
		for (i=0;i<work_on.elements.length;i++)
		{
			if (work_on.elements[i].name.match(new RegExp('&'+prefix.replace('_','\_')+'\d+=1$','g')))
			{
				work_on.elements[i].parentNode.removeChild(work_on.elements[i]);
			}
		}
	} else
	{
		
		work_on.action=work_on.action.replace('?','&');
		work_on.action=work_on.action.replace(new RegExp('&'+prefix.replace('_','\_')+'\d+=1$','g'),'');
		work_on.action=work_on.action.replace('&','?'); 
	}
	for (i=0;i<elements.length;i++)
	{
		if ((elements[i].type=='checkbox') && (elements[i].name.substring(0,prefix.length)==prefix) && (elements[i].checked))
			append+=(((append=='') && (work_on.action.indexOf('?')==-1) && (work_on.action.indexOf('/pg/')==-1) && (!get))?'?':'&')+elements[i].name+'=1';
	}
	if (get)
	{
		var bits=append.split('&');
		for (i=0;i<bits.length;i++)
		{
			if (bits[i]!='')
			{
				var hidden=document.createElement('input');
				hidden.name=bits[i].substr(0,bits[i].indexOf('=1'));
				hidden.value='1';
				hidden.type='hidden';
				work_on.appendChild(hidden);
			}
		}
	} else
	{
		work_on.action+=append;
	}
	return append!='';
}
function markAllTopics()
{
	var e=document.getElementsByTagName('input');
	var i;
	for (i=0;i<e.length;i++)
	{
		if ((e[i].type=='checkbox') && (e[i].name.substr(0,5)=='mark_'))
		{
			e[i].checked=!e[i].checked;
			e[i].onclick();
		}
	}
}



function fixImages()
{
	for(var i=0;i<document.images.length;i++) fixImage(document.images[i]);
	var inputs=document.getElementsByTagName('input');
	for(var i=0;i<inputs.length;i++) fixImage(inputs[i]);
}
function fixImage(img,force_ie8)
{
	if (force_ie8)
	{
		if (!browser_matches('no_alpha_ie_with_opacity')) return;
	} else
	{
		if (!browser_matches('no_alpha_ie')) return;
	}
	if (!img.src) return;
	if (window.location.href.indexOf('keep_noiepng')!=-1) return;

	var imgName=img.src.toUpperCase();
	if (imgName.substring(imgName.length-3,imgName.length)=="PNG")
	{
		if (!img.style.filter)
		{
			var srcURL=img.src;
			img.origsrc=img.src;
			if (browser_matches('ie5'))
			{
				if (!img.style.width) img.style.width=findWidth(img)+'px';
				if (!img.style.height) img.style.height=findHeight(img)+'px';
			}
			img.src="http://www.gouae.com".replace(/^http:/,window.location.protocol)+"/data/images/blank.gif";
			var new_filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+srcURL+"',sizingMethod='image');";
			img.runtimeStyle.filter=new_filter;

			if ((img.title) && (img.title!=''))
			{
				var title=img.title;
				img.attachEvent("onmousemove",function() { repositionTooltip(img,event); });
				img.attachEvent("onmouseout",function() { deactivateTooltip(img,event); });
				img.attachEvent("onmouseover",function() { activateTooltip(img,event,title,'auto'); });
				img.title="";
			}

			addEventListenerAbstract(window,"beforeprint",function() { img.src=img.origsrc; img.runtimeStyle.filter=''; } );
			addEventListenerAbstract(window,"afterprint",function() { fixImage(img); } );
		}
	}
}


function addEventListenerAbstract(element,the_event,command,capture)
{
	if(element)
	{
		if(element.addEventListener)
		{
			
			return element.addEventListener(the_event,command,capture);
		}
		else if(element.attachEvent)
		{
			
			return element.attachEvent("on"+the_event,command);
		}
		else return false;
	}
	else return false;
}
function cancelBubbling(event,for_element)
{
	if (!for_element) for_element='';

	if (!event) event=window.event;
	var src=event.srcElement?event.srcElement:event.target;

	if (src.nodeName.toLowerCase()==for_element)
	{
		if (event.stopPropagation) event.stopPropagation();
		event.cancelBubble=true;
		return true;
	}
	return false;
}

function keep_stub(starting_url) 
{
	var to_add='',i;
	var search=(window.location.search=='')?'?':window.location.search.substr(1);
	var bits=search.split('&');
	var done_session=false;
	var gap_symbol;
	for (i=0;i<bits.length;i++)
	{
		if (bits[i].substr(0,5)=='keep_')
		{
			gap_symbol=(((to_add=='') && (starting_url))?'?':'&');
			to_add=to_add+gap_symbol+bits[i];
			if (bits[i].substr(0,13)=='keep_session=') done_session=true;
		}
	}
	if (!done_session)
	{
		var session=ReadCookie('ocp_session');
		gap_symbol=(((to_add=='') && (starting_url))?'?':'&');
		if (session) to_add=to_add+gap_symbol+'keep_session='+window.encodeURIComponent(session);
	}
	return to_add;
}



function getInnerHTML(element) {

	// recursively copy the DOM into a string
	function Copy(srcDomNode, level) {
		var out='';

		if (typeof level == "undefined") level=1;
		if (level>1) {

			if (srcDomNode.nodeType==1) {

				// element node
				var thisNode=document.createElement(srcDomNode.nodeName);
				out+='<'+thisNode.nodeName;

				// attributes
				for (var a=0,attr=srcDomNode.attributes.length;a<attr;a++) {
					var aName=srcDomNode.attributes[a].name,aValue=srcDomNode.attributes[a].value;
					if (typeof aValue!='null') out+=' '+aName+'="'+escape_html(aValue)+'"';
				}
				
				if (srcDomNode.childNodes.length>0)
				{
					out+='>';

					// do child nodes
					for (var i=0,j=srcDomNode.childNodes.length;i<j;i++) out+=Copy(srcDomNode.childNodes[i],level+1);

					out+='</'+thisNode.nodeName+'>';
				} else
				{
					out+=' />';
				}
			}
			else if (srcDomNode.nodeType==3) {
				// text node
				out+= (srcDomNode.nodeValue?srcDomNode.nodeValue:"");
			}
			else if (srcDomNode.nodeType == 4) {
				// text node
				out+=(srcDomNode.nodeValue?"<![CDATA["+srcDomNode.nodeValue+"]]":"");
			}
		} else
		{
			// do child nodes
			for (var i=0,j=srcDomNode.childNodes.length;i<j;i++) out+=Copy(srcDomNode.childNodes[i],level+1);
		}
		
		return out;
	}
	
	return Copy(element);
}



function EntitiesToUnicode(din)
{
	if ((!din.replace) || (din.indexOf('&')==-1)) return din;

	if (!window.entity_rep_reg)
	{
		var reps={'amp':38,'gt':62,'lt':60,'quot':34,'hellip':8230,'middot':183,'ldquo':8220,'lsquo':8216,'rdquo':8221,'rsquo':8217,'mdash':8212,'ndash':8211,'nbsp':160,'times':215,
		'euro':8364,'pound':163,'bull':8226,'copy':169,'trade':8482,'dagger':8224,'yen':165,'laquo':171,'raquo':187,'larr':8592,'rarr':8594,'uarr':8593,'darr':8595};
		/*'acute':180,'cedil':184,'circ':710,'macr':175,'tilde':732,'uml':168,'Aacute':193,'aacute':225,'Acirc':194,'acirc':226,'AElig':198,
		'aelig':230,'Agrave':192,'agrave':224,'Aring':197,'aring':229,'Atilde':195,'atilde':227,'Auml':196,
		'auml':228,'Ccedil':199,'ccedil':231,'Eacute':201,'eacute':233,'Ecirc':202,'ecirc':234,'Egrave':200,
		'egrave':232,'ETH':208,'eth':240,'Euml':203,'euml':235,'Iacute':205,'iacute':237,'Icirc':206,
		'icirc':238,'Igrave':204,'igrave':236,'Iuml':207,'iuml':239,'Ntilde':209,'ntilde':241,'Oacute':211,
		'oacute':243,'Ocirc':212,'ocirc':244,'OElig':338,'oelig':339,'Ograve':210,'ograve':242,'Oslash':216,
		'oslash':248,'Otilde':213,'otilde':245,'Ouml':214,'ouml':246,'Scaron':352,'scaron':353,'szlig':223,
		'THORN':222,'thorn':254,'Uacute':218,'uacute':250,'Ucirc':219,'ucirc':251,'Ugrave':217,'ugrave':249,
		'Uuml':220,'uuml':252,'Yacute':221,'yacute':253,'yuml':255,'Yuml':376,'cent':162,'curren':164,
		'brvbar':166,'Dagger':8225,
		'frasl':8260,'iexcl':161,'image':8465,'iquest':191,'lrm':8206,
		'not':172,'oline':8254,'ordf':170,'ordm':186,'para':182,'permil':8240,'prime':8242,'Prime':8243,
		'real':8476,'reg':174,'rlm':8207,'sect':167,'shy':173,'sup1':185,'weierp':8472,
		'bdquo':8222,'lsaquo':8249,'rsaquo':8250,
		'sbquo':8218,'emsp':8195,'ensp':8194,'thinsp':8201,'zwj':8205,'zwnj':8204,
		'deg':176,'divide':247,'frac12':189,'frac14':188,'frac34':190,'ge':8805,'le':8804,'minus':8722,
		'sup2':178,'sup3':179,'alefsym':8501,'and':8743,'ang':8736,'asymp':8776,'cap':8745,
		'cong':8773,'cup':8746,'empty':8709,'equiv':8801,'exist':8707,'fnof':402,'forall':8704,'infin':8734,
		'int':8747,'isin':8712,'lang':9001,'lceil':8968,'lfloor':8970,'lowast':8727,'micro':181,'nabla':8711,
		'ne':8800,'ni':8715,'notin':8713,'nsub':8836,'oplus':8853,'or':8744,'otimes':8855,'part':8706,
		'perp':8869,'plusmn':177,'prod':8719,'prop':8733,'radic':8730,'rang':9002,'rceil':8969,'rfloor':8971,
		'sdot':8901,'sim':8764,'sub':8834,'sube':8838,'sum':8721,'sup':8835,'supe':8839,'there4':8756,
		'Alpha':913,'alpha':945,'Beta':914,'beta':946,'Chi':935,'chi':967,'Delta':916,'delta':948,
		'Epsilon':917,'epsilon':949,'Eta':919,'eta':951,'Gamma':915,'gamma':947,'Iota':921,'iota':953,
		'Kappa':922,'kappa':954,'Lambda':923,'lambda':955,'Mu':924,'mu':956,'Nu':925,'nu':957,
		'Omega':937,'omega':969,'Omicron':927,'omicron':959,'Phi':934,'phi':966,'Pi':928,'pi':960,
		'piv':982,'Psi':936,'psi':968,'Rho':929,'rho':961,'Sigma':931,'sigma':963,'sigmaf':962,
		'Tau':932,'tau':964,'Theta':920,'theta':952,'thetasym':977,'upsih':978,'Upsilon':933,'upsilon':965,
		'Xi':926,'xi':958,'Zeta':918,'zeta':950,'crarr':8629,'dArr':8659,'harr':8596,
		'hArr':8660,'lArr':8656,'rArr':8658,'uArr':8657,'clubs':9827,
		'diams':9830,'hearts':9829,'spades':9824,'loz':9674};*/

		window.entity_rep_reg={};
		for (var i in reps)
		{
			window.entity_rep_reg['&#'+reps[i]+';']=new RegExp('&'+i+';','g');
		}
	}

	for (var x in window.entity_rep_reg)
	{
		din=din.replace(window.entity_rep_reg[x],x);
	}
	return din;
}

function Load(xmlString) {
	var xml;
	if (typeof DOMParser!="undefined") xml=(new DOMParser()).parseFromString(xmlString,"application/xml");
	else {
		var ieDOM=["MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XMLDOM"];
		for (var i=0;i<ieDOM.length && !xml;i++) {
			try { xml=new ActiveXObject(ieDOM[i]);xml.loadXML(xmlString); }
			catch(e) {}
		}
	}

	return xml;
}

function Copy(domNode,xmlDoc,level) {
	if (typeof level=="undefined") level=1;
	if (level>1) {
		if (xmlDoc.nodeType==1) {
			// element node
			var thisNode=domNode.ownerDocument.createElement(xmlDoc.nodeName);

			// attributes
			for (var a=0,attr=xmlDoc.attributes.length;a<attr;a++) {
				var aName=xmlDoc.attributes[a].name,aValue=xmlDoc.attributes[a].value,evt=(aName.substr(0,2)=="on");
				if (!evt) {
					switch (aName) {
						case "class": thisNode.className=aValue; break;
						case "for": thisNode.htmlFor=aValue; break;
						default: thisNode.setAttribute(aName,aValue);
					}
				} else thisNode[aName]=eval('var x=function(event) { '+aValue+' }; x;');
			}

			// append node
			domNode=domNode.appendChild(thisNode);
		}
		else if (xmlDoc.nodeType==3) {
			// text node
			var text=(xmlDoc.nodeValue?xmlDoc.nodeValue:"");
			var test=text.replace(/^\s*|\s*$/g,"");

			if (test.indexOf("<!--")!=0 && (test.length<=3 || test.indexOf("-->")!=(test.length-3)))
			{
				if ((domNode.nodeName=='STYLE') && (!domNode.ownerDocument.createCDATASection))
				{
					domNode.cssText=text; /* needed for IE */
				} else
				{
					domNode.appendChild(domNode.ownerDocument.createTextNode(text));
				}
				domNode=null;
			}
		}
		else if (xmlDoc.nodeType==4) {
			// CDATA node
			var text=(xmlDoc.nodeValue?xmlDoc.nodeValue:"");
			if ((domNode.nodeName=='STYLE') && (!domNode.ownerDocument.createCDATASection))
			{
				domNode.cssText=text; /* needed for IE */
			} else
			{
				domNode.appendChild(domNode.ownerDocument./*createCDATASection*/createTextNode(text)); // use of createCDATASection causes weird bug in Firefox (sibling DOM nodes skipped)
			}
			domNode=null;
		}
	}

	
	if (domNode) for (var i=0,j=xmlDoc.childNodes.length;i<j;i++) Copy(domNode,xmlDoc.childNodes[i],level+1);
}
function setInnerHTML(element,tHTML,append) {
	if ((document.write) && (typeof element.innerHTML!="undefined") && (!document.xmlVersion))
	{
		var clone=element.cloneNode(true);
		try
		{
			if (append) element.innerHTML+=tHTML; else element.innerHTML=tHTML;
			return;
		}
		catch(ignore) {};
	}

	tHTML=EntitiesToUnicode(tHTML);

	
	tHTML="<root>"+tHTML+"</root>";
	var xmlDoc=Load(tHTML);
	if (element && xmlDoc) {
		if (!append) while (element.lastChild) element.removeChild(element.lastChild);
		Copy(element,xmlDoc.documentElement);

		var imgs=element.getElementsByTagName('img');
		for(var i=0;i<imgs.length;i++) fixImage(imgs[i]);
	}
}
