var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)
var login_onclick = 0;
var register_onclick = 0;

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
obj.visibility=visible
}
else if (e.type=="click"){
obj.visibility=hidden
}
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function clearpopupbrowseredge(obj, whichedge){
var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropopupobj.contentmeasure=dropopupobj.offsetWidth
		if (windowedge-dropopupobj.x < dropopupobj.contentmeasure)
		edgeoffset=dropopupobj.contentmeasure-obj.offsetWidth
	}
	else{
		var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropopupobj.contentmeasure=dropopupobj.offsetHeight
		if (windowedge-dropopupobj.y < dropopupobj.contentmeasure){ //move up?
			edgeoffset=dropopupobj.contentmeasure+obj.offsetHeight
			if ((dropopupobj.y-topedge)<dropopupobj.contentmeasure) //up no good either?
			edgeoffset=dropopupobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}

function mfsShowDialog(obj, e, dropmenuID, statusPopup,isTop){
var e = window.event || e
var topmenuoffset=(typeof isTop!="undefined")? 6 : 0
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropopupobj!="undefined") //hide previous menu
	dropopupobj.style.visibility = "hidden";

dropopupobj=document.getElementById(dropmenuID)
if (statusPopup == 0){
	dropopupobj.style.visibility="hidden";
}else{
	dropopupobj.style.visibility="visible";
}
dropopupobj.x= getposOffset(obj, "left")
dropopupobj.y=getposOffset(obj, "top")
dropopupobj.style.left=dropopupobj.x - clearpopupbrowseredge(obj, "rightedge")+ "px";
dropopupobj.style.top=dropopupobj.y - clearpopupbrowseredge(obj, "bottomedge")+ obj.offsetHeight-topmenuoffset + "px";
}

function dropdownmenu(obj, e, dropmenuID, isTop){
var e=window.event || e
var topmenuoffset=(typeof isTop!="undefined")? 6 : 0
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight-topmenuoffset+"px"
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobj){
if (document.getElementById){
var subobj=document.getElementById(subobj)
subobj.style.left=getposOffset(curobj, "left")+"px"
subobj.style.top=getposOffset(curobj, "top")+"px"
subobj.style.display="block"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}

////Random Order Contents script////////////

function randomizeContent(classname){
var contents=randomizeContent.collectElementbyClass(classname)
contents.text.sort(function() {return 0.5 - Math.random();})
for (var i=0; i<contents.ref.length; i++){
contents.ref[i].innerHTML=contents.text[i]
contents.ref[i].style.visibility="visible"
}
}

randomizeContent.collectElementbyClass=function(classname){ //return two arrays containing elements with specified classname, plus their innerHTML content
var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
var contentobj=new Object()
contentobj.ref=new Array() //array containing references to the participating contents
contentobj.text=new Array() //array containing participating contents' contents (innerHTML property)
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (var i=0; i<alltags.length; i++){
if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1){
contentobj.ref[contentobj.ref.length]=alltags[i]
contentobj.text[contentobj.text.length]=alltags[i].innerHTML
}
}
if (document.all){ //remove first DIV from group in IE
	contentobj.ref.shift()
	contentobj.text.shift()
}
return contentobj
}

////Dynamic Assign event handler////////////

function assignmyevents(){
var topitem1=document.getElementById("topmenuitem1")
var topitem2=document.getElementById("topmenuitem2")
var topitem3=document.getElementById("topmenuitem3")
var topitem4=document.getElementById("topmenuitem4")
var login=document.getElementById("login")
var register=document.getElementById("register")
var edit=document.getElementById("editprofile")
var logout=document.getElementById("logout")
var keysearch=document.getElementById("keywords")

topitem1.onmouseover=function(event){
	dropdownmenu(this, event, 'anylinkmenu1')
}

topitem2.onmouseover=function(event){
	dropdownmenu(this, event, 'anylinkmenu2')
}
/*
topitem3.onmouseover=function(event){
	var subMenu3 =document.getElementById("anylinkmenu3")	
	if (subMenu3 != null){
		dropdownmenu(this, event, 'anylinkmenu3')
	}
}

topitem4.onmouseover=function(event){
	dropdownmenu(this, event, 'anylinkmenu4')
}
*/

var loginSection = document.getElementById("loginSection")
var registerSection = document.getElementById("registerSection")
loginSection.onclick = function(event){
	if (login_onclick == 0){
		login_onclick = 1;
		register_onclick = 0;
		showPopupMenuStatus(this,1,1);
		if (registerSection != null){
			showPopupMenuStatus(registerSection,0,2);
		}
	}else{
		login_onclick = 0;
		showPopupMenuStatus(this,0,1);
	}
	mfsShowDialog(this, event, 'divLogin',login_onclick);
}
if (registerSection != null){	
	registerSection.onclick = function(event){
		if (register_onclick == 0){
			register_onclick = 1;
			login_onclick = 0;
			showPopupMenuStatus(this,1,2);
			showPopupMenuStatus(loginSection,0,1);
			
		}else{
			register_onclick = 0;
			showPopupMenuStatus(this,0,2);
		}
		mfsShowDialog(this, event, 'divRegister',register_onclick);
	}
}

function showPopupMenuStatus(obj,status,pictureId){
	var objImage = document.getElementById("arrowPopup_" + pictureId);
	if (status == 1){
		obj.className = "current1";	
		objImage.src = "/images/up_arrow.gif";
	}else{
		obj.className = "";
		objImage.src = "/images/down_arrow.gif";
	}
}
/*
var divLogin = document.getElementById("divLogin");
divLogin.onclick = function(event){
	
	return false;
}

window.onclick = function(){
	if (login_onclick == 1 || register_onclick == 1){
		login_onclick = 0;
		register_onclick = 0;
		showPopupMenuStatus(loginSection,0,1);
		showPopupMenuStatus(registerSection,0,2);
		dropopupobj.style.visibility = "hidden";
	}
}
*/
if (login!=null){
login.onclick=function(){window.location=this.title}
register.onclick=function(){window.location=this.title}
}
else if (edit!=null){
edit.onclick=function(){window.location=this.title}
logout.onclick=function(){window.location=this.title}
}

if (keysearch){
	keysearch.onfocus=function(){clearText(this)}
}
}


