// use by kenneth chung
// dim on 20080331 as user comment
/*function showMonthSelect() {
	var i=0;
	var obj = document.getElementsByName('SelectYear')[0];
	var MonthObj = document.getElementsByName('SelectMonth');
	var yearSelectedValue = obj.options.value;
	
	for (i=0; i< MonthObj.length; i++) {
		MonthObj[i].style.visibility = 'hidden';
		MonthObj[i].disabled = true;
	}
	
	
	document.getElementById(yearSelectedValue).style.visibility = 'visible';
	document.getElementById(yearSelectedValue).disabled = false;
}*/

// open window functions
// updated on 31 July 08 adding show meunbar option
var newWin;

function newWindow(url, winType) {
        win_name = "intranet_popup";
        win_size = "resizable,scrollbars,status,top=40,left=40,width=400,height=400";
        if(winType==0){
                win_name = "intranet_popup0";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=400,height=400";
        }
        if(winType==1){
                win_name = "intranet_popup1";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=610,height=400";
        }
        if(winType==2){
                win_name = "intranet_popup2";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=500,height=400";
        }
        if(winType==3){
                win_name = "intranet_popup3";
                win_size = "toolbar,location,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==4){
                win_name = "intranet_popup4";
                win_size = "menubar,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==5){
                win_name = "intranet_popup5";
                win_size = "menubar,toolbar,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==6){
                win_name = "intranet_popup6";
                win_size = "menubar,resizable,scrollbars,status,top=40,left=40,width=500,height=350";
        }
        if(winType==7){
                win_name = "intranet_popup7";
                win_size = "toolbar,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==8){
                win_name = "intranet_popup8";
                win_size = "menubar,toolbar,resizable,scrollbars,status,top=40,left=40,width=800,height=500";
        }
        if(winType==9){
                win_name = "intranet_popup9";
                win_size = "resizable,scrollbars,status,top=40,left=500,width=500,height=400";
        }
        if(winType==10){
                win_name = "intranet_popup10";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=800,height=600";
        }
        if(winType==11){
                win_name = "intranet_popup11";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=500,height=500";
        }

/* JR20 */
		if(winType==12){
                win_name = "intranet_popup12";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=680,height=600";
        }
		if(winType==13){
                win_name = "intranet_popup13";
                win_size = "toolbar,resizable,scrollbars,status,top=10,left=10,width=790,height=630";
        }
		// JR20 : emotion
		if(winType==14){
			win_name = "intranet_popup14";
			win_size = "resizable,scrollbars=no,status,top=40,left=40,width=590,height=300";
		}
		if(winType==15){
			win_name = "intranet_popup15";
			win_size = "resizable,scrollbars=no,status,top=40,left=40,width=590,height=500";
		}
		// self-test, exercise, exam
		if(winType==16){
			win_name = "intranet_popup16";
			win_size = "resizable,scrollbars,status,top=40,left=40,width=800,height=600";
        }
		if(winType==17){
		//for invisible update if cannot find free frameset to use
			var intWidth = screen.width;
			var intHeight = screen.height;
			win_name = "intranet_popup17";
			win_size = "top="+(intWidth+30)+",left="+intHeight+",width=1,height=1";
		}
		if(winType==18){
		//backend status window
			win_name = "intranet_popup18";
			win_size = "scrollbars=no,top=140,left=140,width=400,height=300";
		}
		if(winType==19){
		//special room
			win_name = "intranet_popup19";
			win_size = "toolbar,resizable,scrollbars=1,status,top=0,left=0,width=800,height=600";
		}
		if(winType==20){
		// popup announcement
                win_name = "intranet_popup20";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=640,height=500";
       	}
		// char room
        if(winType==21){
                win_name = "intranet_popup21";
                win_size = "toolbar,location,resizable,scrollbars,status,top=40,left=40,width=680,height=400";
        }

		if(winType==22){
		//backend status window
			win_name = "intranet_popup22";
			win_size = "scrollbars=no,top=140,left=140,width=450,height=300";
		}
		if(winType==23)
		{
			//for powervoice recorder
			win_name = "intranet_popup23";
			win_size = "resizable,scrollbars,top=0,left=0,width=625,height=280";
		}
        if(winType==24)
        {	        
			//For powervoice use	        
			win_name = "intranet_popup24";
			win_size = "menubar=no,resizable,scrollbars,status,top=40,left=40,width=580,height=310";
        }
        if(winType==25)
        {	        
			//For powervoice use	        
			win_name = "intranet_popup25";
			win_size = "menubar=no,resizable,scrollbars=no,status,top=40,left=40,width=380,height=200";
        }		
        if(winType==26)
        {	        
			
			win_name = "intranet_popup26";
			win_size = "menubar=no,resizable,scrollbars=no,status,top=40,left=40,width=810,height=600";
        }
        if(winType==27)
        {	
        	win_name = "intranet_popup27";
			win_size = "resizable,scrollbars,status,top=40,left=40,width="+screen.width+",height="+screen.height;
        }
		
       	// TMP for PowerConcept
		if(winType==90){
		    win_name = "intranet_popup90";
		    win_size = "resizable,scrollbars=no,status,top=40,left=40,width=780,height=550";
		}
		if(winType==91){
		    win_name = "intranet_popup91";
		    win_size = "resizable,scrollbars=1,top=40,left=40,width=290,height=550";
		}
		if(winType==99){
                win_name = "intranet_popup99";
                win_size = "resizable,scrollbars,status,top=40,left=40,width=850,height=600";
        }
		if (newWindow.arguments.length>3) {
			win_name = "GivenSizeWin";
			var is_scroll = 0;
			var is_resizable = 0 ;
			var menubar = 0 ;
			if (newWindow.arguments.length>4) {
				is_scroll = newWindow.arguments[4];
			}
			if (newWindow.arguments.length>5)
			{
			    is_resizable = (newWindow.arguments[5]==1) ? "1" : "0";
			}
			if (newWindow.arguments.length>6)
			{
			    win_name = (newWindow.arguments[6]);
			}
			if (newWindow.arguments.length>7)
			{
			    menubar = (newWindow.arguments[7]==1) ? "menubar" : "";
			}	
			
			if (menubar!=""){
				win_size = menubar+",";
			}
			else{
				win_size = "";
			}	

			win_size += "resizable="+is_resizable+",scrollbars="+is_scroll+",status=0,top=40,left=40,width="+newWindow.arguments[2]+",height="+newWindow.arguments[3];
			
		}

        if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion >="4")
        if (newWin!=null) newWin.close();
        newWin = window.open (url, win_name, win_size);
        if (navigator.appName=="Netscape" && navigator.appVersion >= "3") newWin.focus();
}

