// JavaScript Document

/************************************************ 
Name of File : style.css 
Usage : style for whole interfaces (tables and texts)
Author : Ria Andriana (andriana_ria@yahoo.com)
*************************************************/

/***************************************
Some assigned variables
****************************************/
var date_arr = new Array;

var days_arr = new Array;


date_arr[0]=new Option("Januari",31);

date_arr[1]=new Option("Februari",28);

date_arr[2]=new Option("Maret",31);

date_arr[3]=new Option("April",30);

date_arr[4]=new Option("Mei",31);

date_arr[5]=new Option("Juni",30);

date_arr[6]=new Option("Juli",31);

date_arr[7]=new Option("Agustus",30);

date_arr[8]=new Option("September",30);

date_arr[9]=new Option("Oktober",31);

date_arr[10]=new Option("November",30);

date_arr[11]=new Option("Desember",31);


/***************************************
Function for month list
****************************************/
function fill_select(f,a,b,use)
{
		
        document.writeln("<SELECT name=\"months\"               onchange=\"update_days(searchform,"+b+",'2')\">");
		document.writeln("<OPTION value=\"__\">None</OPTION>");
        for(x=0;x<12;x++)
		{
			stat = "";			
			if (x==a-1)
				stat = "selected" ;
			else
				stat = "";
			

                document.writeln("<OPTION "+stat+" value=\""+date_arr[x].value+","+x+"\">"+date_arr[x].text);
		}
        document.writeln("</SELECT><SELECT name=\"days\">");
		document.writeln("<OPTION value=\"__\">None</OPTION>");
		 for(x=1;x < 32;x++) 
        {
			if (x==b)
				document.writeln("<OPTION selected>"+x+"</OPTION>");
			else
				document.writeln("<OPTION >"+x+"</OPTION>");
        } 
		document.writeln("</SELECT>");
		selection=f.months[f.months.selectedIndex].value;		
		

}


/***************************************
Function of updating days according to
month which user chosen
****************************************/
function update_days(f,a,hit)

{
        
		var val_sel = f.months[f.months.selectedIndex].value
		if (val_sel == "__")
		{
			//alert (val_sel);
			for(x=days_arr.length;x>1;x--)
	        {
                days_arr[x]=null;
                f.days.options[x]=null;
	        }
		   for(x=1;x < 32;x++) 
   		   {
                days_arr[x-1]=new Option(x);            
                f.days.options[x]=days_arr[x-1];
				if (x==a-1)
					 f.days.options[x].selected=true;
  			} 
		}
		else
		{
		
		if (hit==1)
			temp = a-1;
		else
			temp=f.days.selectedIndex; 
		for(x=days_arr.length;x>1;x--)

        {

                days_arr[x]=null;

                f.days.options[x]=null;

         }
		 
		var val_month = (f.months[f.months.selectedIndex].value).split(",");
        selection=parseInt(val_month[0]);

        ret_val = 0;
        if(val_month[0] == 28)

        {

                year=parseInt(f.years.options[f.years.selectedIndex].value);

                if (year % 4 != 0 || year % 100 == 0 ) ret_val=0;

                else

                        if (year % 400 == 0)  ret_val=1;

                        else

                                ret_val=1;

        }

        selection = selection + ret_val;        

        for(x=1;x < selection+1;x++) 
        {

                days_arr[x-1]=new Option(x);            

                f.days.options[x]=days_arr[x-1];

        } }

        if (temp == -1) f.days.options[0].selected=true;

        else
		{
            if (temp > selection)
				 f.days.options[selection-1].selected=true;
			 else
			 f.days.options[temp].selected=true;
}       }


/***************************************
Function to assign year
****************************************/
function year_install(f,a,b,year)

{

        document.writeln("<SELECT name=\"years\" onchange=\"update_days(searchform,"+b+",'2')\">")
		document.writeln("<OPTION selected value=\"____\">None</OPTION>");
        for(x=2006;x<year;x++) 
		{
			stat = "";			
			if (x==a)
				stat = "selected" ;
			else
				stat = "";
			document.writeln("<OPTION "+stat+" value=\""+x+"\">"+x);
		}

        document.writeln("</SELECT>");

}

/***************************************
Function to swap image on rollover 
If mouse over, image is swapped with another image
****************************************/
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_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_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 to convert to <br> or another line
automatically in news administration page
****************************************/
function convert(text){
	text=text.split(" ");msgToDisp="";
    for(i=0;i<text.length;i++){
    // if(text[i].indexOf("http:\/\/")==0||text[i].indexOf("www.")==0){text[i]="<a href=\""+text[i]+"\">"+text[i]+"</a>";}
    
	 text[i]=text[i].replace(/\n/g,"<br>");	 
     if(i!=text.length-1){text[i]+=" ";}
     msgToDisp+=text[i];
    }
	msgToDisp= msgToDisp.replace(/\bhttp\:\/\/www(\.[\w+\.\:\/\_]+)/gi, "http\:\/\/¬¤¸$1");
    msgToDisp= msgToDisp.replace(/\b(http\:\/\/\w+\.[\w+\.\:\/\_]+)/gi,"<a class=tnk href=\"$1\">$1<\/a  >");
	//msgToDisp= msgToDisp.replace(/(http\:\/[^\B\b]+)/gi,"<a class=tnk href=\"$1\">$1<\/a  >");
    msgToDisp= msgToDisp.replace(/\b(www\.[\w+\.\:\/\_]+)/gi, "<a class=tnk href=\"http://$1\">$1</a  >");		
    msgToDisp= msgToDisp.replace(/\bhttp\:\/\/¬¤¸(\.[\w+\.\:\/\_]+)/gi,"<a class=tnk href=\"http\:\/\/www$1\">http\:\/\/www$1</a  >");		
   	msgToDisp= msgToDisp.replace(/\b(\w+@[\w+\.?]*)/gi, "<a class=tnk href=\"mailto\:$1\">$1</a  >");
	
	//alert(msgToDisp);
    document.news.berita.value = msgToDisp;	
 }
 
/***************************************
The back function of convert function
****************************************/
 function to_text(text){
	text=text.split(" ");msgToDisp="";
    for(i=0;i<text.length;i++){   
	 text[i]=text[i].replace("<br>","");	 
     if(i!=text.length-1){text[i]+=" ";}
     msgToDisp+=text[i];
    }	
	//alert(msgToDisp);
    document.news.berita.value = msgToDisp;	
 }

/***************************************
Function on news administration before
submitting the news form
****************************************/
function submitForm()
{	
	convert(document.news.berita.getAttribute('InnerText'));     		
	document.news.submit();
}

/***************************************
Function for Pop Up Window, with variable
URL and height that will be popped up
****************************************/
function popUp(URL, height) 
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height="+height+",left = 0,top = 0');");
}

//End of File
