// JavaScript Document
function promptWarning(title,txt,color){
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle"});
}
function promptLogout(title,txt,color){
	function logoutFunc(v,m,f){
		if (v == true){
			window.location = "logout.php";
		}
	}
	
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle", buttons: { Ok: true, Cancel: false }, focus: 1, callback: logoutFunc });
}
function promptDelete(title,txt,color,id,mnu){
	function deleteFunc(v,m,f){
		if (v == true){
			window.location = "?mnu="+mnu+"&gos=delete&id="+id;
		}
	}
	
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle", buttons: { Ok: true, Cancel: false }, focus: 1, callback: deleteFunc });
}
function promptJoin(title,txt,color,id,mnu){
	function deleteFunc(v,m,f){
		if (v == true){
			window.location = "?mnu="+mnu+"&gos=joinEvent&id="+id;
		}
	}
	
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle", buttons: { Ok: true, Cancel: false }, focus: 1, callback: deleteFunc });
}
function promptUnjoin(title,txt,color,id,mnu){
	function deleteFunc(v,m,f){
		if (v == true){
			window.location = "?mnu="+mnu+"&gos=unjoinEvent&id="+id;
		}
	}
	
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle", buttons: { Ok: true, Cancel: false }, focus: 1, callback: deleteFunc });
}
function promptDeleteD(title,txt,color,id,mnu){
	function deleteFunc(v,m,f){
		if (v == true){
			window.location = "?mnu="+mnu+"&gos=deleteDosen&id="+id;
		}
	}
	
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle", buttons: { Ok: true, Cancel: false }, focus: 1, callback: deleteFunc });
}
function promptApprove(title,txt,color,id,mnu,app){
	function approveFunc(v,m,f){
		if (v == true){
			window.location = "?mnu="+mnu+"&gos=approval&app="+app+"&id="+id;
		}
	}
	
	var img = "<img src=img/Information"+color+".png >";
	var wrap = "<div class=\"imgPrompt floatL\" >"+img+"</div><div class=\"isiPrompt floatL\" ><div class=titlePrompt >"+title+"</div><div>"+txt+"</div></div><div class=clear />";
	$.prompt(wrap,{prefix:"mystyle", buttons: { Ok: true, Cancel: false }, focus: 1, callback: approveFunc });
}

function cekFormGallery(){
	var Cat = document.getElementById('Cat').value;
	if (Cat == ''){
		promptWarning("Update Failed","Pilih salah satu kategori","yellow");
		return false;
	} else {
		return true;	
	}
}

function cekFormLogin(){
	var uid = document.getElementById('userid').value;
	var pass = document.getElementById('passw').value;
	var err = '';
	if (uid == ''){
		err += "You must submit your Username <br>";
	}
	if (pass == ''){
		err += "You must Submit your Password <br>";
	}
	if (err != ''){
		promptWarning("Login Failed",err,"yellow");
		return false;
	} else {
		return true;	
	}
}
function cekFormPass(){
	var pass = document.getElementById('pass').value;
	var pass2 = document.getElementById('pass2').value;
	var pass2a = document.getElementById('pass2a').value;
	var err = '';
	if (pass == ''){
		err += "Password lama harus diisi <br>";
	}
	if (pass2 == ''){
		err += "Password Baru harus diisi <br>";
	}
	if (pass2 != pass2a){
		err += "Ulangi Password Baru dengan benar <br>";
	}
	if (err != ''){
		promptWarning("Change PasswordFailed",err,"yellow");
		
		return false;
	} else {
		return true;	
	}
}

function cekuser(){
	var user = $("#username").val();
	var noChar = /[^a-zA-Z0-9_]/.test(user);
	if (user.length >= 5) {
		if (noChar == false){
			$("#cekhidden").load("cekuser.php?uid="+user);
			$("#cek").load("cekuser.php?uid="+user+"&tipe=img");
		} else {
			user = user.replace(" ","%20");
			$("#cekhidden").load("cekuser.php?uid="+user+"&err=1");
			$("#cek").load("cekuser.php?uid="+user+"&tipe=img&err=1");
		}
	}
}