function newWindowNotClose(url, winType,name) {
        var newWindow;
        win_name = name;
        win_size = "resizable,scrollbars,status,top=40,left=40,width=400,height=400";
        if(winType==0){
                win_size = "resizable,scrollbars,status,top=40,left=40,width=400,height=400";
        }
        if(winType==1){
                win_size = "resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==2){
                win_size = "resizable,scrollbars,status,top=40,left=40,width=500,height=400";
        }
        if(winType==3){
                win_size = "toolbar,location,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==4){
                win_size = "menubar,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==5){
                win_size = "menubar,toolbar,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==6){
                win_size = "menubar,resizable,scrollbars,status,top=40,left=40,width=500,height=350";
        }
        if(winType==7){
                win_size = "toolbar,resizable,scrollbars,status,top=40,left=40,width=600,height=400";
        }
        if(winType==8){
                win_size = "menubar,toolbar,resizable,scrollbars,status,top=40,left=40,width=800,height=500";
        }
        if(winType==9){
                win_size = "resizable,scrollbars,status,top=40,left=500,width=500,height=400";
        }
        if(winType==10){
                win_size = "resizable,scrollbars,status,top=40,left=40,width=800,height=600";
        }
//        if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion >="4")
        newWindow = window.open (url, win_name, win_size);
        if (navigator.appName=="Netscape" && navigator.appVersion >= "3") newWindow.focus();
}

// trim functions
function LTrim(str){
        var whitespace = new String(" \t\n\r");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1) {
                var j=0, i = s.length;
                while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;
                s = s.substring(j, i);
        }
        return s;
}
function RTrim(str){
        var whitespace = new String(" \t\n\r");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                var i = s.length - 1;       // Get length of string
                while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;
                s = s.substring(0, i+1);
        }
        return s;
}
function Trim(str){
        return RTrim(LTrim(str));
}

// form validation functions
function setChecked(val, obj, element_name){
        len=obj.elements.length;
        var i=0;
        for( i=0 ; i<len ; i++) {
                if (obj.elements[i].name==element_name)
                obj.elements[i].checked=val;
        }
}
function countChecked(obj, element_name){
        len=obj.elements.length;
        var i=0;
        var j=0;
        for( i=0 ; i<len ; i++) {
                if (obj.elements[i].name==element_name && obj.elements[i].checked)
                j=j+1;
        }
        return j;
}
function returnChecked(obj, element_name){
        len=obj.elements.length;
        var i=0;
        for( i=0 ; i<len ; i++) {
                if (obj.elements[i].name==element_name && obj.elements[i].checked)
                return obj.elements[i].value;
        }
        return null;
}
function check_text(f, msg){
        if(Trim(f.value)==""){
                alert(msg);
                f.value="";
                f.focus();
                return false;
        }else{
                return true;
        }
}
function check_select(f, msg, g){
        if(Trim(f.options[f.selectedIndex].value)==g){
                alert(msg);
                f.focus();
                return false;
        }else{
                return true;
        }
}
function check_checkbox(obj,element){
        if(countChecked(obj,element)==0){
                return false;
        } else {
                return true;
        }
}
function check_int(f,d,msg){
        if(isNaN(parseInt(f.value)) || parseInt(f.value)==0){
                alert(msg);
                f.value=d;
                f.focus();
                return false;
        }else{
                f.value=parseInt(f.value);
                return true;
        }
}
function check_positive_int (f,msg)
{
     value = parseInt(f.value);
     if (isNaN(value) || value < 0)
     {
         alert(msg);
         f.focus();
         return false;
     }
     else
     {
         f.value = value;
         return true;
     }
}
function check_positive_nonzero_int (f,msg)
{
     value = parseInt(f.value);
     if (isNaN(value) || value <= 0)
     {
         alert(msg);
         f.focus();
         return false;
     }
     else
     {
         f.value = value;
         return true;
     }
}
function check_date(obj, msg){
        var err = 0;
        d_a = obj.value;
        if (d_a.length != 10) err = 1;
        d_b = parseInt(d_a.substring(0, 4),10)        // year
        d_c = d_a.substring(4, 5)                                // '-'
        d_d = parseInt(d_a.substring(5, 7),10)        // month
        d_e = d_a.substring(7, 8)                                // '-'
        d_f = parseInt(d_a.substring(8, 10),10)        // day
        // basic error checking
        if(d_b<0 || d_b>3000 || isNaN(d_b)) err = 1;
        if(d_c != '-') err = 1;
        if(d_d<1 || d_d>12 || isNaN(d_d)) err = 1;
        if(d_e != '-') err = 1;
        if(d_f<1 || d_f>31 || isNaN(d_f)) err = 1;
        // advanced error checking
        // months with 30 days
        if((d_d==4 || d_d==6 || d_d==9 || d_d==11) && (d_f==31)) err = 1;
        // february, leap year
        if(d_d==2){ // feb
                var d_g = parseInt(d_b/4)
                if(isNaN(d_g)) err = 1;
                if(d_f>29) err = 1;
                if(d_f==29 && ((d_b/4)!=parseInt(d_b/4))) err = 1;
        }
        if(err==1){
                alert(msg);
                obj.focus();
                return false;
        }else{
                return true;
        }
}

