<?php

function GetBaseJavaFunc()
{
    global $_REQUEST;
    $javafunc = "";
    $javafunc .=  "<script language ='javascript'>";
    $javafunc .=  "function getFieldsInit(obj) {";
    $javafunc .=  " return 1; ";
    $javafunc .=  "}";
    $javafunc .=  "function getRBtnInit(obj) {";
    $javafunc .=  "return 1;";
    $javafunc .=  "}";
    $javafunc .=  "</script>";
    if($_REQUEST['servicemod'] == 'applicants_online' || $_REQUEST['CREATEPDF'])
        $javafunc = '';
        return $javafunc;
}    

function GetAdvJavaFuncFRB()

{

        $javafunc = "";
            $javafunc .= "<script language ='javascript'>";
                    $javafunc .= "function getFieldsInit(obj) {";
                    $javafunc .= "var selects = document.getElementsByName(obj.name);";
                        $javafunc .= "if(obj.type == 'checkbox' || obj.type == 'radio')";
                                $javafunc .= "{";
    	                                $javafunc .= "for (var i = 0; i <= selects.length-1; i++)  {";
                                    		$javafunc .= "selects[i].checked = obj.checked;";
                            		$javafunc .= "}";
                                $javafunc .= "}";
                        	$javafunc .= "else";
                                $javafunc .= "{";
	                                $javafunc .= "for (var i = 0; i <= selects.length-1; i++)  {";
                    		                $javafunc .= "selects[i].value = obj.value;";
    	    		                $javafunc .= "}";
	                        $javafunc .= "}";
	            $javafunc .= "}";
                $javafunc .= "function getRBtnInit(obj) {";
                        $javafunc .= "var chk = obj.value;";
                                $javafunc .= "for (var i = 0; i <= ".$_SESSION['radioCount']."-1; i++)";
                                $javafunc .= "{";
                                        $javafunc .= "var elemId = obj.id;";
                                        $javafunc .= "var myArray = elemId.split(/[add]+/);";
                                        $javafunc .= " elemId = myArray[0];";
                                        $javafunc .= "if(chk == '')";
                                            $javafunc .= " elemId = elemId + 'addA' + i;";
                                        $javafunc .= "else";
                            		    $javafunc .= " elemId = elemId + 'add' + chk + i;";
                                        $javafunc .= "if(document.getElementById(elemId))";
                                        $javafunc .= "{";
                                                $javafunc .= "document.getElementById(elemId).checked = true;";
                                        $javafunc .= "}";
                                $javafunc .= "}";
                $javafunc .= "}";
                $javafunc .= "function checkOverride(formName)";
                $javafunc .= "{";
                    $javafunc .= "if(confirm('"._('Do you want to save the form despite the incorrect values?')."'))";
                    $javafunc .= "{";
                            $javafunc .= "var form = document.getElementById(formName);";
                            $javafunc .= "form.action = form.action + '&override=true';";
                            $javafunc .= "form.submit();";
                    $javafunc .= "}";
    	            $javafunc .= "else";
        	            $javafunc .= " return 0;";
	        $javafunc .= "}";
                $javafunc .= "</script>";

return $javafunc;
}

function GetAdvJavaFuncBody()
{
    $javafunc = "";
    $javafunc .= "<SCRIPT language ='javascript'>";
   
       if($_REQUEST['expanded']=='true')
		$javafunc .= "size = 200;";
       else
		$javafunc .= "size = 30;";
            $javafunc .= " function expandFrame()";
            $javafunc .= "{";
	            $javafunc .= "if(size==30)";
    	            $javafunc .= "{";
                            $javafunc .= "parent.document.getElementById('mainframeset').rows=\"*,200\";";
                            $javafunc .= "size = 200;";
                    $javafunc .= "}";
                    $javafunc .= "else";
                    $javafunc .= "{";
		            $javafunc .= "parent.document.getElementById('mainframeset').rows=\"*,30\";";
                            $javafunc .= "size = 30;";
                    $javafunc .= "}";
            $javafunc .= "} ";
        $javafunc .= "function printBody()";
        $javafunc .= "{";
                $javafunc .= "if(parent.body.document.charts)";
                $javafunc .= "{";
                        $javafunc .= "parent.body.document.charts.SetVariable('print_chart',true);";
                $javafunc .= "}";
                $javafunc .= "else";
                $javafunc .= "{";
	                $javafunc .= "id=window.open('','_blank');";
                        $javafunc .= "id.location.href = 'footermenu.php?servicefunction=print';";
                $javafunc .= "}";
        $javafunc .= "}";
                    
$javafunc .= "function check_numeric(input) { ";
    $javafunc .= "input.value = input.value.replace(/[^\d.]/g, '');";
$javafunc .= "};";

$javafunc .= "</SCRIPT>";

return $javafunc;
}