function _addEvent(target, functionref, tasktype) {
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent)
		target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
}

/* Anh Le start 20090408 */

var preFeaturedNews = new Array();
var preFeaturedEvents = new Array();

function removeSelectFeatured(id,value){	
	var obj = document.getElementById(id);
	for(idx = 0; idx < obj.options.length; idx ++){
		if (obj.options[idx].value == value){
			obj.options[idx] = null;
			return;
		}
	}
}

function restoreSelectFeatured(id,value){
	var optionObject = new Option(value,value);
	var selectObject = document.getElementById(id);
	var optionRank = selectObject.options.length;
    selectObject.options[optionRank] = optionObject;
}
function SetDefaultValue(numNews, numEvents){
	var tags = document.getElementsByTagName('select'); 
	var orderNews = 0;
	var orderEvents = 0;	
		
	for (var i=0;i<=numNews;i++)
	{
		preFeaturedNews[i] = "";
	}
	
	for (var i=0;i<=numEvents;i++)
	{
		preFeaturedEvents[i] = "";
	}
	
	for(var idx= 0; idx < tags.length; idx++){		
		if (tags[idx].id.substring(0,4) == 'news')
		{
			orderNews++;
			featuredNewsChanged(tags[idx].id,orderNews);
		}			
		if (tags[idx].id.substring(0,5) == 'event')
		{
			orderEvents++;
			featuredEventsChanged(tags[idx].id,orderEvents);
		}		
	}
}
function featuredEventsChanged(id,order){
	var idx = 0;
	var obj = document.getElementById(id);
	var valSel = obj.value;	
	var tags = document.getElementsByTagName('select'); 
	if (valSel != "")
	{
		for(idx = 0; idx < tags.length; idx ++){
			if (tags[idx].id.substring(0,5) == 'event' && tags[idx].id != id)
			{
				removeSelectFeatured(tags[idx].id,valSel);
			}			
		}
	}
	if (preFeaturedEvents[order] != null){
		for(idx = 0; idx < tags.length; idx++){
			if (tags[idx].id.substring(0,5) == 'event' && tags[idx].id != id)
			{
				restoreSelectFeatured(tags[idx].id,preFeaturedEvents[order]);
			}			
		}
	}
	preFeaturedEvents[order] = valSel;
}

function featuredNewsChanged(id,order){
	var idx = 0;
	var obj = document.getElementById(id);
	var valSel = obj.value;	
	var tags = document.getElementsByTagName('select'); 
	if (valSel != "")
	{
		for(idx = 0; idx < tags.length; idx ++){
			if (tags[idx].id.substring(0,4) == 'news' && tags[idx].id != id)
			{
				removeSelectFeatured(tags[idx].id,valSel);
			}			
		}
	}
	if (preFeaturedNews[order] != null){
		for(idx = 0; idx < tags.length; idx++){
			if (tags[idx].id.substring(0,4) == 'news' && tags[idx].id != id)
			{
				restoreSelectFeatured(tags[idx].id,preFeaturedNews[order]);
			}			
		}
	}
	preFeaturedNews[order] = valSel;
}
/* Anh Le end 20090408 */

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
  	{
		// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}

function GetTableHeight(tableId){
	return document.getElementById(tableId).offsetHeight;
}

function DisplayUpAndDownArrow(tableId, upArrowId, downArrowId, divHeight){
	tableHeight = GetTableHeight(tableId);
//	alert(tableId + '|' + tableHeight);
	upArrow = document.getElementById(upArrowId);
	downArrow = document.getElementById(downArrowId);

	if (tableHeight >= divHeight){
		upArrow.style.display = "inline";
		downArrow.style.display = "inline";
	}
}

//start get from sponsors_frontend
function openPopup(uid, fullname)
{
  	window.open('/expertShortBlo.php?uid=' + uid + '&fullname=' + fullname, '', 'width=587,height=400,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
  	return;
}
function openEmailPopup(title, url){
	window.open('/popup/sendEmail/' + title + '/' + url, 'emailToFriend', 'width=587,height=585,scrollbars=yes');
}
//end get from sponsors_frontend