function check_date_without_return_msg(obj){
        var err = 0;
        d_a = obj.value;
        if (d_a.length != 10) err = 1;
        // commented by kenneth chung 2010-04-09, to prevent chinese character pass through to checking
        /*d_b = parseInt(d_a.substring(0, 4),10)        // year
        d_c = d_a.substring(4, 5)                                // '-'
        d_d = parseInt(d_a.substring(5, 7),10)        // month
        d_e = d_a.substring(7, 8)                                // '-'
        d_f = parseInt(d_a.substring(8, 10),10)        // day*/
        d_b = d_a.substring(0, 4);        // year
        d_c = d_a.substring(4, 5);                                // '-'
        d_d = d_a.substring(5, 7);        // month
        d_e = d_a.substring(7, 8);                                // '-'
        d_f = d_a.substring(8, 10);        // day
        //alert(d_f);
        // basic error checking
        if(d_b<0 || d_b>3000 || isNaN(d_b)) err = 1;
        if(d_c != '-') err = 1;
        if(d_d<1 || d_d>12 || isNaN(d_d)) err = 1;
        if(d_e != '-') err = 1;
        if(d_f<1 || d_f>31 || isNaN(d_f)) err = 1;
        // advanced error checking
        // months with 30 days
        if((d_d==4 || d_d==6 || d_d==9 || d_d==11) && (d_f==31)) err = 1;
        // february, leap year
        if(d_d==2){ // feb
                var d_g = parseInt(d_b/4)
                if(isNaN(d_g)) err = 1;
                if(d_f>29) err = 1;
                if(d_f==29 && ((d_b/4)!=parseInt(d_b/4))) err = 1;
        }
        if(err==1){
                return false;
        }else{
                return true;
        }
}

function check_time(obj,msg)
{
        var err = 0;
        d_a = obj.value;
        if (d_a.length != 8) err = 1;
        d_b = parseInt(d_a.substring(0, 2),10)        // hr
        d_c = d_a.substring(2, 3)                                // ':'
        d_d = parseInt(d_a.substring(3, 5),10)        // min
        d_e = d_a.substring(5, 6)                                // ':'
        d_f = parseInt(d_a.substring(6, 8),10)        // sec
        // basic error checking
        if(d_b<0 || d_b>23 || isNaN(d_b)) err = 1;
        if(d_c != ':') err = 1;
        if(d_d<0 || d_d>59 || isNaN(d_d)) err = 1;
        if(d_e != ':') err = 1;
        if(d_f<0 || d_f>59 || isNaN(d_f)) err = 1;
        if(err==1){
                alert(msg);
                obj.focus();
                return false;
        }else{
                return true;
        }
}
function compareDate(s1,s2)
{
        y1 = parseInt(s1.substring(0,4),10);
        y2 = parseInt(s2.substring(0,4),10);
        m1 = parseInt(s1.substring(5,7),10);
        m2 = parseInt(s2.substring(5,7),10);
        d1 = parseInt(s1.substring(8,10),10);
        d2 = parseInt(s2.substring(8,10),10);

        if (y1 > y2)
        {
                return 1;
        }
        else if (y1 < y2)
        {
                return -1;
        }
        else if (m1 > m2)
        {
                return 1;
        }
        else if (m1 < m2)
        {
                return -1;
        }
        else if (d1 > d2)
        {
                return 1;
        }
        else if (d1 < d2)
        {
                return -1;
        }
        return 0;


}

function checkRegEx(str,msg){
        var RE1 = new RegExp("[^0-9a-zA-Z]");
        if (RE1.test(str)){
                alert(msg);
                return false;
        }else{
                return true;
        }
}
function validateEmail(obj,msg){
        //var re = /^[\w_.-]+@[\w-]+(\.\w+)+$/;
        //var re = /^.+@.+\..{2,3}$/;
        //var re = /^[\w_\.\-]+@[\w_\-]+\.[\w]{2,3}$/;
        var re = /^([\w_\.\-])+\@(([\w_\.\-])+\.)+([\w]{2,4})+$/;	
        if (re.test(obj.value)) {
                return true;
        }else{
                alert(msg);
                obj.focus();
                return false;
        }
}
function validateFilename(str){
        var re = /[:<>\\\/\|\*\?'"]/;
        if (re.test(str)) {
                alert(globalAlertMsg25);
                return false;
        }else{
                return true;
        }
}

// page functions
function gopage(page, obj){
        obj.pageNo.value=page;
        obj.submit();
}
function sortPage(a, b, obj){
        obj.order.value=a;
        obj.field.value=b;
        obj.pageNo.value=1;       
        obj.submit();        
}

// menu bar functions
function checkNew(page){
        self.location.href=page;
}
function checkPost(obj,url){
        obj.action=url;
        obj.method = "post";
        obj.submit();
}
function checkGet(obj,url){
        obj.action=url;
        obj.method = "get";
        obj.submit();
}
function AlertPost (obj,url,msg){
        if(confirm(msg)){
           obj.action=url;
           obj.method = "post";
           obj.submit();
        }
}
function checkRemoveAll(obj,url){
        if(confirm(globalAlertMsgRemoveAll)){
           obj.action=url;
           obj.method = "get";
           obj.submit();
        }
}

function checkEdit(obj,element,page){
        if(countChecked(obj,element)==1) {
                obj.action=page;
                obj.submit();
        } else {
                alert(globalAlertMsg1);
        }
}
function checkRemove(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertMsg3)){
                obj.action=page;
                obj.method="POST";
                obj.submit();
                }
        }
}
function checkReject(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertMsgReject)){
                obj.action=page;
                obj.method="POST";
                obj.submit();
                }
        }
}
function checkRejectNoDel(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertMsgRejectNoDel)){
                obj.action=page;
                obj.method="POST";
                obj.submit();
                }
        }
}

function checkRestore(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                obj.action=page;
                obj.submit();
        }
}
function checkApprove(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertMsg4)){
                obj.action=page;
                obj.submit();
                }
        }
}
function checkActivate(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertActivate)){
                obj.action=page;
                obj.submit();
                }
        }
}

function checkSuspend(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertMsg5)){
                obj.action=page;
                obj.submit();
                }
        }
}
function checkSwap(obj,element,page){
        if(countChecked(obj,element)!=2)
                alert(globalAlertMsg6);
        else{
                if(confirm(globalAlertMsg7)){
                obj.action=page;
                obj.submit();
                }
        }
}
function checkImport(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                obj.action=page;
                obj.submit();
        }
}
function checkIdentity(obj,element){
        if(countChecked(obj,element)==0){
                alert(globalAlertMsg14);
                return false;
        }else{
                return true;
        }
}
function checkRole(obj,element,page){
        if(countChecked(obj,element)==0){
                alert(globalAlertMsg2);
        }else{
                obj.action=page;
                obj.submit();
        }
}
function checkArchive(obj,element,page){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(globalAlertMsg21)){
                obj.action=page;
                obj.submit();
                }
        }
}