function GetAdvJavaFuncMakeCourse()
{
/*
            $javafunc = "";
            $javafunc .= "<SCRIPT language=javascript>";
            $javafunc .= "function makeCourse(course_num,id)";
            $javafunc .= "{";
                    $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][COURSE_TITLE]\'))";
                            $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][COURSE_TITLE]\').onclick();";
	            $javafunc .= "if(courses[course_num])";
                            $javafunc .= "document.getElementById(\'inputvalues[\'+id+\'][COURSE_TITLE]\').value = courses[course_num];";
                    $javafunc .= "else if(courses[course_num.substring(0,7)])";
                    $javafunc .= "{";
                            $javafunc .= "course_num = course_num.substring(0,7);";
                            $javafunc .= "document.getElementById(\'inputvalues[\'+id+\'][COURSE_TITLE]\').value = courses[course_num];";
	            $javafunc .= "}";
	            $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][GRAD_SUBJECT_ID]\'))";
                            $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][GRAD_SUBJECT_ID]\').onclick();";
                    $javafunc .= "if(grad_subjects[course_num])";
                    $javafunc .= "{";
	                    $javafunc .= "for(var i=0;document.getElementById(\'inputvalues[\'+id+\'][GRAD_SUBJECT_ID]\').options[i].value != grad_subjects[course_num];i++)";
                            $javafunc .= "{}";
                            $javafunc .= "document.getElementById(\'inputvalues[\'+id+\'][GRAD_SUBJECT_ID]\').selectedIndex = i;";
                    $javafunc .= "}";
                    $javafunc .= "if(scales[course_num])";
                    $javafunc .= "{";
                            $javafunc .= "clickAllBoxes(id);";
                            $javafunc .= "for(var i=0;document.getElementById(\'inputvalues[\'+id+\'][GRADE_TYPE_ID]\').options[i].value != scales[course_num];i++)";
                            $javafunc .= "{}";
                            $javafunc .= "document.getElementById(\'inputvalues[\'+id+\'][GRADE_TYPE_ID]\').selectedIndex = i;";
                    $javafunc .= "}";
                    $javafunc .= "else if(scales.length && course_num)";
                    $javafunc .= "{";
                            $javafunc .= "clickAllBoxes(id);";
                            $javafunc .= "document.getElementById(\'inputvalues[\'+id+\'][GRADE_TYPE_ID]\').selectedIndex = 0;";
                    $javafunc .= "}";
            $javafunc .= "}";

            $javafunc .= "function clickAllBoxes(id)";
            $javafunc .= "{";
                    $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][GRADE_TITLE]\'))";
        	            $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][GRADE_TITLE]\').onclick();";
                    $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][CARRIES_CREDITS]\'))";
    	                    $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][CARRIES_CREDITS]\').onclick();";
    	            $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][CREDITS]\'))";
	                    $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][CREDITS]\').onclick();";
                    $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][GRADE_TYPE_ID]\'))";
	                    $javafunc .= 'document.getElementById(\'innerdivvalues[\'+id+\'][GRADE_TYPE_ID]\').style.display="inline";';
                    $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][GPA_POINTS]\'))";
                            $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][GPA_POINTS]\').onclick();";

if(SystemPreferences('WEIGHTED_GPA')=='Y')
{
                    $javafunc .= "if(document.getElementById(\'innerdivvalues[\'+id+\'][WEIGHTED_GPA_POINTS]\'))";
                            $javafunc .= "document.getElementById(\'innerdivvalues[\'+id+\'][WEIGHTED_GPA_POINTS]\').onclick();";
}
                    $javafunc .= "doOnresize();";
            $javafunc .= "}";
            $javafunc .= "</script>";

*/
            $javafunc = "";
            $javafunc .= "<SCRIPT language=javascript>";
            $javafunc .= "function makeCourse(course_num,id)";
            $javafunc .= "{";
                    $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][COURSE_TITLE]'))";
                            $javafunc .= "document.getElementById('innerdivvalues['+id+'][COURSE_TITLE]').onclick();";
	            $javafunc .= "if(courses[course_num])";
                            $javafunc .= "document.getElementById('inputvalues['+id+'][COURSE_TITLE]').value = courses[course_num];";
                    $javafunc .= "else if(courses[course_num.substring(0,7)])";
                    $javafunc .= "{";
                            $javafunc .= "course_num = course_num.substring(0,7);";
                            $javafunc .= "document.getElementById('inputvalues['+id+'][COURSE_TITLE]').value = courses[course_num];";
	            $javafunc .= "}";
	            $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][GRAD_SUBJECT_ID]')) ";
                            $javafunc .= "document.getElementById('innerdivvalues['+id+'][GRAD_SUBJECT_ID]').onclick();";
                    $javafunc .= "if(grad_subjects[course_num])";
                    $javafunc .= "{";
	                    $javafunc .= "for(var i=0;document.getElementById('inputvalues['+id+'][GRAD_SUBJECT_ID]').options[i].value != grad_subjects[course_num];i++)";
                            $javafunc .= "{}";
                            $javafunc .= "document.getElementById('inputvalues['+id+'][GRAD_SUBJECT_ID]').selectedIndex = i;";
                    $javafunc .= "}";
                    $javafunc .= "if(scales[course_num])";
                    $javafunc .= "{";
                            $javafunc .= "clickAllBoxes(id);";
                            $javafunc .= "for(var i=0;document.getElementById('inputvalues['+id+'][GRADE_TYPE_ID]').options[i].value != scales[course_num];i++)";
                            $javafunc .= "{}";
                            $javafunc .= "document.getElementById('inputvalues['+id+'][GRADE_TYPE_ID]').selectedIndex = i;";
                    $javafunc .= "}";
                    $javafunc .= "else if(scales.length && course_num)";
                    $javafunc .= "{";
                            $javafunc .= "clickAllBoxes(id);";
                            $javafunc .= "document.getElementById('inputvalues['+id+'][GRADE_TYPE_ID]').selectedIndex = 0;";
                    $javafunc .= "}";
            $javafunc .= "}";

            $javafunc .= "function clickAllBoxes(id)";
            $javafunc .= "{";
                    $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][GRADE_TITLE]')) ";
        	            $javafunc .= "document.getElementById('innerdivvalues['+id+'][GRADE_TITLE]').onclick();";
                    $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][CARRIES_CREDITS]')) ";
    	                    $javafunc .= "document.getElementById('innerdivvalues['+id+'][CARRIES_CREDITS]').onclick();";
    	            $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][CREDITS]')) ";
	                    $javafunc .= "document.getElementById('innerdivvalues['+id+'][CREDITS]').onclick();";
                    $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][GRADE_TYPE_ID]')) ";
	                    $javafunc .= 'document.getElementById(\'innerdivvalues[\'+id+\'][GRADE_TYPE_ID]\').style.display="inline";';
                    $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][GPA_POINTS]')) ";
                            $javafunc .= "document.getElementById('innerdivvalues['+id+'][GPA_POINTS]').onclick();";

