function addLoadEvent(func) {
  
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function popImg(imgURL,imgTitle,smallWidth,smallHeight){
	posX = 10;
	posY = 10;
	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
	}

	defaultWidth  = smallWidth + 20;
	defaultHeight = smallHeight + 20;
	var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+posX+',top='+posY;
	var optIE='scrollbars=yes,width=150,height=100,left='+posX+',top='+posY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html>\n<head>\n\t<title>Loading...</title>\n\t<style>body{margin:0px;}</style>');
		writeln('\t<style type="text/css">\n\t<!--');
		writeln('\t\tbody{background:#99ccff;margin:0px}');
		writeln('\t// -->\n\t</style>');
		writeln('\t<sc'+'ript language="JavaScript">\n\t<!--');
		writeln('\tvar isNN,isIE;');
		writeln('\tif(parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('\t\tisNN=(navigator.appName=="Netscape")?1:0;');
		writeln('\t\tisIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;\n\t}');
		writeln('\tfunction reSizeToImage(){');
		writeln('\t\tif(isIE){');
		writeln('\t\t\twindow.resizeTo(150,150);');
		writeln('\t\t\twidth=150-(document.body.clientWidth-document.images[0].width);');
		writeln('\t\t\theight=150-(document.body.clientHeight-document.images[0].height);');
		writeln('\t\t\twindow.resizeTo(width,height);\n\t\t}');
		writeln('\t\tif(isNN){');       
		writeln('\t\t\twindow.innerWidth=document.images["itemProduct"].width;');
		writeln('\t\t\twindow.innerHeight=document.images["itemProduct"].height;\n\t\t}\n\t}');
		writeln('\tfunction doTitle(){document.title="'+imgTitle+'";}');
		writeln('\t// -->\n\t</sc'+'ript>');
		writeln('</head>');
		writeln('\n<body scroll="no" onload="javascript: reSizeToImage();doTitle();self.focus()">');
		writeln('\n<img name="itemProduct" src="'+imgURL+'" style="display:block" alt="'+imgTitle+' image">\n\n</body>\n</html>');
		close();		
	}
}

function changec(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function showPic (whichpic, img, desc) {
	if (document.getElementById) {
		document.getElementById(img).src = whichpic.href;
		if (whichpic.title) {
			document.getElementById(desc).childNodes[0].nodeValue = whichpic.title;
		} else {
			document.getElementById(desc).childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	} else {
		return true;
	}
}
function showEvent (whichpic, img, ref, urlredir) {
	if (document.getElementById) {
		document.getElementById(img).src = whichpic.href;
		document.getElementById(ref).href = urlredir;
		return false;
	} else {
		return true;
	}
}

var currentImage = 0;
var endImage;
var thumbs;
var captionArray = new Array();

function galleryInit() {
	if (document.getElementById) {
		var el = document.getElementById('gallery');
		thumbs = el.getElementsByTagName('div');
		endImage = thumbs.length;
		
		document.getElementById('main-image').style.display = 'none';
		captionArray = document.getElementById("caption").getElementsByTagName("span");

		gantigbr (0);
		
		for(var i = 0; i < thumbs.length; i++) {
			thumbs[i].firstChild.setAttribute('href', 'javascript:gantigbr(' + i + ')');
		}
	}
}

function gantigbr (i) {
	thumb_src = thumbs[i].getElementsByTagName('img')[0].getAttribute('src');
	image_src = thumb_src.substring(0,thumb_src.length-5) + '.jpg';
	document.getElementById('gallery-image').style.backgroundImage='url(' + image_src + ')'	
	changecaption(i);
	deselectThumb(currentImage);			
	selectThumb(i);
	currentImage = i;
}

function selectThumb (i) {
	thumbs[i].className = 'selected';
}

function deselectThumb (i) {
	thumbs[i].className = '';
}

function changecaption(i) {
	captionArray[currentImage].className = "";
	captionArray[i].className = "show";
}

function nextImage () {
	if (currentImage == (endImage - 1)){
		gantigbr(0);
	} else {
		gantigbr(currentImage + 1);
	}
}

function prevImage () {
	if (currentImage == 0){
		gantigbr(endImage - 1);
	} else {
		gantigbr(currentImage - 1);
	}
}

//popup window di home
var newwindow = '';
function poptastic(url,name,left)
{
	newwindow=window.open(url,name,'height=305,width=229,left=' + left);
	if (window.focus) {newwindow.focus()}
}

function tutup()
{
	window.close()
}

function getCookie( name )
{
        var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie.length )
        {
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie.length;
                        return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }
        return "";
}

function popUpwin(URL,x,y,a,b) {
	window.open(URL, 'Rohan', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+x+',height='+y+',left = '+b+',top = '+a+'');
}

//showhide
function showHide (id,ident,tot_id) {
	for (i=1;i<=tot_id;i++) {
		document.getElementById(id + i).style.display = 'none';
		document.getElementById('txt'+id + i).style.display = 'none';
	}
	document.getElementById(id + ident).style.display = '';
	document.getElementById('txt'+id + ident).style.display = '';
	hide('selectgame');
}

function hide( targetId ){
 if (document.getElementById){
		target = document.getElementById( targetId );
				target.style.visibility = "hidden";
	}
}

function show( targetId ){
 if (document.getElementById){
		target = document.getElementById( targetId );
				target.style.visibility = "visible";
	}
}

