//a repository of checkbox functions
//Author: Adenowun Oladipupo
//upload checkbox functions start
function boxChecker()
{
	var stat = document.upForm.atchFrmID.length;
  if (stat == undefined)
   {
		if ((document.upForm.atchFrmID.checked == false) && (document.upForm.reqFiles.value != "") )
    	{
    		document.upForm.atchFrmID.checked = true;
    	}
   }
  else
  {
    for (var i=0;i<document.upForm.elements.length;i++)
    {
    	if ((document.upForm.atchFrmID[i].checked == false) && (document.upForm.reqFiles[i].value != "") )
    	{
    		document.upForm.atchFrmID[i].checked = true;
    	}
    }
  }

}
function checkAllU()
{
	var stat = document.upForm.frmDelete.length;
    if (stat == undefined)
    {
    	document.upForm.frmDelete.checked = true;
    }
    else
    {
	for (var i=0;i<document.upForm.elements.length;i++)
    {

    		document.upForm.frmDelete[i].checked = true;
    }
    }
}
function unCheckAllU()
{
	var stat = document.upForm.frmDelete.length;
    if (stat == undefined)
    {
    	document.upForm.frmDelete.checked = false;
    }
    else
    {
	for (var i=0;i<document.upForm.elements.length;i++)
    {

    		document.upForm.frmDelete[i].checked = false;
    }
    }
}
//upload checkbox functions ends


function boxCheck()
{
	var stat = document.forms[0].licID.length;
	if (stat == undefined)
	{
      if ((document.forms[0].licType.checked == false) && (document.forms[0].licID.checked == true))
    	{
    		document.forms[0].licType.checked = true;
    	}
    	if ((document.forms[0].licType.checked == true) && (document.forms[0].licID.checked == false))
    	{
    		document.forms[0].licType.checked = false;
    	}
	}
 else
  {
	var status = document.forms[0].licID.length;
    for (var i=0;i<status;i++)
    {
    	if ((document.forms[0].licType[i].checked == false) && (document.forms[0].licID[i].checked == true))
    	{
    		document.forms[0].licType[i].checked = true;
    	}
    	if ((document.forms[0].licType[i].checked == true) && (document.forms[0].licID[i].checked == false))
    	{
    		document.forms[0].licType[i].checked = false;
    	}
    }
   }
}
function checkAll()
{
	var stat = document.forms[0].myLicID.length;
	if (stat == undefined)
	{
		document.forms[0].myLicID.checked = true;
    	//document.forms[0].licType.checked = true;
	}
   else
   {
	var status = document.forms[0].myLicID.length;
	for (var i=0;i<status;i++)
    {
    		document.forms[0].myLicID[i].checked = true;
    		//document.forms[0].licType[i].checked = true;
    }
   }
}
function unCheckAll()
{
	var stat = document.forms[0].myLicID.length;
	if (stat == undefined)
	{
		document.forms[0].myLicID.checked = false;
    	//document.forms[0].licType.checked = false;
	}
   else
   {
	var status = document.forms[0].myLicID.length;
	for (var i=0;i<status;i++)
    {
    		document.forms[0].myLicID[i].checked = false;
    		//document.forms[0].licType[i].checked = false;
    }
   }
}