if(SystemPreferences('WEIGHTED_GPA')=='Y')
{
                    $javafunc .= "if(document.getElementById('innerdivvalues['+id+'][WEIGHTED_GPA_POINTS]')) ";
                            $javafunc .= "document.getElementById('innerdivvalues['+id+'][WEIGHTED_GPA_POINTS]').onclick();";
}
                    $javafunc .= "doOnresize();";
            $javafunc .= "}";
            $javafunc .= "</script>";
            
return $javafunc;                                            
}

function GetAdvJavaFuncStuFields()
{
    $func1 = '<script language=javascript>
	function trim(string){
	    string = string.replace(/ /g,\' \');
	    return string.replace(/(^\s+)|(\s+$)/g, "");
	}

    function CompareAmountOpCodes(obj)
    {
        var linuxOS = obj.value.search("\n\r");
	if(linuxOS != -1)
            var sep = "\n\r";
        else
            var sep = "\n";
                                                    
        obj.value = trim(obj.value);
        var codesArr =  obj.value.split(sep);
                    
        var optStr = obj.id.replace("SELECT_CODES", "SELECT_OPTIONS");
        var optionsTextarea = document.getElementById(optStr);
        optionsTextarea.value = trim(optionsTextarea.value);
        var optArr = optionsTextarea.value.split(sep);
                                                                                                
        if(codesArr.length && optArr.length)
        {
            var saveBut = document.getElementById(\'savebutton\');
            if(codesArr.length != optArr.length && obj.value != \'\')
            {
                saveBut.disabled = \'disabled\';
                alert(\''._("You have to enter the equal quantity of options!").'\');
            }
	    else
	    {
		if(saveBut.disabled = \'disabled\')
		    saveBut.disabled = \'\';
	    }
	}
    }
    </script>';
    $func2 = "
    <script language=javascript>
    function StudentListFieldCheck()
    {
        for(var i=1; i<=20; i++)
        {
            var field = document.getElementById('inputlogging[TYPE][LOG_FIELD'+i+']');
            if(field)
            {
                if(field.value == '')
                {
                    if (confirm('"._("Do you want to remove one of these fields?")."'))
                        return true;
                    else
                        return  false;
                }
            }
	}
	return true;
    }
    </script>";
    $func3 = "
    <script language=javascript>
    function changeSortOrder(direction, fieldName, nearestElem)
    {
        var form = document.getElementById('fieldsForm');
        var nearestFieldCollection = document.getElementsByName('logfilednamediv');
        for(var i = 0; i<= nearestFieldCollection.length-1; i++)
        {
            if(nearestFieldCollection[i].id == fieldName)
            {
		if(direction == 'left')
		    var nearestField = nearestFieldCollection[i-1].id;
		if(direction == 'right')
		    var nearestField = nearestFieldCollection[i+1].id;
	    }
	}
	form.action = form.action + '&fieldname='+fieldName+'&nearelem='+nearestField;
	form.submit();
    }</script>";
    
    return $func1." ".$func2." ".$func3;
}
?>