// JavaScript Document

function wqTabs(id_tab,selected){
	$(id_tab).addClass('tabs');
	$('ul:first',id_tab).addClass('basictab');
	
	$(id_tab+" li a").each(function(){
		if($(this).attr('href') == selected){
			$(this).addClass('selected');
		}
	})
	
	$(id_tab+' li').each(function(){
								  
		if(selected != null){
			$(id_tab+' .content').each(function(){
				$(this).css('display','none');
			})
			$(selected).css('display','');	
		}
		
		$("a",this).click(function(){
				$(id_tab+" li a").each(function(){
						$(this).removeClass('selected');	
						var idx=$(this).attr('href');
						$(idx).css('display','none');
				})
				$(this).addClass('selected');
				var idxa=$(this).attr('href');
				$(idxa).fadeIn(1000);
				return false;
		});
	})
}

function winClose(id) 
{	
	if (document.getElementById(id) != null) {
		var d = document.getElementById(id);
		d.style.display='none';
		d.parentNode.removeChild(d);
	}
}

function xAlert(txt){
	$('#body').append('<div id="xAlert">'+txt+'</div>');	
	$('#xAlert').dialog({
		autoOpen: false,
		width: 300,
		buttons: {
				"Ok": function() { 
						$(this).dialog("close"); 
				  }
		},
		modal:true,
		title:'Alert'
	});
	$('#xAlert').dialog('open');	
}


function postForm(url,formID,targetResult){
		loading();
		var $form = $( "#"+formID+"" ),
			term = $form.serializeArray(),
			url = url;
			
		$.post( url, term ,
		  function( data ) {
			  $( "#"+targetResult+"" ).html( data );
		  }
		);
}

function openSec(url,container){
	if(arguments[2] != 'no-load'){
		loading();
	}
	url = url.split(' ').join('+');
	$('#'+container+'').load(url);
}

function loading(tx){
	if(tx == 'end'){
		if(document.getElementById('blockLoading_23423') != null){
			winClose('blockLoading_23423');
		}
	} else {
		var hsd='<div id="blockLoading_23423" class="opac70" onclick="//winClose(\'blockLoading_23423\')" style="background:#000">'+
					'<center>'+
					'<span style="position:relative;top:40px" >Loading... <img src="'+SITE+'/images/mloader.gif" align="absmiddle" style="width:30px" />'+
					'</center>'+
				'</div>';
		$('body').append(hsd);
		var hgtBody=document.getElementById('mainbody').offsetHeight;
		$('#blockLoading_23423').css({'position':'absolute','top':'0px','left':'0px','width':'100%','height':hgtBody+'px','z-index':'9999'});
	}
	//setTimeout(function(){var ld=$('#fileSedangLoading').val();if( parseInt(ld) == 0){loading()},100);
}

function winPop(url,title,id,wdth,hght,tp,lft){
	$('#body').append('<div id="'+id+'" style="position:relative"><div id="'+id+'_layout"></div></div>');
	$('#'+id+'').dialog({
		autoOpen:false,
		width:wdth,
		height:hght,
		modal:true,
		title:title
	});
	$('#'+id+'').dialog('open');
	$('#'+id+'_layout').html('');
	setTimeout(function(){openSec(url,id+'_layout');},100);
}

function popUp(title,id,wdth,hght){
	$('#body').append('<div id="'+id+'" style="position:relative"><div id="'+id+'_layout"></div></div>');
	$('#'+id+'').dialog({
		autoOpen:false,
		width:wdth,
		height:hght,
		title:title
	});
	$('#'+id+'').dialog('open');
	$('#'+id+'_layout').html('');
}

function sxTheChat(e,n,id,nx,me){
			var dKey=e.keyCode? e.keyCode : e.charCode ? e.charCode : e.which;
			if(dKey == 13){
				var vshr=n.value;
				var decoded = $(n).html(vshr).text();
				chat(id,decoded,me,nx);
				setTimeout(function(){
					//alert(SITE+'/load.php?d=chat&f=send_text&id='+id+'&tx='+decoded,'tampaForHidLoad','no-load');
					openSec(SITE+'/load.php?d=chat&f=send_text&id='+id+'&tx='+decoded,'tampaForHidLoad','no-load');
				},100);
				
				n.value='';
			}
}

function chat(id,text,nx,me){
	var cxID='chat_'+id;
	var title = (nx == null) ? id : nx;
	
	if(document.getElementById('chat_'+id) == null){
		popUp(title,cxID,250,300);
		$( "#"+cxID ).dialog({ resizable: false });
		var bodyChx='<div style="height:220px; border:0; overflow:auto">'+
					'<div id="'+cxID+'_body"></div>'+
					'<a href="#" style="outline:none" id="href_'+cxID+'">&nbsp;</a>'+
					'</div>'+
					'<input type="text" style="width:218px;" onkeyup="sxTheChat(event,this,\''+id+'\',\''+nx+'\',\''+me+'\')" id="'+cxID+'_lkwjeoriwereu">';
		$('#'+cxID+'_layout').html(bodyChx);
		
		var inHtx=$('#'+cxID+'_body').html();
		if(text != null && parseInt(text.length) > 0){
			btext = (inHtx != null) ? inHtx : '';
			tx='<span style="font-size:9px;color:#AAA">'+title+'</span>: '+text+'<br>';
			$('#'+cxID+'_body').html(btext+tx);	
		}
		
	} else {
		$('#'+cxID+'').dialog('open');
		var inHtx=$('#'+cxID+'_body').html();
		if(text != null && parseInt(text.length) > 0){
			btext = (inHtx != null) ? inHtx : '';
			tx='<span style="font-size:9px;color:#AAA">'+title+'</span>: '+text+'<br>';
			$('#'+cxID+'_body').html(btext+tx);
			$('#href_'+cxID).focus();
		}
	}
	
	$('#'+cxID+'_lkwjeoriwereu').focus();
	
}