function boxCheckString()
{
 var stat = document.forms[0].strID.length;
 if (stat >= 4)
 //if (stat == undefined)
	{
       if ((document.forms[0].strCol.checked == false) && (document.forms[0].strID.value != 0))
    	{
    		document.forms[0].strCol.checked = true;
    	}
    	if ((document.forms[0].strCol.checked == true) && (document.forms[0].strID.value == 0))
    	{
    		document.forms[0].strCol.checked = false;
    	}
    	//for description
    	if ((document.forms[0].strCold.checked == false) && (document.forms[0].strID.value != 0))
    	{
    		document.forms[0].strCold.checked = true;
    	}
    	if ((document.forms[0].strCold.checked == true) && (document.forms[0].strID.value == 0))
    	{
    		document.forms[0].strCold.checked = false;
    	}
	}
  else
  {
	var status = document.forms[0].strID.length;
    for (var i=0;i<status;i++)
    {
    	if ((document.forms[0].strCol[i].checked == false) && (document.forms[0].strID[i].value != 0))
    	{
    		document.forms[0].strCol[i].checked = true;
    	}
    	if ((document.forms[0].strCol[i].checked == true) && (document.forms[0].strID[i].value == 0))
    	{
    		document.forms[0].strCol[i].checked = false;
    	}
    	//for description
    	if ((document.forms[0].strCold[i].checked == false) && (document.forms[0].strID[i].value != 0))
    	{
    		document.forms[0].strCold[i].checked = true;
    	}
    	if ((document.forms[0].strCold[i].checked == true) && (document.forms[0].strID[i].value == 0))
    	{
    		document.forms[0].strCold[i].checked = false;
    	}
    }
 }
}

function boxCheckNumber()
{
	var stat = document.forms[0].numID.length;
if (stat >= 4)
 //if (stat == undefined)
	{
       if ((document.forms[0].numCol.checked == false) && (document.forms[0].numID.value != 0))
    	{
    		document.forms[0].numCol.checked = true;
    	}
    	if ((document.forms[0].numCol.checked == true) && (document.forms[0].numID.value == 0))
    	{
    		document.forms[0].numCol.checked = false;
    	}
    	//for description
        if ((document.forms[0].numCold.checked == false) && (document.forms[0].numID.value != 0))
    	{
    		document.forms[0].numCold.checked = true;
    	}
    	if ((document.forms[0].numCold.checked == true) && (document.forms[0].numID.value == 0))
    	{
    		document.forms[0].numCold.checked = false;
    	}
	}
  else
  {
	var status = document.forms[0].numID.length;
    for (var i=0;i<status;i++)
    {
    	if ((document.forms[0].numCol[i].checked == false) && (document.forms[0].numID[i].value != 0))
    	{
    		document.forms[0].numCol[i].checked = true;
    	}
    	if ((document.forms[0].numCol[i].checked == true) && (document.forms[0].numID[i].value == 0))
    	{
    		document.forms[0].numCol[i].checked = false;
    	}
    	//for description
    	if ((document.forms[0].numCold[i].checked == false) && (document.forms[0].numID[i].value != 0))
    	{
    		document.forms[0].numCold[i].checked = true;
    	}
    	if ((document.forms[0].numCold[i].checked == true) && (document.forms[0].numID[i].value == 0))
    	{
    		document.forms[0].numCold[i].checked = false;
    	}
    }
 }
}

function boxCheckDate()
{
	var stat = document.forms[0].dateID.length;
 if (stat >= 4)
 //if (stat == undefined)
	{
       if ((document.forms[0].dateCol.checked == false) && (document.forms[0].dateID.value != 0))
    	{
    		document.forms[0].dateCol.checked = true;
    	}
    	if ((document.forms[0].dateCol.checked == true) && (document.forms[0].dateID.value == 0))
    	{
    		document.forms[0].dateCol.checked = false;
    	}
    	//for description
       if ((document.forms[0].dateCold.checked == false) && (document.forms[0].dateID.value != 0))
    	{
    		document.forms[0].dateCold.checked = true;
    	}
    	if ((document.forms[0].dateCold.checked == true) && (document.forms[0].dateID.value == 0))
    	{
    		document.forms[0].dateCold.checked = false;
    	}

	}
  else
  {
	var status = document.forms[0].dateID.length;
    for (var i=0;i<status;i++)
    {
    	if ((document.forms[0].dateCol[i].checked == false) && (document.forms[0].dateID[i].value != 0))
    	{
    		document.forms[0].dateCol[i].checked = true;
    		document.forms[0].dateText[i].value = i;
    	}
    	if ((document.forms[0].dateCol[i].checked == true) && (document.forms[0].dateID[i].value == 0))
    	{
    		document.forms[0].dateCol[i].checked = false;
    		document.forms[0].dateText[i].value = "";
    	}
    	//for description
    	if ((document.forms[0].dateCold[i].checked == false) && (document.forms[0].dateID[i].value != 0))
    	{
    		document.forms[0].dateCold[i].checked = true;
    		document.forms[0].dateText[i].value = i;
    	}
    	if ((document.forms[0].dateCold[i].checked == true) && (document.forms[0].dateID[i].value == 0))
    	{
    		document.forms[0].dateCold[i].checked = false;
    		document.forms[0].dateText[i].value = "";
    	}
    }
 }

}

