function trim() {
	var val = this;

	if (val != '') {
		var re = /^ +/;
		val = val.replace(re, '');
		re = / +$/;
		val = val.replace(re, '');
	}
	else {
		val = '';
	}
	return val;
}

String.prototype.trim = trim;

function ge() {
	var ea;
	
	for(var i=0;i<arguments.length;i++) {
		var e=arguments[i];
		
		if(typeof e=='string')
			e=document.getElementById(e);
			
		if(arguments.length==1)
			return e;
			
		if(!ea)
			ea=new Array();
			
		ea[ea.length]=e;
	}
	
	return ea;
}

function show() {
	for(var i=0;i<arguments.length;i++) {
		var element=ge(arguments[i]);
		
		if(element&&element.style)
			element.style.display='';
	}
		
	return false;
}

function hide() {
	for(var i=0;i<arguments.length;i++) {
		var element=ge(arguments[i]);
		
		if(element&&element.style)
			element.style.display='none';
	}

	return false;
}

function shown(el) {
	el=ge(el);
	
	return(el.style.display!='none');
}

function pageScrollX() {
	return document.body.scrollLeft||document.documentElement.scrollLeft;
}

function pageScrollY() {
	return document.body.scrollTop||document.documentElement.scrollTop;
}

function elementX(obj) {
	var curleft=0;
	
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			curleft+=obj.offsetLeft;
			obj=obj.offsetParent;
		}
	}
	else if(obj.x)
		curleft+=obj.x;return curleft;
}

function elementY(obj) {
	var curtop=0;
	
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			curtop+=obj.offsetTop;
			obj=obj.offsetParent;
		}
	}
	else if(obj.y)
		curtop+=obj.y;
	
	return curtop;
}

function getViewportWidth() {
	var width=0;
	
	if(document.documentElement&&document.documentElement.clientWidth) {
		width=document.documentElement.clientWidth;
	}
	else if(document.body&&document.body.clientWidth) {
		width=document.body.clientWidth;
	}
	else if(window.innerWidth) {
		width=window.innerWidth-18;
	}

	return width;
}

function getIEVerPage() {
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
	var tempVers = navigator.appVersion;
	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 ) {
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}

function changeStyleButtonLink() {
	var styleS = document.styleSheets[0];

	if (styleS.rules)
		styleS.cssRules = styleS.rules;

	if (styleS.cssRules[0]) 
		if (document.all && getIEVerPage() < 6) 
			if (styleS.cssRules[0].style.color) 
				if (styleS.cssRules[0].style.color == "#528BC0") 
					styleS.cssRules[0].style.cursor = "hand";
}

function bind(obj,method) {
	obj=obj||window;
	var args=[];
	
	for(var ii=2;ii<arguments.length;ii++) {
		args.push(arguments[ii]);
	}
	
	return function() {
		var _args=[];
		
		for(var kk=0;kk<args.length;kk++) {
			_args.push(args[kk]);
		}
		
		for(var jj=0;jj<arguments.length;jj++) {
			_args.push(arguments[jj]);
		}
		
		if(typeof(method)=="string") {
			if(obj[method]) {
				return obj[method].apply(obj,_args);
			}
		}
		else {
			return method.apply(obj,_args);
		}
	}
}

Function.prototype.bind=function(context) {
	var argv=[arguments[0],this];
	var argc=arguments.length;
	
	for(var ii=1;ii<argc;ii++) {
		argv.push(arguments[ii]);
	}
	
	return bind.apply(null,argv);
}

function addEventBase(obj,type,fn,name_hash) {
	if(obj.addEventListener)
		obj.addEventListener(type,fn,false);
	else if(obj.attachEvent) {
		obj["e"+type+fn+name_hash]=fn;
		obj[type+fn+name_hash]=function() {
			obj["e"+type+fn+name_hash](window.event);
		}
		obj.attachEvent("on"+type,obj[type+fn+name_hash]);
	}
}