function cekFormReg(cap){
	var username = document.getElementById('username').value;
	var usernameCek = document.getElementById('cekhidden').value;
	var pass = document.getElementById('password').value;
	var pass2 = document.getElementById('password2').value;
	var nama = document.getElementById('nama').value;
	var email = document.getElementById('email').value;
	var telp = document.getElementById('telepon').value;
	var tgllahir = document.getElementById('tglLahir').value;
	var alamat = document.getElementById('alamat').value;
	var kota = document.getElementById('kota').value;
	var mobil = document.getElementById('tipe').value;
	var captcha = document.getElementById('captcha').value;	
	
	var txt = '';
	if (username == ''){
		txt += "<li>You must submit a user name </li>";
	} else if (username.length <= 4) {
		txt += "<li>User name must contain at least 5 character </li>";
	} else {
		var noChar = /[^a-zA-Z0-9_]/.test(username);
		if (noChar == true){
			txt += "<li>User name can only contain letters, numbers and underscore </li>";
		} else if (usernameCek == 'FAILED') {
			txt += "<li>User name already used by someone else. Choose another user name !</li>";
		}
	}
	if (pass == ''){
		txt += "<li>You must submit a password </li>";
	} else if (pass.length <= 4) {
		txt += "<li>Password must contain at least 5 character </li>";
	} else {
		var noChar = /[^a-zA-Z0-9_]/.test(pass);
		if (noChar == true){
			txt += "<li>Password can only contain letters, numbers and underscore </li>";
		}
	}
	if (pass2 == ''){
		txt += "<li>You must retype your password </li>";
	} else {
		if (pass2 != pass){
			txt += "<li>You must retype your password correctly </li>";
		}
	}
	if (nama == ''){
		txt += "<li>You must submit a name </li>";
	}	
	if (email == ''){
		txt += "<li>You must submit an email </li>";
	}	
	if (telp == ''){
		txt += "<li>You must submit a phone </li>";
	}	
	if (tgllahir == ''){
		txt += "<li>You must submit your birth date </li>";
	}	
	if (alamat == ''){
		txt += "<li>You must submit an address </li>";
	}	
	if (kota == ''){
		txt += "<li>You must submit a city </li>";
	}	
	if (mobil == ''){
		txt += "<li>You must submit an owned car </li>";
	}	
	if (captcha != cap){
		txt += "<li>Wrong Security Code </li>";
	}	
	if (txt != ''){
		txt = "<ul class=errmsg>"+txt+"</ul>";
		promptWarning("Failed",txt,"Yellow");
		return false;
	} else {
		return true;	
	}
}
function cekFormBukuTamu(cap){
	var nama = document.getElementById('nama').value;
    var tlp = document.getElementById('tlp').value;
	var komentar = document.getElementById('komentar').value;
	var captcha = document.getElementById('captcha').value;

	var txt = '';
	
	if (nama == ''){
		txt += "Silakan isi nama <br>";
	}
	if (tlp == ''){
		txt += "Silakan isi no telepon yang bisa dihubungi <br>";
	}	
	if (komentar == ''){
		txt += "Silakan isi alamat <br>";
	}
	if (captcha != cap){
		txt += "Wrong Security Code<br>";
	}	
	if (txt != ''){
		promptWarning("Failed",txt,"yellow");
		return false;
	} else {
		return true;	
	}
}

function startclock(){
	var thetime=new Date();
	
	var nhours=thetime.getHours();
	var nmins=thetime.getMinutes();
	var nsecn=thetime.getSeconds();
	var nday=thetime.getDay();
	var nmonth=thetime.getMonth();
	var ntoday=thetime.getDate();
	var nyear=thetime.getYear();
	var AorP=" ";
	
	if (nhours>=12)
		AorP="P.M.";
	else
		AorP="A.M.";
	
	if (nhours>=13)
		nhours-=12;
	
	if (nhours==0)
	   nhours=12;
	
	if (nsecn<10)
	 nsecn="0"+nsecn;
	
	if (nmins<10)
	 nmins="0"+nmins;
	
	if (nday==0)
	  nday="Sun";
	if (nday==1)
	  nday="Mon";
	if (nday==2)
	  nday="Tue";
	if (nday==3)
	  nday="Wed";
	if (nday==4)
	  nday="Thu";
	if (nday==5)
	  nday="Fri";
	if (nday==6)
	  nday="Sat";
	
	nmonth+=1;
	
	if (nyear<=99)
	  nyear= "19"+nyear;
	
	if ((nyear>99) && (nyear<2000))
	 nyear+=1900;
	
	$('#clocks').html(nday+", "+nmonth+"/"+ntoday+"/"+nyear+" "+nhours+": "+nmins+": "+nsecn+" "+AorP);
	
	setTimeout('startclock()',1000);

} 