function number(n){if (n.value != ''){hv=''+n.value+'';t=hv.split(' ').join('');var numExp=/^[0-9\.\+\-]+$/;if(t.match(numExp)){n.className='';}else{n.className='redFont';n.focus(); alert('Only number are allowed for this! Change your character except leters or numbers.');return false;}}}
function clearKarakter(s){var str=s.value;var tr=Array("+" ,"/" ,"\'","\"","^","#","|","&");for (i=0;i<tr.length;i++){str=str.replace(tr[i],'');}s.value=str;}
function cekKarakter(n,k){t=n.value.split('');var tanda_terlarang=" + , / ,\',\", ^ , # , | , &";for (i=0;i<t.length;i++){if (t[i]=='+' || t[i]=='^' || t[i]=='#' || t[i]=='/' || t[i]=='\'' || t[i]=='\"' || t[i]=='|' || t[i]=='&'){if (k == null){alert('OptoPro detect that you are using one of these ('+tanda_terlarang+') characters.<br>Please dont\'t use those characters to maintain the stability of this system!');}clearKarakter(n);n.style.color='#DD1122';return false;} else {n.style.color='#454545';}}}
function trim(str){if(!str || typeof str != 'string')return null;return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');}
function cekFormatEmail(str){var emlExp=/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;if(str.match(emlExp)){return true;} else {return false;}}

$(document).ready(function(){  $('form').submit( function(){ loading(); } ) })

function upBox(up_id,this_id,width,height,position,close_option){
	if(document.getElementById(this_id) == null){
		var bodyTopID='mainbody';
		if(arguments[4] != null){
			if(arguments[4][2] != null){
				var bodyTopID=arguments[4][2];
			} 
		}
		var bx=document.getElementById(bodyTopID);
		$('#'+bodyTopID).append('<div id="wero2i34092348" style="position:absolute;top:0px;left:0px; width:100%; height:'+(bx.offsetHeight + 10)+'px;"></div>');
		$('#wero2i34092348').css('z-index','1005');
		closeSlct=function(){winClose(this_id+'_up');winClose('wero2i34092348')};
		var bxt='';
		if(close_option == null){
			$('#wero2i34092348').click(function(){closeSlct()});
		} else if (close_option == 'button'){
			var bxt='<div style="height:20px; padding-top:5px;cursor:move" onmousedown="this.style.cursor=\'move\'" id="'+this_id+'_handler"><a href="#" class="active divActive boxround5" style="border:0px; text-decoration:none; float:right;margin-right:15px" id="poi345oi34u5ou34i" onclick="closeSlct()"><span>close</span></a></div>';
		}
		//document.getElementById('wero2i34092348').style.zIndex=999;
		
		var left=0;
		var top=27;
		if(position != null){
			//alert(arguments[4][0]+' | '+arguments[4][1]);
			if(position == 'center'){
				left= (bx.offsetWidth - parseFloat(width)) / 2;
				top= (bx.offsetHeight - parseFloat(height)) / 2;
			} else {
				top=arguments[4][0];
				left=arguments[4][1];	
			}
		}
		var inHg=';height:'+height+'px';
		if(height == null){inHg='';}
		
		$('#'+up_id).append('<div id="'+this_id+'_up" class="boxShad" style="position:absolute;background:#FFF">'+bxt+'<div id="'+this_id+'" style="'+inHg+'; width:'+width+'px"></div></div>');
		$('#'+this_id+'_up').css({'top':top+'px' , 'left':left+'px', 'z-index':'1007'});
		//document.getElementById(this_id+'_up').style.zIndex=1007;
		if (close_option == 'button'){ document.getElementById('poi345oi34u5ou34i').focus(); $( '#'+this_id+'_up' ).draggable({ handle : '#'+this_id+'_handler'});}
	}
}

function iconActtion(){
	$(document).ready(
		function(){
			$('.icon_action').addClass('icon_base');
			$('.icon_action').css({width:32, height:16});
			var inhtx='<span style="float:left; position:relative; left:3" class="ui-icon ui-icon-triangle-1-n"></span>'+
                      '<span style="float:right; display:inline-block; position:relative; right:3" class="ui-icon ui-icon-pencil"></span>';
			$('.icon_action').html(inhtx);
		}
	)
}

function rklikIE4(){
	if (event.button==2){
		return false;
	}
}

function rklikNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			wTip(textup,textup);
			return false;
		}
	}
}

	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=rklikNS4;
	} else if (document.all&&!document.getElementById){
		document.onmousedown=rklikIE4;
	}
	
	document.oncontextmenu=new Function("return false");