function removeEventBase(obj,type,fn,name_hash) {
	if(obj.removeEventListener)
		obj.removeEventListener(type,fn,false);
	else if(obj.detachEvent) {
		obj.detachEvent("on"+type,obj[type+fn+name_hash]);
		obj[type+fn+name_hash]=null;
		obj["e"+type+fn+name_hash]=null;
	}
}

function break_menu(arrow,menu,event,arrow_class,arrow_old_class) {
	if(menu.style.display=='none') {
		menu.style.display='block';
		var old_arrow_classname=arrow_old_class?arrow_old_class:arrow.className;
		
		arrow.className=arrow_class?arrow_class:'gmenu_active';
		var justChanged=true;
		var shim=ge(menu.id+'_iframe');
		
		if(shim) {
			shim.style.top=menu.style.top;
			shim.style.right=menu.style.right;
			if (!(document.all && getIEVerPage() < 5.5)) {
				shim.style.display='block';
			}
			shim.style.width=(menu.offsetWidth+2)+'px';
			shim.style.height=(menu.offsetHeight+2)+'px';
		}

		
		menu.offclick=function(e) {
			if(!justChanged) {
				hide(this);
				
				arrow.className=old_arrow_classname;
				
				var shim=ge(menu.id+'_iframe');
				
				if(shim) {
					shim.style.display='none';
					shim.style.width=menu.offsetWidth+'px';
					shim.style.height=menu.offsetHeight+'px';
				}
				
				removeEventBase(document,'click',this.offclick,menu.id);
			}
			else {
				justChanged=false;
			}
		}.bind(menu);
		
		addEventBase(document,'click',menu.offclick,menu.id);
	}
	
	return false;
}

function show_note(arrow,menu) {
	if(menu.style.display=='none') {
		menu.style.display='block';
		
		var shim=ge(menu.id+'_iframe');

		if(shim) {
			shim.style.top=menu.style.top;
			shim.style.right=menu.style.right;
			
			if (!(document.all && getIEVerPage() < 5.5)) {
				shim.style.display='block';
			}
			shim.style.width=(menu.offsetWidth+0)+'px';
			shim.style.height=(menu.offsetHeight+0)+'px';
		}
	}
	
	return false;
}

function hide_note(arrow,menu) {
	if(menu.style.display=='block') {
		menu.style.display='none';
		
		var shim=ge(menu.id+'_iframe');
		
		if(shim) {
			shim.style.display='none';
			shim.style.width=menu.offsetWidth+'px';
			shim.style.height=menu.offsetHeight+'px';
		}
	}
	
	return false;
}

function newWindow(page, width, height){
	if (width == 0 && height == 0)
		var OpenWin = this.open(page, "_blank", "toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,fullscreen=yes");
	else
		var OpenWin = this.open(page, "_blank", "toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,ScreenX=0,ScreenY=0,top=0,left=0,width=" + width+ ",height=" + height);
}

function newWindowAll(page, width, height){
	if (width == 0 && height == 0)
		var OpenWin = this.open(page, "_blank", "toolbar=yes,menubar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,fullscreen=yes");
	else
		var OpenWin = this.open(page, "_blank", "toolbar=yes,menubar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,ScreenX=0,ScreenY=0,top=0,left=0,width=" + width+ ",height=" + height);
}

function showDate(language){
	if (language == 1){
		var aDays=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
		var aMonths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	}
	else{
		var aDays=new Array("Minggu","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu");	
		var aMonths=new Array("Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agt","Sep","Okt","Nov","Des");
	}
	
	var today=new Date();
	var currentday=today.getDay();
	var currentmonth=today.getMonth();
	var currentdate=today.getDate();
	if(navigator.userAgent.indexOf("MSIE 4.0")!=-1) version=0;
	else if(navigator.userAgent.indexOf("MSIE 3.0")!=-1) version=1;
	else if(navigator.userAgent.indexOf("MSIE 5.0")!=-1) version=0;
	else if(navigator.userAgent.indexOf("Mozilla/3.0")!=-1) version=1;
	else if(navigator.userAgent.indexOf("Mozilla/2.0")!=-1) version=1;
	else if(navigator.userAgent.indexOf("Mozilla/4.5")!=-1) version=1;
	else version=0;
	var currentyear=0;
	if (version == 0) {currentyear=today.getFullYear();}
	if (version == 1) {currentyear=today.getYear();}
	document.write("&nbsp;");
	if (language == 1){
		document.write(aDays[currentday]+", ");
		document.write(aMonths[currentmonth]+" ");
		document.write(currentdate+", ");
		document.write(currentyear);
	}
	else{
		document.write(aDays[currentday]+", ");
		document.write(currentdate+" ");
		document.write(aMonths[currentmonth]+" ");
		document.write(currentyear);
	}
	return true;
}

