  $(document).ready(function(){
		$(".twtr-tweets").topnews({
			startstop:true,
			limit:10,
			move:'down'
		});
		
		//*********** Slide news ***********//	
		 jQuery('#mycarousel').jcarousel({
			auto: 30,
			wrap: 'circular',
			initCallback: mycarousel_initCallback
		});
		
		///********** menu *************//
		 $(".signin").click(function(e) {          
				e.preventDefault();
                $("fieldset#signin_menu").toggle();
				$(".signin").toggleClass("menu-open");
            });
			
			$("fieldset#signin_menu").mouseup(function() {
				return false
			});
			$(document).mouseup(function(e) {
				if($(e.target).parent("a.signin").length==0) {
					$(".signin").removeClass("menu-open");
					$("fieldset#signin_menu").hide();
				}
			});		
			
			$(".signin2").click(function(e) {          
				e.preventDefault();
                $("fieldset#signin_menu2").toggle();
				$(".signin2").toggleClass("menu-open2");
            });
			
			$("fieldset#signin_menu2").mouseup(function() {
				return false
			});
			$(document).mouseup(function(e) {
				if($(e.target).parent("a.signin2").length==0) {
					$(".signin2").removeClass("menu-open2");
					$("fieldset#signin_menu2").hide();
				}
			});		
			
			Accordions();
			/*$('.accordian li:even').next().slideToggle('normal');		*/
				
			/*oHandler = $(".ddlang").msDropDown().data("dd");
			oHandler.visible(true);*/
			
			$('ul#first-languages li:not(.selected_language)').css('opacity', 0.3);
			/*$('ul#first-languages li:not(.selected_language)').hover(function(){
				$(this).css('opacity', 1);
			}, function(){
				$(this).css('opacity', 0.3);
			});*/
			
	});
	
	function content(){
		if($("#stscontent").val()=='1'){
			$('#edii-home').fadeOut('slow', function(){ $('#edii-product').fadeIn('slow'); });
			$("#stscontent").val('2');
		}
		else if($("#stscontent").val()=='2'){
			$('#edii-product').fadeOut('slow', function(){ $('#edii-adv').fadeIn('slow'); });
			$("#stscontent").val('3');
		}
		else if($("#stscontent").val()=='3'){
			$('#edii-adv').fadeOut('slow', function(){ $('#edii-axway').fadeIn('slow'); });
			$("#stscontent").val('0');
		}
		else{
			$('#edii-axway').fadeOut('slow', function(){ $('#edii-home').fadeIn('slow'); });			
			$("#stscontent").val('1');
		}
	    setTimeout("content()",10000);		
	}
	setTimeout("content()",10000);
	
	
	function Accordions(){
		$('.accordian li:odd:gt(0)').hide();
		$('.accordian li:odd').addClass('dimension');
		$('.accordian li:even:even').addClass('even');
		$('.accordian li:even:odd').addClass('odd');
		$('.accordian li:even').css('cursor', 'pointer');
		$('.accordian li:even').click( function() {
			var cur = $(this).next();
			var old = $('.accordian li:odd:visible');
			if ( cur.is(':visible') )
				return false;
			old.slideToggle(300);
			cur.stop().slideToggle(300);
	
		} );		
	}

	//*********** Slide news ***********//	
	function mycarousel_initCallback(carousel){
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
			  
	function popup(jns,url){
		if(jns=="div"){ 
			jQuery.facebox({ div: '#'+url }, 'my-groovy-style')
		}else if(jns=="image"){ 
			jQuery.facebox({ image: url }, 'my-groovy-style');
		}else{
			jQuery.facebox({ ajax: url }, 'my-groovy-style');
		}
	}  
	
	function set_datetimeclock(id) {
		var sekarang = new Date();
		var tanggal = sekarang.getDate();
		var hari = sekarang.getDay();
		if (hari == 0) hari = 'Sunday'; 
		if (hari == 1) hari = 'Monday';
		if (hari == 2) hari = 'Tuesday';
		if (hari == 3) hari = 'Wednesday';
		if (hari == 4) hari = 'Thursday';
		if (hari == 5) hari = 'Friday';
		if (hari == 6) hari = 'Saturday';
		var bulan = sekarang.getMonth();
		if (bulan == 0) bulan = 'January'; if (bulan == 1) bulan = 'February';
		if (bulan == 2) bulan = 'March'; if (bulan == 3) bulan = 'April';
		if (bulan == 4) bulan = 'May'; if (bulan == 5) bulan = 'Jun';
		if (bulan == 6) bulan = 'July'; if (bulan == 7) bulan = 'August';
		if (bulan == 8) bulan = 'September'; if (bulan == 9) bulan = 'October';
		if (bulan == 10) bulan = 'November'; if (bulan == 11) bulan = 'December';
		var tahun = sekarang.getFullYear();
		var detik = sekarang.getSeconds();
		if (detik < 10) detik = '0' + detik;
		var menit = sekarang.getMinutes();
		if (menit < 10) menit = '0' + menit;
		var jam = sekarang.getHours();
		if (jam < 10) jam = '0' + jam;
		if (tanggal == 1) { xx = 'st'; }
		else if (tanggal == 2) { xx = 'nd'; }
		else if (tanggal == 3) { xx = 'rd'; }
		else { xx = 'th'; }
		
		var showdate = '<b>'+ hari +', ' + bulan + ' ' + tanggal + xx +' ' + tahun + ' &nbsp; :: &nbsp; ' + jam + ':' + menit + ':' + detik +'</b>';
		document.getElementById(id).innerHTML = showdate;
		setTimeout('set_datetimeclock(\''+id+'\')', 1000);
	}

	function showover(id){
		$("#"+id).fadeIn('slow');
	}

	function closeover(id){
	$("#"+id).fadeOut('slow');
	}
	
	function tooltip(id){
	$("#"+id).tooltip;
	}
	
	function Clearjloadings(){
		$("#popup_container").remove();
		$("#popup_overlay").remove();	
	}
	
	function GiveMeAnError(InputID){
		if($(InputID).val().length<1){
			$(InputID).addClass('error');
			return false;
		}		
		else{
			$(InputID).removeClass('error');
			return true;
		}
	}
	
	function ShowErrorBox(DivID,message){
		$(DivID).hide();
		$(DivID).html(message);
		$(DivID).fadeIn('slow');
	}
	
	function ShowvalidBox(DivID,message){
		$(DivID).hide();
		$(DivID).addClass('resultBox');
		$(DivID).html(message);
		$(DivID).fadeIn('slow');
	}
	
	function ClearErrorBox(DivID,message){
		$(DivID).hide();
		$(DivID).removeClass('resultmasage');
		$(DivID).fadeIn('slow');
	}
	
	function ClearvalidBox(DivID,message){
		$(DivID).hide();
		$(DivID).removeClass('resultBox');
		$(DivID).fadeIn('slow');
	}
	
	function ShowLoading(DivID){
		var message="";
		message ="<img src=\"img/icon/indicator.gif\" alt=\"loading\" border=\"0\" />";
		message +=" Please wait ... ";
		ShowErrorBox(DivID,message);
	}
		
	function ExecForm(url,DivID,formId,urlSuccess){
		var result;
		ShowLoading(DivID);
		result=false;
		$.ajax({
			type: 'POST',
			url: url,
			data: $(formId).serialize(),
			dataType: 'html',
			success: function(data) {
				if(typeof(data) != 'undefined'){
					var arrayDataTemp = data.split("|");
					//alert(data);
					if(arrayDataTemp[0]==0){
						ShowErrorBox(DivID,arrayDataTemp[1]);	
					}
					else 
					if(arrayDataTemp[0] ==1){
						if(urlSuccess!=""){
							if (urlSuccess == "refresh"){
								ShowErrorBox(DivID,arrayDataTemp[1]);	
								window.location.reload(true);
							}
							else{
								ShowErrorBox(DivID,arrayDataTemp[1]);	
								window.location = urlSuccess;
							}
						}
						else{
							ShowErrorBox(DivID,arrayDataTemp[1]);
						}
					}
				}
			}
		});			
	}


	function getLogin(){
		var cb = eval('document.frmLogin');	
		var username = cb.username.value;
		var password = cb.password.value;
		var keycode = cb.keycode.value;
		var msg = "";
		
		if(!GiveMeAnError("#username")){
			msg += "&raquo; username <br>";	
		}
		if(!GiveMeAnError("#password")){
			msg += "&raquo; password <br>";	
		}
		if(!GiveMeAnError("#keycode")){
			msg += "&raquo; keycode <br>";	
		}
		if(msg.length>0){
			var message = "<b>Error</b>, Please fill this input : <br>" + msg;	
			ShowErrorBox("#DivLogin",message);
		}
		else{
			ExecForm('mod/indexpos.php?what=login','#DivLogin','#frmLogin','index.php');
		}
		return false;
	}
	
	function logout(){
	   var txt = "Are you sure want to exit this application";
  	   jConfirm(txt, ":: EDII - All about e-business solutions ::", 
			 function(r) {
				if(r==true){
					cekOut();
					return true;
				}else if(r==false){
					return false;
				}
			 }
		);
	} 
	
	function cekOut(){
		jloadings();
		$.post("mod/indexpos.php?what=logout",{what:"logout"} ,function(data)
		{
			if(data!='success'){
				Clearjloadings();
				Alert(data);
			}
			else{
				document.location = 'index.php';
			}
		});
		return false;
		Clearjloadings();
	}
	
	function Confirm(text){
		jConfirm(text, ":: EDII - All about e-business solutions ::", 
				 function(r) {
					if(r==true){
						return true;
					}else if(r==false){
						return false;
					}
				 }
		);
	}
	
	function Prompt(text,value,title){
		jPrompt(text, value, title, 
				function(r) {
				if(r) alert('You entered ' + r);
		});
	}
	
	function Alert(text){
		jAlert(text,"::  EDII - All about e-business solutions ::");
	}
	
	function change_captcha(){
		document.getElementById('captcha').src="library/Captcha/get_captcha.php?rnd=" + Math.random();
 	}
	function change_captcha2(){
		document.getElementById('captcha2').src="library/Captcha/get_code.php?rnd=" + Math.random();
 	}
	
	function postId(act,vid){
		$.post("mod/indexpos.php?what=idnews",function(data){
			if(data=='success'){
				if(vid.length>0){
					document.location = 'index.php?act='+act+'&id='+vid;
				}else{
					document.location = 'index.php?act='+act;
				}
			}else{
				Alert('Error '+data);
			}
		});
		return false;
	}
	
	function postUrl(act,vid,index,idmenu){
		$.post("mod/indexpos.php?what=idnews&index="+index+'&idmenu='+idmenu,function(data){
			if(data=='success'){
				if(vid.length>0){
					document.location = 'index.php?act='+act+'&id='+vid;
				}else{
					document.location = 'index.php?act='+act;
				}
			}else{
				Alert('Error '+data);
			}
		});
		return false;
	}
	
	function SearchBox(){
		jloadings();
		 var a=0;	
		  $('#seachbox #txtsearch').each(function(n,element){
				if ($(element).val()=='') {  
					a = a+1;
					$("#"+element.id).css("border","1px solid red");
				}else{
					$("#"+element.id).css("border","");
				}  
		  });  
		if(a>0){
			Alert('Field must have a value');
			return false;
		}
		else{
			var values = $('#seachbox').serialize();
			$.post("mod/indexpos.php?"+values,{what:"searchbox"} ,function(data)
			{
				var arrdata = data.split('|');
				if(arrdata[0]!='success'){
					Clearjloadings();
					Alert(arrdata[1]);
				}else{
					Clearjloadings();
					$("#mainContentz").load("mod/getViewSearchBox.php?aksi=ajax&data="+arrdata[1]);
				}
			});
			return false;
		}
		return false;
	}
	
	function SearchTracking(){
		var cb = eval('document.tracking');	
		var msg = "";
		if(!GiveMeAnError("#noaju")){msg += "&raquo;";}
		if(!GiveMeAnError("#code")){msg += "&raquo;";}
		if(msg.length>0){
			var message = "<br>"+msg+"&nbsp;Please fill input ";	
			ShowErrorBox("#errorAju",message);
		}
		else{
			var values = $('#tracking').serialize();
			jQuery.facebox(function() {
				$('.content').html('<div class="loading"><img src="img/icon/loading.gif"/></div> ');
       			$.get('mod/getTblTracking.php?'+values, function(data) { $.facebox(data) })
     		})
			return false;
		}
		return false;
	}
	
	function postContact(form,what){
		$("#"+form).validator().submit(function(e){ 
				if (!e.isDefaultPrevented()) {
					jloadings();
					var values = $("#"+form).serialize();
					$.post("mod/indexpos.php?"+values,{what:what} ,function(data)
					{ //alert(data);
						if(data!='success'){
							Clearjloadings();
							Alert(data);
						}else{
							$("#mainContentz").load('tpl/direct.html', {limit: 25}, function(){
								Clearjloadings();
							 });
						}
					});
					return false;
				}
			});
	}
	
	function ChangeLang(val){
		jloadings();
		$.post("mod/indexpos.php?lang="+val,{what:"ChLanguage"} ,function(data)
		{//alert(data);
			if(data!='success'){
				Clearjloadings();
				Alert(data);
			}else{
				Clearjloadings();
				document.location = 'index.php';
			}
		});
		return false;
	}
	
	function intInput(event, keyRE) {
		if ( String.fromCharCode(((navigator.appVersion.indexOf('MSIE') != (-1)) ? event.keyCode : event.charCode)).search(keyRE) != (-1)
			|| ( navigator.appVersion.indexOf('MSIE') == (-1)
				&& ( event.keyCode.toString().search(/^(8|9|13|45|46|35|36|37|39)$/) != (-1) 
					|| event.ctrlKey || event.metaKey ) ) ) {
			return true;
		} else {
			return false;
		}
	}
	
	function formdate(id){
		$("#"+id).datepicker({changeMonth: true, changeYear: true});
	}
	
	function c_div(id, inner){
		div = document.createElement("div");	
		div.innerHTML = '<div id="'+id+'" style="display: none;">'+inner+'</div>';
		document.body.appendChild(div);
	}

	function c_dialog(id, title, inner, width, height, clobtn, modal, resize){
			$('#'+id).remove();
			c_div(id, '<div style="margin:20px 25px 5px 12px;">'+inner+'</div>');
			$("#"+id).dialog({ bgiframe: true, resizable: false, autoOpen: true, modal: modal, title: title, height: height, width: width, resize: resize, 
				clobtn: clobtn,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			});
	}

	function closedialog(id){
		$("#"+id).dialog('close');		
	}
	
	function loads(div, url, title){	
		$("#"+div).html('<center><img src=\"img/icon/loading.gif\" alt=\"loading...\" /></center>');
		$('#'+div).load(url);
	}
	
	function popDialog(url,title,width, height,modal){
		if(modal==null){modal=true}
		c_dialog('popup', ':: '+title+' ::', '<div id="idv_popup"></div>', width, height, "run-in", modal, false);
		loads('popup', url);		
	}
	
	function loadEditor(id,toolbar){
		var varid = id.split("|");
		for(var c=0;c<varid.length;c++){
			var instance = CKEDITOR.instances[varid[c]];
			if(instance){
				CKEDITOR.remove(instance);
			}
			if(toolbar==1){
				CKEDITOR.replace( varid[c],{toolbar : 'Basic'});	
			}else{
				CKEDITOR.replace(varid[c]);	
			}
		}
	}
	
	function resetEditor(id){
		CKEDITOR.instances[id].setData();
		return false;
	}
	
	function isValidEmail(email, required) {
		if (required==undefined) {   
			required=true;
		}
		if (email==null) {
			if (required) {
				return false;
			}
			return true;
		}
		if (email.length==0) {  
			if (required) {
				return false;
			}
			return true;
		}
		if (! allValidChars(email)) {  
			return false;
		}
		if (email.indexOf("@") < 1) { 
			return false;
		} else if (email.lastIndexOf(".") <= email.indexOf("@")) {  
			return false;
		} else if (email.indexOf("@") == email.length) {  
			return false;
		} else if (email.indexOf("..") >=0) { 
		return false;
		} else if (email.indexOf(".") == email.length) {  
		return false;
		}
		return true;
	}

	function allValidChars(email) {
	  var parsed = true;
	  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	  for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
		  continue;
		parsed = false;
		break;
	  }
	  return parsed;
	}
	
	
	
