// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isValid()
{
	var isChecked = 0;
	var total = document.getElementById("totPolling").value;
	for(i = 0;i<total;i++)
	{
		if(document.frmPolling.txtPolling[i].checked)
		{
			isChecked = 1;
		}
	}
	if(isChecked < 1 )
	{
		alert("Pilih salah satu kategori !");
		return false;
	}
	document.frmPolling.submit();
}
function error(selector, errorCode) {
	$(".errorcode").remove();
	$(selector).css({"background-color" : "yellow"});
	$(selector).change(function(){
		$(selector).css({"background-color" : "white"});
		$(".errorcode").remove();
	});
	$(selector).keydown(function(){
		$(selector).css({"background-color" : "white"});
		$(".errorcode").remove();
	});
	$(selector).after("<span style='color: red' class='errorcode'>&nbsp;&nbsp;"+getErrorCode(errorCode)+"</span>");
	$(selector).focus();
}
function getErrorCode(errorCode) {
	switch(errorCode) {
		case 1 :
			return "This field should not empty";	
			break;
		case 2 :
			return "Email is not valid";	
			break;
		case 3 :
			return "Repeat Password did not match";	
			break;
	}
}
function new_window_disc_reply_nonmember(DiscussionID,DiscussionTypeID)
{
	var strURL="discussionreplynonmember.asp?DiscussionID=" + DiscussionID + "&DiscussionTypeID=" + DiscussionTypeID ;
	win = window.open (strURL ,'discussionreplynonmember','scrollbars=yes,resizable=no,width=480,height=200');
	win.focus();
	win.moveTo(0,0);
}
function new_window_disc_forum_nonmember(DiscussionTypeID)
{
	var strURL="disc-addforumnonmember.asp?DiscussionTypeID=" + DiscussionTypeID ;
	win = window.open (strURL ,'discussionaddforumnonmember','scrollbars=yes,resizable=no,width=480,height=200');
	win.focus();
	win.moveTo(0,0);
}
function new_window_disc_forum(DiscussionTypeID,strZona)
{
	var strURL="disc-addforum.asp?DiscussionTypeID=" + DiscussionTypeID + "&zona=" + strZona;
	win = window.open (strURL ,'discussionaddforum','scrollbars=yes,resizable=no,width=510,height=280');
	win.focus();
	win.moveTo(0,0);
}
function input_verify_discuss2(btn)
{
	btn.disabled=true;

	if (document.frmDiscuss.txtPesan.value == '')
	{
		alert ("Silahkan masukkan pesan anda terlebih dahulu");
		document.frmDiscuss.txtPesan.focus();
		btn.disabled=false;
		return false;
	}
	if(document.frmDiscuss.txtPesan.value != '' && !checktags(document.frmDiscuss.txtPesan.value))
	{
		alert('Pesan tidak boleh ada Script/HTML tags!\nSilahkan masukkan yang benar.');
		document.frmDiscuss.txtPesan.focus();
		btn.disabled=false;
		return false;
	}
    document.frmDiscuss.submit();
	return true;
}
function input_verify_discuss(btn)
{
	btn.disabled=true;
	if (document.frmDiscuss.txtJudul.value == '')
	{
		alert ("Silahkan masukkan Judul pesan anda terlebih dahulu");
		document.frmDiscuss.txtJudul.focus();
		btn.disabled=false;
		return false;
	}
	if (document.frmDiscuss.txtPesan.value == '')
	{
		alert ("Silahkan masukkan pesan anda terlebih dahulu");
		document.frmDiscuss.txtPesan.focus();
		btn.disabled=false;
		return false;
	}
	
	document.frmDiscuss.submit();
	return true;
}
function checkphone(strphone,maxrep)
{
    var i = 0;
    var j = 0;
    var repdigit = new Array(14);
    var digit= new Array(14);
    var repcnt=0;

    if (strphone.indexOf("12345")!=-1 || strphone.indexOf("00000")!=-1 || strphone.indexOf("11111")!=-1 || strphone.indexOf("22222")!=-1 || strphone.indexOf("33333")!=-1 || strphone.indexOf("44444")!=-1 || strphone.indexOf("55555")!=-1 || strphone.indexOf("66666")!=-1 || strphone.indexOf("77777")!=-1 || strphone.indexOf("88888")!=-1 || strphone.indexOf("99999")!=-1)
		return false;
    else {
	
    for (i = 0; i < strphone.length; i++) {
        repdigit[i] = 0;
	digit[i] = 0;
    }
    for (i = 0; i < strphone.length; i++) {
	digit[i]=strphone.substring(i,i+1);
    	for (j = 0; j <= i; j++) {
	    if (digit[j]==digit[i]) {
		repdigit[j]=repdigit[j]+1;
	    }
        }
    }
    for (i = 0; i < strphone.length; i++) {
	if (repdigit[i]>=maxrep) {
		repcnt=repcnt+1;
	}
    }
    if (repcnt>0)
		return false;
	else
		return true;   
    }
}
function checkdate(intDay,intMonth,intYear) {
	var dtDate = new Date(intMonth + '/' + intDay + '/' + intYear )
    if (dtDate.getDate() != intDay && dtDate.getMonth() != intMonth-1) 
    	return false;
    else
    	return true;
}
function new_window_disc_reply(DiscussionID,DiscussionTypeID)
{
	var strURL="discussionreply.asp?DiscussionID=" + DiscussionID + "&DiscussionTypeID=" + DiscussionTypeID ;
	win = window.open (strURL ,'discussionreply','scrollbars=yes,resizable=no,width=750,height=400');
	win.focus();
	win.moveTo(0,0);
}
function checktags(chkstr) {
		if (chkstr.indexOf("i>")==-1 && chkstr.indexOf("b>")==-1 && chkstr.indexOf("p>")==-1 && chkstr.indexOf("h1>")==-1 && chkstr.indexOf("h2>")==-1 && chkstr.indexOf("h3>")==-1 && chkstr.indexOf("h4>")==-1 && chkstr.indexOf("h5>")==-1 && chkstr.indexOf("h6>")==-1 && chkstr.indexOf("body>")==-1 && chkstr.indexOf("html>")==-1 && chkstr.indexOf("br>")==-1 && chkstr.indexOf("hr>")==-1 && chkstr.indexOf("font>")==-1 && chkstr.indexOf("'")==-1 && chkstr.indexOf("script>")==-1 && chkstr.indexOf("-->>")==-1 && chkstr.indexOf("<!--")==-1 && chkstr.indexOf("form>")==-1 && chkstr.indexOf("div>")==-1 && chkstr.indexOf("u>")==-1 && chkstr.indexOf("ol>")==-1 && chkstr.indexOf("ul>")==-1 && chkstr.indexOf("select>")==-1 && chkstr.indexOf("<input")==-1 && chkstr.indexOf("location.href")==-1 && chkstr.indexOf("response.redirect")==-1 && chkstr.indexOf("<%")==-1 && chkstr.indexOf("%>")==-1)
			return true;
		else
			return false;

}
function submitReporter()
{
	var doc = document.frmAddNews;
	if(doc.txtName.value == ""){
		alert("Nama tidak boleh kosong !");
		doc.txtName.focus();
		return false;
	}
	if(doc.txtTitle.value == ""){
		alert("Title tidak boleh kosong !");
		doc.txtTitle.focus();
		return false;
	}
	if(doc.txtBrief.value == ""){
		alert("Brief tidak boleh kosong !");
		doc.txtBrief.focus();
		return false;
	}
	if(doc.txtContent.value == ""){
		alert("Content tidak boleh kosong !");
		doc.txtContent.focus();
		return false;
	}
	if(doc.txtCity.value == ""){
		alert("Pilih salah satu event city !");
		doc.txtCity.focus();
		return false;
	}
	doc.submit();
}
function new_window_cons_forum(DiscussionTypeID,strZona)
{
	var strURL="consultation-addforum.asp?DiscussionTypeID=" + DiscussionTypeID + "&zona=" + strZona;
	win = window.open (strURL ,'consuladdforum','scrollbars=yes,resizable=no,width=510,height=280');
	win.focus();
	win.moveTo(0,0);
}