function roundPrice(price) {
	remain = price % 1000;
	
	if (remain > 500) {
		if (remain > 0)
			price += (1000 - remain);
	}
	else {
		if (remain > 0)
			price -= remain;
	}
	
	return price;
}

if (document.all && getIEVerPage() < 5.5) {
	/**
	 * Call a function as though it was a method of a given object, using the set
	 * of arguments supplied.
	 * @param thisArg the value or object to use as <code>this</code>.  Defaults to <code>window</code> if no value (or null) is supplied
	 * @param argArray an (optional) array or arguments object.  The members of the array are used as parameters to the method call, in the order given
	 * @return the result of the method call
	 * @author <a href="http://hexmen.com/blog/">Ash Searle</a>
	 * @license http://creativecommons.org/licenses/by/2.5/
	 */
	Function.prototype.apply = function(thisArg, argArray) {
	    if (typeof this != 'function') {
		throw new Error('apply called on incompatible object (not a function)');
	    }
	    if (argArray != null && !(argArray instanceof Array) && typeof argArray.callee != 'function') {
		throw new Error('The 2nd argument to apply must be an array or arguments object');
	    }

	    thisArg = (thisArg == null) ? window : Object(thisArg);
	    thisArg.__applyTemp__ = this;

	    // youngpup's hack
	    var parameters = [], length = (argArray || '').length >>> 0;
	    for (var i = 0; i < length; i++) {
		parameters[i] = 'argArray[' + i + ']';
	    };
	    var functionCall = 'thisArg.__applyTemp__(' + parameters + ')';

	    try {
		return eval(functionCall)
	    } finally {
		try { delete thisArg.__applyTemp__ } catch (e) { /* ignore */ }
	    }
	}

	/**
	 * Call a function as though it was a method of a given object.  Any additional
	 * arguments supplied are used in the order given as parameters to the method
	 * call.
	 * @param thisArg the value or object to use as <code>this</code>.  Defaults to <code>window</code> if no value (or null) is supplied
	 * @return the result of the method call
	 * @author <a href="http://hexmen.com/blog/">Ash Searle</a>
	 * @license http://creativecommons.org/licenses/by/2.5/
	 */
	Function.prototype.call = function(thisArg) {
	    return this.apply(thisArg, Array.prototype.slice.apply(arguments, [1]));
	}

	/**
	 * Append any supplied arguments to the end of the array, in the order given.
	 * @return the new length of the array
	 * @author <a href="http://hexmen.com/blog/">Ash Searle</a>
	 * @license http://creativecommons.org/licenses/by/2.5/
	 */
	Array.prototype.push = function() {
	    var n = this.length >>> 0;
	    for (var i = 0; i < arguments.length; i++) {
		this[n] = arguments[i];
		n = n + 1 >>> 0;
	    }
	    this.length = n;
	    return n;
	};

	/**
	 * Remove the last element of the array and return it.
	 * @return the element removed (if any), otherwise return <code>undefined</code>
	 * @author <a href="http://hexmen.com/blog/">Ash Searle</a>
	 * @license http://creativecommons.org/licenses/by/2.5/
	 */
	Array.prototype.pop = function() {
	    var n = this.length >>> 0, value;
	    if (n) {
		value = this[--n];
		delete this[n];
	    }
	    this.length = n;
	    return value;
	};
}