function checkAlert(obj,element,page,msg){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                if(confirm(msg)){
                obj.action=page;
                obj.method="POST";
                obj.submit();
                }
        }
}
function checkPrompt(obj,element,page,msg,data,defaultmsg){
        if(countChecked(obj,element)==0)
                alert(globalAlertMsg2);
        else{
                var inputdata = prompt(msg,defaultmsg);
                if (inputdata==null) return;
                else {
                data.value = inputdata;
                obj.action=page;
                obj.method="POST";
                obj.submit();
                }
        }
}

function countOption(obj){
        checkOption(obj);
        var j = 0;
        for(i=0; i<obj.length; i++){
                if(obj.options[i].selected == true){
                        j = j+1;
                }
        }
        return j;
}

function checkOption(obj){
        for(i=0; i<obj.length; i++){
                if(obj.options[i].value== ''){
                        obj.options[i] = null;
                }
        }
}

function checkOptionAll(obj){
        checkOption(obj);
        for(i=0; i<obj.length; i++){
                obj.options[i].selected = true;
        }
}

function checkOptionNone(obj){
        for(i=0; i<obj.length; i++){
                obj.options[i].selected = false;
        }
}

function checkOptionAdd(obj, text, value){
        obj.options[obj.length] = new Option(text, value, false, false);
}

function checkOptionRemove(obj){
        checkOption(obj);
        i = obj.selectedIndex;
        while(i!=-1){
                obj.options[i] = null;
                i = obj.selectedIndex;
        }
}

function checkOptionClear(obj){
        i = obj.length;
        while(i!=-1){
                obj.options[i] = null;
                i = i - 1;;
        }
}

function checkOptionTransfer(from,to){
        checkOption(from);
        checkOption(to);
        i = from.selectedIndex;
        while(i!=-1){
                to.options[to.length] = new Option(from.options[i].text, from.options[i].value, false, false);
                from.options[i] = null;
                i = from.selectedIndex;
        }
}

// browser checker
function Browser() {
        var b=navigator.appName;
        if (b=="Netscape") this.b="ns";
        else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
        else if (b=="Microsoft Internet Explorer") this.b="ie";
        if (!b) alert('Unidentified browser./nThis browser is not supported,');
        this.version=navigator.appVersion;
        this.v=parseInt(this.version);
        this.ns=(this.b=="ns" && this.v>=4);
        this.ns4=(this.b=="ns" && this.v==4);
        this.ns6=(this.b=="ns" && this.v==5);
        this.ie=(this.b=="ie" && this.v>=4);
        this.ie4=(this.version.indexOf('MSIE 4')>0);
        this.ie5=(this.version.indexOf('MSIE 5')>0);
        this.ie55=(this.version.indexOf('MSIE 5.5')>0);
        this.opera=(this.b=="opera");
        this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
        this.def=(this.ie||this.dom); // most used browsers, for faster if loops
        var ua=navigator.userAgent.toLowerCase();
        if (ua.indexOf("win")>-1) this.platform="win32";
        else if (ua.indexOf("mac")>-1) this.platform="mac";
        else this.platform="other";
}
is = new Browser();
if(is.ie) {
document.writeln("<link rel=stylesheet href=/templates/ie.css>");
document.writeln("<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>");
}

// filesystem functions
function fs_view(url){
        newWindow(url,6);
}
function fs_openfolder(folder, obj, page){
        obj.path.value = (folder == "..") ? obj.path.value.substring(0,obj.path.value.lastIndexOf("/")) : obj.path.value + "/" + folder;
        obj.action = page;
        obj.submit();
}
function fs_newfolder(obj, page){
        folder = prompt(globalAlertMsg8, "New_Folder");
        if(folder!=null && Trim(folder)!=""){
                if(validateFilename(folder)){
                        obj.folderName.value = folder;
                        obj.action = page;
                        obj.submit();
                }
        }
}
function fs_fileupload(obj, page){
        if(check_int(obj.no_file, 1, globalAlertMsg9)){
                obj.action = page;
                obj.submit();
        }
}
function fs_attachfile(obj, element, target){
        var x = "";
        for(var i=0;i<obj.elements.length;i++){
                if (obj.elements[i].name==element && obj.elements[i].checked){
                        if (x!='') x = x + " : ";
                        x = x + obj.path.value + '/' + obj.elements[i].value
                }
        }
        target.value = x;
        self.close();
}
function fs_rename(obj, element, page){
        var flag=0;
        if(countChecked(obj,element)==1) {
                filename = prompt(globalAlertMsg10, returnChecked(obj, element))
                if(filename!=null && Trim(filename)!=""){
                        if(validateFilename(filename)){
                                for(var i=0 ; i<obj.elements.length ; i++) {
                                        if (obj.elements[i].name==element && obj.elements[i].value==filename)
                                        flag=1;
                                }
                                if(flag==1){
                                        alert(globalAlertMsg11);
                                }else{
                                        obj.newName.value = filename;
                                        obj.action = page;
                                        obj.submit();
                                }
                        }
                }
        } else {
                alert(globalAlertMsg1);
        }
}

function fs_unzip(obj, element, page){
        var flag=0;
        if(countChecked(obj,element)==1) {
                filename = returnChecked(obj,element);
                filename = filename.toLowerCase();
                if(filename.indexOf(".zip")!=-1){
                        if(confirm(globalAlertMsg12)){
                                obj.action = page;
                                obj.submit();
                        }
                }else{
                        alert(filename + globalAlertMsg13);
                }
        } else {
                alert(globalAlertMsg1);
        }
}

function fs_move(obj, element, page){
        if(countChecked(obj,element)==0)
        alert(globalAlertMsg2);
        else{
                obj.action = page;
                obj.submit();
        }
}

function fs_copy(obj, element, page){
        if(countChecked(obj,element)==0)
        alert(globalAlertMsg2);
        else{
                obj.action = page;
                obj.submit();
        }
}

