var openedMenu=null;
var boldedCaller=null;

function openedOnLoad(menuIndex, itemIndex){
	var curCaller = document.getElementById('btn'+menuIndex);
	var curMenu = document.getElementById('menu'+menuIndex);
	curMenu.rows[itemIndex-1].style.fontWeight='bold';
	openMenu('menu'+menuIndex, curCaller);
}

function openMenu(menuToOpen, caller){
	var curMenu = document.getElementById(menuToOpen);
	if(curMenu != openedMenu){
		if(openedMenu != null){
			openedMenu.style.display='none';
			openedMenu.parentNode.style.backgroundColor='#E65200';
			boldedCaller.style.fontWeight='normal';
		}
		curMenu.style.display='inline';
		curMenu.parentNode.style.backgroundColor='#FE7500';
		caller.style.fontWeight='bold';
		openedMenu=curMenu;
		boldedCaller=caller;
	}else{
		curMenu.style.display='none';
		curMenu.parentNode.style.backgroundColor='#E65200';
		caller.style.fontWeight='normal';
		openedMenu=null;
	}
}

function selfReload(v){
	if(v.indexOf('changLang')!=-1)
		return;
	if(window.location.href.indexOf(".php") > 0)
		pos=window.location.href.substring(0,window.location.href.indexOf(".php")+4);
	else
		pos=window.location.href + "index.php";
	window.location.href=pos+"?"+v;
}

function openPopUp(popURL, popName, popWidth, popHeight, popParams){	
	if( !window.outerWidth ) // for IE
		if( window.screenLeft ){ // under windows
			destX = (window.screenLeft-8) + (document.body.offsetWidth+8)/2 - popWidth/2;
			destY = (window.screenTop-142) + (document.body.offsetHeight+142)/2 - popHeight/2;
		}else{ // under MacOS
			destX = window.screen.width/2 - popWidth/2;
			destY = window.screen.availHeight/2 - popHeight/2;
		}
	else{ // for NS
			destX = window.screenX + window.outerWidth/2 - popWidth/2;
			destY = window.screenY + window.outerHeight/2 - popHeight/2;
	}
	destX=Math.round(destX);
	destY=Math.round(destY);
	winObj=window.open(popURL, popName, 'left='+destX+',top='+destY+',width='+popWidth+',height='+popHeight+','+popParams);
	winObj.focus();
	return winObj;
} 

function Ecard(Region,Num){
	cardName=regionArray[Region]+Num;
	if((selNum==Num) && (selReg==Region)){
		document.getElementById("ecardVal").value="";
		document.getElementById(cardName).style.border='0px';
		theURL="";
		Pos=0;
		selNum=selReg=-1;
	}else{
		selNum=Num;
		selReg=Region;
		for(n in regionArray){
			for(i in ecardArray){
				if((Num==ecardArray[i]) && (Region==n)){
					document.getElementById(regionArray[n]+ecardArray[i]).style.border='solid orange 2px';
					document.getElementById("ecardVal").value=Num;
					document.getElementById("ecardReg").value=regionArray[Region];
					document.getElementById("ecardComment").value=escape(ecardComme[i]);
					document.getElementById("ecardPos").value=ecardPos[i];
					
					theURL="view.php?cardName="+regionArray[Region]+"/ca_"+ecardArray[i]+"&ecardComme="+escape(ecardComme[i]);
					Pos=ecardPos[i]
				}else{
					
					document.getElementById(regionArray[n]+ecardArray[i]).style.border='0px';
				}
			}
		}
	}
}
function Open(){
	if(theURL.length!=0){
		param='width=510,height=405';
		window.open(theURL,'view',param);
	}
}

