var popupobj = new Array();

function findPos(obj) {
	var coords = { x: 0, y: 0 };
	if (obj.offsetParent) {
		while (obj) {
			coords.x += obj.offsetLeft;
			coords.y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return coords.x;
}

function searchinarray(objpop){
	var found = false;
	for (i = 0; i < popupobj.length; i++){
		if (popupobj[i][0] == objpop){
			found = true;
			break;
		}
	}
	if (found)
		return i;
	else
		return "none";
}

function searchhighlight(objimgsrc){
	var found = false;
	for (i = 0; i < imgsrc.length; i++){
		if (objimgsrc.indexOf(imgsrc[i]) != -1){
			found = true;
			break;
		}
	}
	if (found)
		return i;
	else
		return "none";
}

function positioningbaloon(name){
	var c = document.getElementById('popup_baloon_'+name);
	var d = document.getElementById('popup_'+name+'_parent');
	var elpos = findPos(d);
	c.style.left = parseInt(parseInt(elpos)+parseInt(80))+'px';
	c.style.bottom = d.offsetHeight+'px';
	c.style.display = 'block';
}

function showpopup(objpop,objparent,objimg){
	//check if objpop already in array
	
	closeallpopup(objpop);
	
	if (objpop == 'popup_ann'){
		document.getElementById('anntext').innerHTML = 'Announcement';
		document.getElementById('anntext').className = 'frame_text';
	}
	if (objpop == 'popup_sugg'){
		document.getElementById('suggtext').innerHTML = 'Kritik &amp; Saran';
		document.getElementById('suggtext').className = 'frame_text';
	}
	
	var founds = searchinarray(objpop);
	if (founds == "none"){
		if (popupobj.length == 0){
			popupobj[0] = new Array(4);
			popupobj[0][0] = objpop;
			popupobj[0][1] = "1";
			popupobj[0][2] = objparent;
			popupobj[0][3] = objimg;
		}
		else{
			popupobj[popupobj.length] = new Array(4);
			popupobj[popupobj.length-1][0] = objpop;
			popupobj[popupobj.length-1][1] = "1";
			popupobj[popupobj.length-1][2] = objparent;
			popupobj[popupobj.length-1][3] = objimg;
		}
	}
	else{
		if (popupobj[i][1] == "1"){
			closepopup(objpop,objparent,objimg);
			return;
		}
		else{
			popupobj[i][1] = "1";
		}
	}
	
	var c = document.getElementById(objpop);
	var d = document.getElementById(objparent);
	var e = document.getElementById(objimg);
	var elpos = findPos(d);
	var widthel = c.style.width;
	widthel = widthel.replace("px","");
	var posexceed = parseInt(elpos) + parseInt(widthel);
	if (posexceed > screen.width)
		elpos = elpos-widthel+d.offsetWidth;
	c.style.left = elpos+'px';
	c.style.bottom = d.offsetHeight+'px';
	c.style.display = 'block';
	d.style.backgroundColor="#FFFFFF";
	e.src=img[searchhighlight(e.src.replace("_off","_on"))].src;
}

function closepopup(objpop,objparent,objimg){
	var founds = searchinarray(objpop);
	if (founds != 'none'){
		if (popupobj[founds][1] == "1"){
			popupobj[founds][1] = "0";
		}
	}
	var c = document.getElementById(objpop);
	var d = document.getElementById(objparent);
	var e = document.getElementById(objimg);
	c.style.display = 'none';
	d.style.backgroundColor="";		
	e.src=img[searchhighlight(e.src.replace("_on","_off"))].src;
}

function closeallpopup(excp){
	for (var nm = 0; nm < popupobj.length; nm++){
		if (popupobj[nm][0] != excp){
			closepopup(popupobj[nm][0],popupobj[nm][2],popupobj[nm][3]);
		}
	}
}

function objmouseover(objpop,objparent,objimg){
	var founds;
	if (objpop != '')
		founds = searchinarray(objpop);
	else
		founds = 'none';
	if (founds != 'none'){
		if (popupobj[founds][1] == '0'){
			var d = document.getElementById(objparent);
			var e = document.getElementById(objimg);
			if (d.style.backgroundColor == '')
				d.style.backgroundColor="#FFFFFF";
			e.src=img[searchhighlight(e.src.replace("_off","_on"))].src;
		}
	}
	else{
		var d = document.getElementById(objparent);
		var e = document.getElementById(objimg);
		if (d.style.backgroundColor == '')
			d.style.backgroundColor="#FFFFFF";
		e.src=img[searchhighlight(e.src.replace("_off","_on"))].src;
	}
}

function objmouseout(objpop,objparent,objimg){
	var founds;
	if (objpop != '')
		founds = searchinarray(objpop);
	else
		founds = 'none';
	if (founds != 'none'){
		if (popupobj[founds][1] == '0'){
			var d = document.getElementById(objparent);
			var e = document.getElementById(objimg);
			if (d.style.backgroundColor.toLowerCase() == 'rgb(255, 255, 255)' || d.style.backgroundColor.toLowerCase() == '#ffffff' || d.style.backgroundColor.toLowerCase() == 'white')
				d.style.backgroundColor="";
			e.src=img[searchhighlight(e.src.replace("_on","_off"))].src;
		}
	}
	else{
		var d = document.getElementById(objparent);
		var e = document.getElementById(objimg);
		if (d.style.backgroundColor.toLowerCase() == 'rgb(255, 255, 255)' || d.style.backgroundColor.toLowerCase() == '#ffffff' || d.style.backgroundColor.toLowerCase() == 'white')
			d.style.backgroundColor="";
		e.src=img[searchhighlight(e.src.replace("_on","_off"))].src;
	}
}

function switch_style(C,E){
	var F=1;
	if(F==""){
		return 
	}
	var B=new String(window.location);
	var A=new String("");
	B=B.split("#");
	if(B[1]){
		A="#"+B[1]
	}
	B=B[0];
	if(B.indexOf(E+"id=")!=-1&&is_regexp){
		var D=new RegExp(E+"id=\\d+&?");
		B=B.replace(D,"")
	}
	if(B.indexOf("?")==-1){
		B+="?"
	}
	else{
		lastchar=B.substr(B.length-1);
		if(lastchar!="&"&&lastchar!="?"){
			B+="&"
		}
	}
	window.location=B+E+"id="+F+A
}

function getKeyEvent(e){
	var keynum;
	if(window.event) 
		keynum = e.keyCode;
	else if(e.which) 
		keynum = e.which;
	return keynum;
}

function gotoblog(){
	var uname = document.getElementById("usernamebloggo").value;
	window.open("http://blog.ngobrolaja.com/"+uname,"_blank");
}

function checkenterblog(evt){
	if (getKeyEvent(evt) == 13){
		gotoblog();
	}
}