// front end view functions
function fe_view_announcement(id){
        newWindow('/home/view_announcement.php?AnnouncementID='+id,20);
}
function fe_view_class_announcement(className, id){
        newWindow('/home/view_class_announcement.php?AnnouncementID='+id+'&AnnouncementClassName='+className,20);
}
function fe_view_event(id){
        newWindow('/home/view_event.php?EventID='+id,0);
}

function fe_view_event_by_date(ts){
        newWindow('/home/view_event_by_date.php?ts='+ts,1);
}

function fe_view_event_by_type(tp){
        newWindow('/home/view_event_by_type.php?tp='+tp,1);
}

function fe_view_polling(id){
        newWindow('/home/view_pollresult.php?PollingID='+id,2);
}

function fe_eclass(id){
        newWindow('/home/eclass/login.php?uc_id='+id,19);
}

function fe_eclass_guest(id){
        newWindow('/home/eclass/guest.php?c_id='+id,19);
}

function fe_directory(id){
        newWindow('view.php?GroupID='+id,1);
}

function fe_pastpoll(){
        newWindow('/home/view_pastpoll.php',1);
}

function fe_pollnow(){
        newWindow('/home/view_pollnow.php',91);
}

function fe_view_timetable(id){
        newWindow('/home/school/timetable/index.php?GroupID='+id,10);
}

function fe_view_chat(id){
        newWindow('/home/school/chat/index.php?GroupID='+id,10);
}

function fe_view_bulletin(id){
        newWindow('/home/school/bulletin/index.php?GroupID='+id,10);
}

function fe_view_links(id){
        newWindow('/home/school/links/index.php?GroupID='+id,10);
}

function fe_view_files(id){
        newWindow('/home/school/files/index.php?GroupID='+id,10);
}

function fe_view_settings(id){
         newWindow('/home/school/settings/index.php?GroupID='+id,10);
}

function fe_view_homework_detail(id){
        newWindow('/home/homework/view.php?hid='+id,1);
}

function fe_view_day_rb(ts){
         newWindow('/home/resource/dayview.php?ts='+ts,1);
}
function fe_view_qb(id){
         newWindow('/home/school/qb/index.php?GroupID='+id,10);
}

function fe_view_all_event(){
         newWindow('/home/allevent.php',9);
}


function open_tv()
{
         tv_window = window.open('/home/plugin/campustv/','tv_window','scrollbars=0,toolbar=0,menubar=0,resizable=1,dependent=0,status=0,width=780,height=550,left=25,top=25')
}

function open_bulletin_msg(id)
{
         newWindowNotClose('/home/school/bulletin/message.php?BulletinID='+id,10,"intranet_bulletin");
}

function qb_open_source_document(id, isEng)
{
         newWindowNotClose('/home/school/qb/view_source.php?qid='+id+'&isEng='+isEng,10,"intranet_qb_source");
}
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 check_numeric(f,d,msg){
        if(f.value=='' || !IsNumeric(f.value)){
                alert(msg);
                f.value=d;
                f.focus();
                return false;
        }else{
                return true;
        }
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var Char;

   for (i = 0; i < sText.length; i++)
   {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1)
        {
            return false;
        }
   }
   return true;

}


/*================================================================================*/
/*============================== new for Junior 2.0 ==============================*/
/*================================================================================*/

var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
var pa = "parent";
var sliding = {MyTools:false};
var ck_move_to = "ck_move_to";

//initilization
function init_tool_bar(lay, h) {
	if (isCookieEnabled()) {
		var ck_position = parseInt(getCookie(ck_move_to));
		if (ck_position!=h && !isNaN(ck_position)) {
		    movelayer(lay, (ck_position-h));
		}
	}
}

function movelayer(lay,h){
	if (ie4) {heig=document.all[lay].style.left;}
	if (ns4) {heig=document.layers[pa].document.layers[lay].left;}
	if (ns6) {heig=document.getElementById([lay]).style.left;}
	ih = parseInt(heig) + h;
	if (ie4) {document.all[lay].style.left=ih+'px';}
	if (ns4) {document.layers[pa].document.layers[lay].left = ih;}
	if (ns6) {document.getElementById([lay]).style.left=ih+'px';}
}


function slide(lay, h, speed, up) {
	if (ie4) {
		heig=document.all[lay].style.left;
		it=4;
	}
	if (ns4) {heig=document.layers[pa].document.layers[lay].left; it=6;}
	if (ns6) {heig=document.getElementById([lay]).style.left; it=10;}
	ih = parseInt(heig);

	if (up == 0){
		if (ih != h)
			movelayer(lay, it);
		if (ih < h) {
			setSliding(lay, 1);
			setTimeout("slide('"+lay+"',"+h+","+speed+",0)",speed);
		} else {
		    setSliding(lay, 0);
			if (isCookieEnabled())
			    setCookie(ck_move_to, h);
		}
	} else {
		if (ih != 25)
			movelayer(lay, -it);
		if (ih > 25) {
			setSliding(lay, 1);
			setTimeout("slide('"+lay+"',"+h+","+speed+",1)",speed);
		} else {
		    setSliding(lay, 0);
			if (isCookieEnabled())
				setCookie(ck_move_to, 25);
		}
	}
}


function setSliding(lay, on_off) {
	is_sliding = "sliding." + lay;
	is_sliding += (on_off==0) ? "=false" : "=true";
	eval (is_sliding);
}


function getSliding(lay) {
	is_sliding = "sliding." + lay;
	return eval(is_sliding);
}


function move(lay,h){
	if (getSliding(lay))
		return;
	if (ie4) {
		heig=document.all[lay].style.left;
		speed=1;
	}
	if (ns4) {heig=document.layers[pa].document.layers[lay].left; speed=1;}
	if (ns6) {heig=document.getElementById([lay]).style.left;speed=1;}
	ih = parseInt(heig);

	if (ih<=25)
		slide(lay,h,speed,0);
	else
		slide(lay,h,speed,1);
}




function setCookie(name, value)
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	var path = "/";

	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function getCookie(name) {
	var bikky = document.cookie;
	var index = bikky.indexOf(name + "=");
	if (index == -1) return null;
	index = bikky.indexOf("=", index) + 1; // first character
	var endstr = bikky.indexOf(";", index);
	if (endstr == -1) endstr = bikky.length; // last character

	return unescape(bikky.substring(index, endstr));
}