function checkMandatory()
{
    var errMsg = "";
  if (document.forms[0].strMan != undefined)
  {
    var strstat = document.forms[0].strMan.length;
   if (strstat == undefined)
   {
   	//if ((document.forms[0].strMan.value == 1) && (document.forms[0].strID.value == 0) || (document.forms[0].strText.value == ""))
   	if ((document.forms[0].strMan.value == 1) &&  (document.forms[0].strText.value == ""))
    	{
    		errMsg += document.forms[0].strCold.value+" is mandatory! \n";
    	}
   }
   else
   {
   	for (var i=0;i<strstat;i++)
    {
    	//if ((document.forms[0].strMan[i].value == 1) && (document.forms[0].strID[i].value == 0) || (document.forms[0].strText[i].value == ""))
    	if ((document.forms[0].strMan[i].value == 1) && (document.forms[0].strText[i].value == ""))
    	{
    		errMsg += document.forms[0].strCold[i].value+" is mandatory! \n";
    	}
    }
   }
  }
  //number Section
  if (document.forms[0].numMan != undefined)
  {
  var numstat = document.forms[0].numMan.length;
   if (numstat == undefined)
   {
   	//if ((document.forms[0].numMan.value == 1) && (document.forms[0].numID.value == 0) && (document.forms[0].numText.value == ""))
   	if ((document.forms[0].numMan.value == 1) && (document.forms[0].numText.value == ""))
    	{
    		errMsg += document.forms[0].numCold.value+" is mandatory! \n";
    	}
   }
   else
   {
   	for (var i=0;i<numstat;i++)
    {
    	//if ((document.forms[0].numMan[i].value == 1) && (document.forms[0].numID[i].value == 0) && (document.forms[0].numText[i].value == ""))
    	if ((document.forms[0].numMan[i].value == 1) && (document.forms[0].numText[i].value == ""))
    	{
    		errMsg += document.forms[0].numCold[i].value+" is mandatory! \n";
    	}
    }
   }
  }
 //Date Section
  if (document.forms[0].dateMan != undefined)
  {
  var datestat = document.forms[0].dateMan.length;
   if (datestat == undefined)
   {
   	//if ((document.forms[0].numMan.value == 1) && (document.forms[0].numID.value == 0) && (document.forms[0].numText.value == ""))
   	if ((document.forms[0].dateMan.value == 1) && (document.forms[0].dateID.value == 0))
    	{
    		errMsg += document.forms[0].dateCold.value+" is mandatory! \n";
    	}
   }
   else
   {
   	for (var i=0;i<numstat;i++)
    {
    	//if ((document.forms[0].numMan[i].value == 1) && (document.forms[0].numID[i].value == 0) && (document.forms[0].numText[i].value == ""))
    	if ((document.forms[0].dateMan[i].value == 1) && (document.forms[0].dateID[i].value == 0))
    	{
    		errMsg += document.forms[0].dateCold[i].value+" is mandatory! \n";
    	}
    }
   }
  }

   if (errMsg != "")
    {
      var theMsg = "The following error(s) occured: \n" + errMsg + " Please correct to continue!";
      alert(theMsg);
      return false;
    }
    else
    {
      return true;
    }
}

function doReload()
{
	document.forms[0].subApp.value = "yes";
	document.forms[0].passedApp.value = document.forms[0].sec_reg_no.value;
	document.forms[0].submit();
}