/****************************************************************************************************
FUNCTION NAME:  COPYADDRESS()
DESCRIPTION:    Common Function.(Copying Mailing Adress to Permanent Adress)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   14th August 2009(14/8/2009)
****************************************************************************************************/
function CopyAddress(form_name, MailingAdd, StudPhone1, StudPhone2, StudEmail, StudMobile, PermanentAdd, StudPh1, StudPh2, StudEm, StudMob, chk_box)
{
    if(document.getElementById(chk_box).checked == true)
    {
        document.getElementById(PermanentAdd).value = document.getElementById(MailingAdd).value;
        document.getElementById(StudPh1).value = document.getElementById(StudPhone1).value;
        document.getElementById(StudPh2).value = document.getElementById(StudPhone2).value;
        document.getElementById(StudEm).value = document.getElementById(StudEmail).value;
        document.getElementById(StudMob).value = document.getElementById(StudMobile).value;
    }
    else
    {
        document.getElementById(PermanentAdd).value = "";
        document.getElementById(StudPh1).value = "";
        document.getElementById(StudPh2).value = "";
        document.getElementById(StudEm).value = "";
        document.getElementById(StudMob).value = "";
    }
}
/**************************************************************************************************
END OF 'COPYADDRESS()'
**************************************************************************************************/
/****************************************************************************************************
FUNCTION NAME:  PERCENTAGEMARK()
DESCRIPTION:    Common Function.(Calculating Percentage of Marks)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   26th August 2009(26/8/2009)
****************************************************************************************************/
function PercentageMark(form_name,MarkSecured,FullMarks,Percentage)
{

    var MS=document.getElementById(MarkSecured).value;
    var FM=document.getElementById(FullMarks).value;
    if(MS <= 10)
    {
        if(MS != "")
        {

            var Per=MS*100/FM;
            if(MS != 10)
            {
                var Per1 = Per.toFixed(2);
                document.getElementById(Percentage).value = Per1;
            }
            else
            {
                var Per1 = Math.round(Per);
                document.getElementById(Percentage).value = Per1;
                document.getElementById(Percentage).value = Per1;
            }

        }
        else
        {
            document.getElementById(Percentage).value = "";
        }
    }
    else
    {
        alert("Marks Secured exceed Full Marks! Please Enter valid marks.");
        document.getElementById(MarkSecured).value="";
    }
}
/*******************************END OF 'COPYADDRESS()'**************************************************/
/****************************************************************************************************
FUNCTION NAME:  SELECTADDROWS()
DESCRIPTION:    Common Function.(Adding Items from one List box to Another)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   2nd September 2009(02/9/2009)
****************************************************************************************************/
function SelectAddRows(ListBox1, ListBox2, hidden_arr)
{
    var SelID='';
    var SelText='';
    for (i=ListBox1.options.length - 1; i>=0; i--)
    {
        if (ListBox1.options[i].selected == true)
        {
            SelID=ListBox1.options[i].value;
            SelText=ListBox1.options[i].text;
            var newRow = new Option(SelText,SelID);
            ListBox2.options[ListBox2.length]=newRow;
            ListBox1.options[i]=null;
			
        }
    }
    hid_array = new Array();
    for (i=ListBox2.options.length - 1; i>=0; i--)
    {
        SelID=ListBox2.options[i].value;
        SelText=ListBox2.options[i].text;
        hid_array.push(SelID);

    }
    document.getElementById(hidden_arr).value = hid_array;

    var tot = ListBox1.length;
    var inG1 = hid_array.length;
    document.getElementById('ng').innerHTML = tot;
    var inG1 = hid_array.length;
    if(hidden_arr == "hidgruparr_1" || hidden_arr == "hidsectionarr_1")
    {
        document.getElementById('g1').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_2" || hidden_arr == "hidsectionarr_2")
    {
        document.getElementById('g2').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_3" || hidden_arr == "hidsectionarr_3")
    {
        document.getElementById('g3').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_4" || hidden_arr == "hidsectionarr_4")
    {
        document.getElementById('g4').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_5" || hidden_arr == "hidsectionarr_5")
    {
        document.getElementById('g5').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_6" || hidden_arr == "hidsectionarr_6")
    {
        document.getElementById('g6').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_7" || hidden_arr == "hidsectionarr_7")
    {
        document.getElementById('g7').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_8" || hidden_arr == "hidsectionarr_8")
    {
        document.getElementById('g8').innerHTML = inG1;
    }
}
/*******************************END OF SELECTADDROWS()**************************************************/

/****************************************************************************************************
FUNCTION NAME:  SELECTREMOVEROWS()
DESCRIPTION:    Common Function.(Removing Items from one List box to Another)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   2nd September 2009(02/9/2009)
****************************************************************************************************/
function SelectRemoveRows(ListBox1, ListBox2, hidden_arr)
{
    var SelID='';
    var SelText='';
    for (i=ListBox2.options.length - 1; i>=0; i--)
    {
        if (ListBox2.options[i].selected == true)
        {
            SelID=ListBox2.options[i].value;
            SelText=ListBox2.options[i].text;
            var newRow = new Option(SelText,SelID);
            ListBox1.options[ListBox1.length]=newRow;
            ListBox2.options[i]=null;
        }
    }
    hid_array = new Array();  
    for (i=ListBox2.options.length - 1; i>=0; i--)
    {
        SelID=ListBox2.options[i].value;
        SelText=ListBox2.options[i].text;
        hid_array.push(SelID);
    }
    
    document.getElementById(hidden_arr).value = hid_array;

    /**************     Count Students      *************/
    var tot = ListBox1.length;
    var inG1 = hid_array.length;
    document.getElementById('ng').innerHTML = tot;

    var inG1 = hid_array.length;
    if(hidden_arr == "hidgruparr_1" || hidden_arr == "hidsectionarr_1")
    {
        document.getElementById('g1').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_2"  || hidden_arr == "hidsectionarr_2")
    {
        document.getElementById('g2').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_3" || hidden_arr == "hidsectionarr_3")
    {
        document.getElementById('g3').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_4" || hidden_arr == "hidsectionarr_4")
    {
        document.getElementById('g4').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_5" || hidden_arr == "hidsectionarr_5")
    {
        document.getElementById('g5').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_6" || hidden_arr == "hidsectionarr_6")
    {
        document.getElementById('g6').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_7" || hidden_arr == "hidsectionarr_7")
    {
        document.getElementById('g7').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_8" || hidden_arr == "hidsectionarr_8")
    {
        document.getElementById('g8').innerHTML = inG1;
    }
}
/*******************************END OF SELECTREMOVEROWS()**************************************************/


/****************************************************************************************************
FUNCTION NAME:  SELECTALLROWS()
DESCRIPTION:    Common Function.(Adding all Items from one List box to Another)
CREATED BY:     NIRAJ KUMAR NAYAK
CREATED DATE:   8th October 2009(08/10/2009)
****************************************************************************************************/
function SelectAllRows(ListBox1, ListBox2, hidden_arr)
{
    var SelID='';
    var SelText='';
    for (i=ListBox1.options.length - 1; i>=0; i--)
    {
        SelID=ListBox1.options[i].value;
        SelText=ListBox1.options[i].text;
        var newRow = new Option(SelText,SelID);
        ListBox2.options[ListBox2.length]=newRow;
        ListBox1.options[i]=null;
    }
    hid_array = new Array();
    for (i=ListBox2.options.length - 1; i>=0; i--)
    {
        SelID=ListBox2.options[i].value;
        SelText=ListBox2.options[i].text;
        hid_array.push(SelID);

    }
    document.getElementById(hidden_arr).value = hid_array;

    var tot = ListBox1.length;
    var inG1 = hid_array.length;
    document.getElementById('ng').innerHTML = tot;
    var inG1 = hid_array.length;
    if(hidden_arr == "hidgruparr_1" || hidden_arr == "hidsectionarr_1")
    {
        document.getElementById('g1').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_2" || hidden_arr == "hidsectionarr_2")
    {
        document.getElementById('g2').innerHTML = inG1;
    }
}
/*******************************END OF SELECTALLROWS()**************************************************/

/****************************************************************************************************
FUNCTION NAME:  REMOVEALLROWS()
DESCRIPTION:    Common Function.(Removing Items from one List box to Another)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   2nd September 2009(02/9/2009)
****************************************************************************************************/
function RemoveAllRows(ListBox1, ListBox2, hidden_arr)
{
    var SelID='';
    var SelText='';
    for (i=ListBox2.options.length - 1; i>=0; i--)
    {
            SelID=ListBox2.options[i].value;
            SelText=ListBox2.options[i].text;
            var newRow = new Option(SelText,SelID);
            ListBox1.options[ListBox1.length]=newRow;
            ListBox2.options[i]=null;
    }
    hid_array = new Array();
    for (i=ListBox2.options.length - 1; i>=0; i--)
    {
        SelID=ListBox2.options[i].value;
        SelText=ListBox2.options[i].text;
        hid_array.push(SelID);
    }
    document.getElementById(hidden_arr).value = hid_array;

    /**************     Count Students      *************/
    var tot = ListBox1.length;
    var inG1 = hid_array.length;
    document.getElementById('ng').innerHTML = tot;

    var inG1 = hid_array.length;
    if(hidden_arr == "hidgruparr_1" || hidden_arr == "hidsectionarr_1")
    {
        document.getElementById('g1').innerHTML = inG1;
    }
    if(hidden_arr == "hidgruparr_2"  || hidden_arr == "hidsectionarr_2")
    {
        document.getElementById('g2').innerHTML = inG1;
    }
}
/*******************************END OF SELECTREMOVEROWS()**************************************************/


/****************************************************************************************************
FUNCTION NAME:  ShowHideDiv()
DESCRIPTION:    Common Function.(Show-Hide Divisions in Employee Add and Update)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   10th September 2009(10/09/2009)
****************************************************************************************************/
function ShowHideDiv(ch_box,email_NM,email_M,user)
{
    if(document.getElementById(ch_box).checked == true)
    {
        document.getElementById(email_NM).style.display="none";
        document.getElementById(email_M).style.display="block";
        document.getElementById(user).style.display="block";
    }
    else
    {
        document.getElementById(email_NM).style.display="block";
        document.getElementById(email_M).style.display="none";
        document.getElementById(user).style.display="none";
    }
}
/*******************************END OF ShowHideDiv()**************************************************/
/****************************************************************************************************
FUNCTION NAME:  NUMBERSONLY()
DESCRIPTION:    Common Function.(ASCII validation for only numeric value and dot(.))
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   15th September 2009(15/09/2009)
****************************************************************************************************/

function numbersonly( e )
{
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if( unicode != 8 )
    {
        if(unicode < 46 || unicode > 57 || unicode == 47)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        return true;
    }
}
/*******************************END OF NUMBERSONLY()**************************************************/
/****************************************************************************************************
FUNCTION NAME:  ONLYNUMBERS()
DESCRIPTION:    Common Function.(ASCII validation for only numeric value)
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   1st October 2009(01/10/2009)
****************************************************************************************************/
function onlynumbers(e)
{
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if( unicode != 8 )
    {
        if(unicode < 9 || unicode > 9 && unicode < 48 || unicode > 57) 
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        return true;
    }
}
/*******************************END OF ONLYNUMBERS()**************************************************/
/****************************************************************************************************
FUNCTION NAME:  nameonly()
DESCRIPTION:    Common Function.(ASCII validation for Name- Characters,colon(') and dot(.))
CREATED BY:     PRAKASH RANJAN SATPATHY
CREATED DATE:   1st October 2009(01/10/2009)
//onkeypress="return nameonly(event);"
****************************************************************************************************/
function nameonly( e )
{
    var unicode = e.charCode ? e.charCode : e.keyCode;
    if( unicode != 8 )
    {
        if(unicode < 32 || unicode > 32 && unicode < 39 || unicode > 39 && unicode < 46 || unicode > 46 && unicode < 65 || unicode > 90 && unicode < 97 || unicode > 122)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        return true;
    }
}
/*******************************END OF nameonly()**************************************************/
/****************************************************************************************************
FUNCTION NAME:  DISPLAY_SUB_SECTION()
DESCRIPTION:     Function.(Display the sub section in lesson plan)
CREATED BY:     NIRANJAN SARANGI
CREATED DATE:   24th September 2009(24/09/2009)
****************************************************************************************************/


    function display_sub_section(ltp, sub_section)
    {

        var divltptype = document.getElementById(ltp).value;
        if(divltptype == "L")
        {
            document.getElementById(sub_section).style.display="none";
        }
        if(divltptype == "P")
        {
            document.getElementById(sub_section).style.display="block";
        }

    }

/*******************************END OF DISPLAY_SUB_SECTION()**************************************************/

function validatePost(mon,yy,today_m,today_y)
{
	var month = document.getElementById(mon).value;
	var year = document.getElementById(yy).value;
	
	if(month > today_m && year >= today_y)
	{
		alert("Sorry, you cannot post Timesheet in advance!");
		document.getElementById(mon).focus();
		return false;
	}
	else if(year > today_y)
	{
		alert("Sorry, you cannot post Timesheet in advance!");
		document.getElementById(yy).focus();
		return false;
	}
	else
	{
		document.getElementById('succ').style.display='none';
		document.getElementById('load').style.display='block';
	}
}
function validateForm(txa,sel,date,typ)
{
	var t = document.getElementById(txa).value;
	var s = document.getElementById(sel).value;
	if(t == "")
	{
		alert("'Description' cann't be left blank!");
		document.getElementById(txa).focus();
		return false;
	}
	else if(s == "")
	{
		alert("'Full Day/Half Day/Leave' cann't be left blank!");
		document.getElementById(sel).focus();
		return false;
	}
	else if(t != "" && s != "")
	{
		if(typ == "post")
		{
			var conf = confirm("Are you sure you want to post Timesheet for '"+date+"' ?")
		}
		else if(typ == "update")
		{
			var conf = confirm("Are you sure you want to update Timesheet for '"+date+"' ?")
		}
		if(conf == false)
		{
			return false;
		}
		else
		{
			document.getElementById('succ').style.display='none';
			document.getElementById('load').style.display='block';
			return true;
		}
	}
}
function validatePost(mon,yy,today_m,today_y)
{
	var month = document.getElementById(mon).value;
	var year = document.getElementById(yy).value;
	
	if(month > today_m && year >= today_y)
	{
		alert("Sorry, you cann't post Timesheet in advance!");
		document.getElementById(mon).focus();
		return false;
	}
	else if(year > today_y)
	{
		alert("Sorry, you cann't post Timesheet in advance!");
		document.getElementById(yy).focus();
		return false;
	}
}
function changeColor(a,b,c)
{
	document.getElementById(c).style.backgroundColor=b;
}
function defaultColor(a,b,c)
{
	document.getElementById(c).style.backgroundColor=a;
}
function resizeTextarea(id)
{
	var len = document.getElementById(id).value.length;
	if(len > 35)
	{
		var y = (document.getElementById(id).value.length / 15);
		document.getElementById(id).rows = y+1;
	}
}
function resizeTextareaSmall(id)
{
	var len = document.getElementById(id).value.length;
	if(len > 12)
	{
		var y = (document.getElementById(id).value.length / 12);
		document.getElementById(id).rows = y+1;
	}
}
function funActiveUpdate(a,b)
{
	document.getElementById(a).disabled=false;
	document.getElementById(b).style.display='none';
}
/***************************************************************
Function Name : checkNode()
Description   : Timesheet View & Approved
Created By    : Prakash Ranjan Satpathy
Date Created  : 8th March 2010(08/03/2010)
***************************************************************/
if(!window.Node)
{
	var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}
function checkNode(node, filter)
{
	return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}
function getChildren(node, filter)
{
	var result = new Array();
	if(node)
	{
		var children = node.childNodes;
		for(var i = 0; i < children.length; i++)
		{
			if(checkNode(children[i], filter)) result[result.length] = children[i];
		}
		return result;
	}
}
function getChildrenByElement(node)
{
	return getChildren(node, "ELEMENT_NODE");
}
function getFirstChild(node, filter)
{
	var child;
	var children = node.childNodes;
	for(var i = 0; i < children.length; i++)
	{
		child = children[i];
		if(checkNode(child, filter)) return child;
	}
	return null;
}
function getFirstChildByText(node)
{
	return getFirstChild(node, "TEXT_NODE");
}
function getNextSibling(node, filter)
{
	for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling)
	{
		if(checkNode(sibling, filter)) return sibling;
	}
	return null;
}
function getNextSiblingByElement(node)
{
	return getNextSibling(node, "ELEMENT_NODE");
}
var activeMenu = null;

function showMenu()
{
	if(activeMenu)
	{
		activeMenu.className = "";
		getNextSiblingByElement(activeMenu).style.display = "none";
	}
	if(this == activeMenu)
	{
		activeMenu = null;
	}
	else
	{
		this.className = "active";
		getNextSiblingByElement(this).style.display = "block";
		activeMenu = this;
	}
	return false;
}
function initMenu()
{
	var menus, expandmenu, text, a, i;
	menus = getChildrenByElement(document.getElementById("expandmenu"));
	if(menus)
	{
		for(i = 0; i < menus.length; i++)
		{
			menu = menus[i];
			text = getFirstChildByText(menu);
			a = document.createElement("a");
			menu.replaceChild(a, text);
			a.appendChild(text);
			a.href = "#";
			a.onclick = showMenu;
			a.onfocus = function(){this.blur()};
		}
	}
	
}
if(document.createElement) window.onload = initMenu;
/*****************************************************************/
function showBranch(sem,branch1,branch2)
{
	var semister  = document.getElementById(sem).value;
	if(semister >= 3)
	{
		document.getElementById(branch1).style.display='block';
		document.getElementById(branch2).style.display='block';
		
	}
	else
	{
		document.getElementById(branch1).style.display='none';
		document.getElementById(branch2).style.display='none';
	}
}