function isCookieEnabled() {
  if (document.all) {
    if (!navigator.cookieEnabled) {
      return false;
    }
    else return true;
  }
  else {
    setCookie('temp','temp');
    var temp = getCookie('temp');
    if (!temp) {
      return false;
    }
    else return true;
  }
}

function check(from,to){
	checkOption(from);
	checkOption(to);
	i = from.selectedIndex;
	while(i!=-1){
		to.options[to.length] = new Option(from.options[i].text, from.options[i].value, false, false);
		from.options[i] = null;
		i = from.selectedIndex;
	}
}


function compareTime(date_s, hr_s, min_s, date_e, hr_e, min_e) {
    var time1 = toTimeStr(date_s, hr_s, min_s);
	var time2 = toTimeStr(date_e, hr_e, min_e);
	if (time1>time2) {
	    return false;
	}else {
		return true;
	}
}

function toTimeStr(date_o, hr_o, min_o) {
    var hr_v = parseInt(hr_o.options[hr_o.selectedIndex].value);
	if (hr_v<10) {
	    hr_v = "0"+hr_v;
	}
	min_v = parseInt(min_o.options[min_o.selectedIndex].value);
	if (min_v<10) {
	    min_v = "0"+min_v;
	}
	var time1 = date_o.value + hr_v + min_v;
	return time1;
}


function charEscape(xStr) {
	var fStr = "";
    for (var j=0; j<xStr.length; j++)
	{
		fStr += (xStr.charCodeAt(j)>255) ? xStr.charAt(j) : escape(xStr.charAt(j));
	}

	return fStr;
}


function postInstantForm(obj, url, method, winType, winName) {
	var aWin = newWindow("",winType);
	var frmTargetOrg = obj.target;
	var frmActionOrg = obj.action;
	var frmMethodOrg = obj.method;

	obj.target = winName;
	if (method!="")
	{
		obj.form.method = method;
	}
	obj.action = url;
	obj.submit();

	obj.target = frmTargetOrg;
	obj.action = frmActionOrg;
	obj.method = frmMethodOrg;

    return;
}

// Added by Simon 7 Nov 2003
function clickMark(obj, page){
	if(confirm(globalAlertMsg22)){
		obj.action=page;
		obj.submit();
	}
}


function displayTable(tableID, myStyle){
	//block, none, inline
	/*var currentStyle = document.all[tableID].style.display;
	var selectedStyle = (typeof(myStyle)!="undefined") ? myStyle : "block";
	var newStyle = (currentStyle=="none") ? selectedStyle : "none";

	document.all[tableID].style.display = newStyle;

	return;*/
	if (document.all[tableID])
	{
		
	var currentStyle = document.all[tableID].style.display;
	var newStyle = "none";
	if (typeof(myStyle)!="undefined")
	{
		newStyle = myStyle;
	} else
	{
		newStyle = (currentStyle=="none") ? "block" : "none";
	}

	document.all[tableID].style.display = newStyle;
	
	}

	return;
}


/* Used in :
	/staff2/data/daily/staff_status_in.php
	/staff2/data/daily/staff_status_in_list.php
	/staff2/data/daily/staff_status_out.php
	/staff2/data/daily/staff_status_out_list.php
*/
function setDivVisible(state, lay, lay2)
{
	var DivRef = document.getElementById(lay);
	var lay_used = (lay2!="") ? lay2 : "lyrShim";
	var IfrRef = document.getElementById(lay_used);
	if (state)
	{
		DivRef.style.display = 'block';
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = 'block';
	} else
	{
		DivRef.style.display = 'none';
		IfrRef.style.display = 'none';
	}
}

/*
Floating Menu script-  Roy Whittle (http://www.javascript-fx.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/
function JSFX_FloatTopDiv(SpecY)
{
	
	var startX = 0,	
	startY = 19;
	
	if (typeof(SpecY) != "undefined")
	{
		startY = SpecY;
	}
	
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x;this.style.top=y;};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function()
	{
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}

		if (parseInt(ftlObj.y)>parseInt(getPostion(document.getElementById('hidden_image'), "offsetTop")))
		{
			ftlObj.sP(ftlObj.x, ftlObj.y);
		} else
		{
			ftlObj.sP(ftlObj.x, parseInt(getPostion(document.getElementById('hidden_image'), "offsetTop")));
		}
		setTimeout("stayTopLeft()", 15);
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
}

function jChangeContent( objID, new_content ) {
	var obj = document.getElementById(objID);
	if (obj!=null)
	{
		obj.innerHTML = new_content;
	}
}

/* Used in :
	/staff2/data/daily/staff_status_in.php
	/staff2/data/daily/staff_status_in_list.php
	/staff2/data/daily/staff_status_out.php
	/staff2/data/daily/staff_status_out_list.php
*/
function getPostion(obj, direction){
	var objStr = "obj";
	var pos_value = 0;

	while (typeof(eval(objStr))!="undefined" && eval(objStr + ".tagName")!="BODY")
	{
		pos_value += eval(objStr + "." + direction);
		objStr += ".offsetParent";
	}

	return pos_value;
}

/*
* function for valid numeric strings
*/
function jIS_NUMERIC(jParString)	
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (jParString.length == 0) return false;

	//  test jParString consists of valid characters listed above
	for (i = 0; i < jParString.length && blnResult == true; i++)
	{
		strChar = jParString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

/*
* function to check whether value is in a array
*/
function jIN_ARRAY(jParArray, jParString)	
{
	var len = jParArray.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( jParArray[x] == jParString ) return true;
	}
	return false;
}

function strReplaceAll(s, t, f){
	var tmp1=s;
	var tmp2="";

	while (tmp1.indexOf(t)!=-1)
	{
		tmp2=tmp2+tmp1.substring(0,tmp1.indexOf(t))+f;
		tmp1=tmp1.substring(tmp1.indexOf(t)+t.length);
	}
	tmp2=tmp2+tmp1;

	return tmp2;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function Select_All_Selection_Option(SelectObj,SelectValue) {
	var SelectIndex = 0;
	
	if (SelectValue == "") {
		return true;
	}
	else {
		for (var j=0; j< SelectObj[0].length; j++) {
			if (SelectObj[0].options[j].value == SelectValue) {
				SelectIndex = j;
				break;
			}
		}
		
		for (var i=0; i< SelectObj.length; i++) {
			SelectObj[i].selectedIndex = SelectIndex;
		}
		
		return true;
	}
}
function openPortfolio(){
        newWindow('/home/eclass/index_portfolio.php',19);
}

function isInteger(val)
{
    if(val==null)
    {
        return false;
    }
    if (val.length==0)
    {
        return false;
    }
    for (var i = 0; i < val.length; i++) 
    {
        var ch = val.charAt(i)
        if (i == 0 && ch == "-")
        {
            continue
        }
        if (ch < "0" || ch > "9")
        {
            return false
        }
    }
    return true
}


function init_textToSpeach(ignoreEmpty){
	var ignoreEmpty = ignoreEmpty || false;
	  var img_loading = IMAGE_PREFIX+"loading_s.gif";
	  
	  if($(".textToSpeech").length > 0){
	    $(".textToSpeech").click(function (){	    	
	      if($(this).attr("src") != img_loading){
	        $(this).attr("src", img_loading);  
	        TTS_Play($(this));
	      }
	    });
	  }
	  
	  if($(".TTS_PlayButton").length > 0){
	    $(".TTS_PlayButton").each(function(){
	    	var target = $(this).attr("ttsTarget");	    	
	    	if(ignoreEmpty || Trim($("#"+target).text()) != ""){
		      $(this).html(
		        TTS_PlayButton(
		        $(this).attr("ttsTarget"),
		        $(this).attr("ttsPlayer"),
		        $(this).attr("ttsLang"),
		        $(this).attr("ttsPlayerType"),
		        $(this).attr("ttsButtonFull"),
		        $(this).attr("ttsButtonHighLight"),
		        $(this).attr("ttsButtonSetting"),
		        $(this).attr("ttsExpired")	        
		        )
		      );
	    	}
	    });
	  }

	}
	

// function for return message
{
var TimeoutObj;
function Get_Return_Message(Message) {
	if(Trim(Message) != ''){
		clearTimeout(TimeoutObj);
		var ReturnMessage = Message.split('|=|');
	
		var MessageLayer = $("div.SystemReturnMessage");
		
		if (ReturnMessage[0] == "0") 
			MessageLayer.addClass("warning_box");
		else 
			MessageLayer.removeClass("warning_box");
		
		var Temp = ReturnMessage[1];
		Temp += ' <a href="#" onclick="$(\'div.SystemReturnMessage\').css(\'visibility\',\'hidden\'); return false;">[Clear]</a>';
		$("div.msg_board_right").html(Temp);
		MessageLayer.css("visibility",'visible');
		TimeoutObj = setTimeout("Hide_Return_Message();",1000*5);
	}
}

function Hide_Return_Message() {
	$("div.SystemReturnMessage").css("visibility","hidden");
	clearTimeout(TimeoutObj);
}

function Show_jEditable_Edit_Background(Obj, js_PATH_WRT_ROOT, js_LAYOUT_SKIN) {
	Obj.style.backgroundImage = "url(" + js_PATH_WRT_ROOT + "/images/" + js_LAYOUT_SKIN + "/icon_edit_b.gif)";
	Obj.style.backgroundPosition = "center right";
	Obj.style.backgroundRepeat = "no-repeat";
}

function Hide_jEditable_Edit_Background(Obj) {
	Obj.style.backgroundImage = "";
	Obj.style.backgroundPosition = "";
	Obj.style.backgroundRepeat = "";
}

function js_Hide_ThickBox()
{
	tb_remove();
}

function initThickBox(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
}
}

// block ui functions
{
var isBlocking = false;
var blockMsg = "Loading (��J��...)";
function Block_Thickbox(){
	if (!isBlocking) {
		$('#TB_window').block(blockMsg, { color:'#ccc' ,border:'3px solid #ccc' });
	}
}

function UnBlock_Thickbox() {
	$('#TB_window').unblock();
	isBlocking = false;
}

function Block_Document() {
	if (!isBlocking) {
		
		$('body').block(blockMsg, { color:'#ccc' ,border:'3px solid #ccc' });
	}
}

function UnBlock_Document() {
	$('body').unblock();
	isBlocking = false;
}

function Block_Element(ElementID) {
	$('#'+ElementID).block(blockMsg, { color:'#ccc' ,border:'3px solid #ccc' });
}

function UnBlock_Element(ElementID) {
	$('#'+ElementID).unblock();
}
}

// select all options for multipule selection box
function Select_All_Options(SelectID,SelectType) {
	var SelectList = document.getElementById(SelectID);
	for (var j=0; j< SelectList.length; j++) {
		SelectList.options[j].selected = SelectType;
	}
}

function Get_Form_Values(fobj, excluded) {
   var str = "";
   var valueArr = null;
   var val = "";
   var cmd = "";
   for(var i = 0;i < fobj.elements.length;i++) {
   	
   	 if(excluded == fobj.elements[i].name)
   	 	continue;
   	 
   	 //alert(fobj.elements[i].name + ": " + fobj.elements[i].type);
     switch(fobj.elements[i].type) {
       case "text":
            str += fobj.elements[i].name +
             "=" + encodeURIComponent(fobj.elements[i].value) + "&";
            break;
       case "select-one":
            str += fobj.elements[i].name +
            "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
            break;
       case "hidden":
       			str += fobj.elements[i].name +
             "=" + encodeURIComponent(fobj.elements[i].value) + "&";
             break;
       case "checkbox":
       case "radio":
       			if (fobj.elements[i].checked) {
       				str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].value) + "&";
       			}
       			 break;
       case "select-multiple":
       			for (var j=0; j< fobj.elements[i].length; j++) {
       				if (fobj.elements[i].options[j].selected) {
       					str += fobj.elements[i].name +
            		"=" + fobj.elements[i].options[j].value + "&";
       				}
       			}
       			 break;
     }
   }
   str = str.substr(0,(str.length - 1));
   
   return str;
}

function Get_Check_Box_Value(CheckBoxID,ReturnType,IgnoreSelectedStatus) {
	var IgnoreSelectedStatus = IgnoreSelectedStatus || false;
	var ReturnType = ReturnType || "Array";
	var ValueArray = Array();
	if (document.getElementsByName(CheckBoxID)) {
		var CheckboxElement = document.getElementsByName(CheckBoxID);
		var ValueStr = '';
		for (var i=0; i< CheckboxElement.length; i++) {
			if (CheckboxElement[i].checked || IgnoreSelectedStatus) 
				ValueStr += CheckboxElement[i].value + ',';
		}
		
		if (ValueStr != "" && ValueStr.lastIndexOf(',') != -1) {
			ValueStr = ValueStr.substring(0,ValueStr.lastIndexOf(','));
			
			ValueArray = ValueStr.split(',');
		}	
	}
	
	if (ReturnType == "Array") {
		return ValueArray;
	}
	// form/ ajax post query string
	else {
		var ValueStr = "";
		for (var i=0; i< ValueArray.length; i++) {
			ValueStr += CheckBoxID + "=" + ValueArray[i] + '&';
		}
		
		return ValueStr;
	}
}

function Get_Radio_Value(RadioID) {
	if (document.getElementsByName(RadioID)) {
		var RadioElement = document.getElementsByName(RadioID);
		var ValueStr = '';
		for (var i=0; i< RadioElement.length; i++) {
			if (RadioElement[i].checked) {
				return RadioElement[i].value;
				break;
			}
		}
	}
	
	return "";
}

function Get_Selection_Value(SelectionID,ReturnType,IgnoreSelectedStatus) {
	var ReturnType = ReturnType || "Array";
	var IgnoreSelectedStatus = IgnoreSelectedStatus || false;
	var ValueArray = Array();
	var str = '';
	
	if (document.getElementById(SelectionID)) {
		var SelectionObj = document.getElementById(SelectionID);
		switch(SelectionObj.type) {
    	case "select-one":
    		str += SelectionObj.options[SelectionObj.selectedIndex].value; 
	      //str += fobj.elements[i].name +
	      //"=" + SelectionObj.options[SelectionObj.selectedIndex].value + "&";
	      break;
      case "select-multiple":
				for (var j=0; j< SelectionObj.length; j++) {
					if (SelectionObj.options[j].selected || IgnoreSelectedStatus) {
	 					str += SelectionObj.options[j].value + ",";
	 				}
	 			}
	 			break;
  	}
  	
  	if (str.lastIndexOf(',') != -1) 
  		str = str.substring(0,str.lastIndexOf(','));
  		
  	if (str != "") 
  		ValueArray = str.split(',');
	}
	
	if (ReturnType == "Array") {
		return ValueArray;
	}
	// normal string -- onlu for select-one element
	else if (ReturnType == "String") {
		return str;
	}
	// form/ ajax post query string
	else {
		str = "";
		for (var i=0; i< ValueArray.length; i++) {
			str += SelectionID + "=" + ValueArray[i] + '&';
		}
		
		return str;
	}
}

function Set_Checkbox_Value(CheckboxName,CheckStatus) {
	var obj = document.getElementsByName(CheckboxName);
	
	for (var i=0; i< obj.length; i++) {
		obj[i].checked = CheckStatus;
	}
}

function Scroll_To_Element(DomID) {
$(window).scrollTo('#'+DomID,800,{queue:true});
}

function Scroll_To_Top() {
$(window).scrollTo( 0, 800, {queue:true} );
}

function embedFlash(areaFlashID, swfPath, flashVarsStr, flashColor, flashWidth, flashHeight, flashVersion, IsTransparent){
	var IsTransparent = IsTransparent || "YES";
	var areaFlash = document.getElementById(areaFlashID);
	while(areaFlash.hasChildNodes()){
		areaFlash.removeChild(areaFlash.firstChild);
	}
	
	var flashvars = flashVarsStr;
	
	if (IsTransparent == "YES") {
		WindowMode = 'transparent';
	}
	else {
		WindowMode = 'window';
	}
	var params = {
		play: "true",
		loop: "true",
		menu: "true",
		quality: "high",
		//scale: "showall",
		scale: "noscale",
		//wmode:"transparent",
		wmode: WindowMode,
		bgcolor: flashColor,
		//devicefont: "false",
		allowscriptaccess: "sameDomain",
		allowfullscreen: "true"
	};
	var attributes = {
		id: areaFlashID,
		name: areaFlashID,
		align: "middle"
	};
	
	swfobject.embedSWF(swfPath, areaFlashID, flashWidth, flashHeight, flashVersion, "expressInstall.swf", flashvars, params, attributes);
}

function htmlspecialchars (string, quote_style, charset, double_encode) {
    // Convert special characters to HTML entities  
    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined' || quote_style === null) {        quote_style = 2;
    }
    string = string.toString();
    if (double_encode !== false) { // Put this first to avoid double-encoding
        string = string.replace(/&/g, '&amp;');    }
    string = string.replace(/</g, '&lt;').replace(/>/g, '&gt;');
 
    var OPTS = {
        'ENT_NOQUOTES': 0,        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/'/g, '&#039;');
    }    if (!noquotes) {
        string = string.replace(/"/g, '&quot;');
    }
 
    return string;
}

function switchOnlineHelp(m_function,evt){
	
	var slide_speed = 500;
	if($('#online_'+m_function+'_help_board').is(":hidden"))
	{
		$('#online_'+m_function+'_help_btn').onclick =  function() {switchOnlineHelp(m_function);}; 
		if (document.compatMode == 'BackCompat' ){
			$('#online_'+m_function+'_help_board').show(200);
		}
		else{
			$('#online_'+m_function+'_help_board').slideDown(slide_speed);
		}
		
		var pos = findPos(document.getElementById('online_'+m_function+'_help_btn'));
	 	 
  		$('#online_'+m_function+'_help_board').css('left', (pos[0]-60) + "px");
  		$('#online_'+m_function+'_help_board').css('top',  (pos[1]+25) + "px");
	}
	else
	{
		if (document.compatMode == 'BackCompat' ){
			$('#online_'+m_function+'_help_board').hide(200);
		}
		else{
			$('#online_'+m_function+'_help_board').slideUp(slide_speed);
		}
    	$('#online_'+m_function+'_help_btn').onclick =  function() {switchOnlineHelp(m_function);};
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}