function selectUnselectMatchingOptions(obj,regex,which,only){if(window.RegExp){if(which == "select"){var selected1=true;var selected2=false;}else if(which == "unselect"){var selected1=false;var selected2=true;}else{return;}var re = new RegExp(regex);for(var i=0;i<obj.options.length;i++){if(re.test(obj.options[i].text)){obj.options[i].selected = selected1;}else{if(only == true){obj.options[i].selected = selected2;}}}}}
function selectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",false);}
function selectOnlyMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",true);}
function unSelectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"unselect",false);}
function sortSelect(obj){var o = new Array();if(obj.options==null){return;}for(var i=0;i<obj.options.length;i++){o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;}if(o.length==0){return;}o = o.sort(
function(a,b){if((a.text+"") <(b.text+"")){return -1;}if((a.text+"") >(b.text+"")){return 1;}return 0;});for(var i=0;i<o.length;i++){obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);}}
function selectAllOptions(obj){for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}}
function moveSelectedOptions(from,to){if(arguments.length>3){var regex = arguments[3];if(regex != ""){unSelectMatchingOptions(from,regex);}}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){to.options[to.options.length] = new Option( o.text, o.value, false, false);}}for(var i=(from.options.length-1);i>=0;i--){var o = from.options[i];if(o.selected){from.options[i] = null;}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(from);sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function copySelectedOptions(from,to){var options = new Object();for(var i=0;i<to.options.length;i++){options[to.options[i].value] = to.options[i].text;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text){to.options[to.options.length] = new Option( o.text, o.value, false, false);}}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function moveAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){moveSelectedOptions(from,to);}else if(arguments.length==3){moveSelectedOptions(from,to,arguments[2]);}else if(arguments.length==4){moveSelectedOptions(from,to,arguments[2],arguments[3]);}}
function copyAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){copySelectedOptions(from,to);}else if(arguments.length==3){copySelectedOptions(from,to,arguments[2]);}}
function swapOptions(obj,i,j){var o = obj.options;var i_selected = o[i].selected;var j_selected = o[j].selected;var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}
function moveOptionUp(obj){for(i=0;i<obj.options.length;i++){if(obj.options[i].selected){if(i != 0 && !obj.options[i-1].selected){swapOptions(obj,i,i-1);obj.options[i-1].selected = true;}}}}
function moveOptionDown(obj){for(i=obj.options.length-1;i>=0;i--){if(obj.options[i].selected){if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){swapOptions(obj,i,i+1);obj.options[i+1].selected = true;}}}}
function removeSelectedOptions(from){for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected){from.options[i] = null;}}from.selectedIndex = -1;}
function removeAllOptions(from){for(var i=(from.options.length-1);i>=0;i--){from.options[i] = null;}from.selectedIndex = -1;}
function addOption(obj,text,value,selected){if(obj!=null && obj.options!=null){obj.options[obj.options.length] = new Option(text, value, false, selected);}}

addEvent(window,"load",convertTrees);
function addEvent(o,e,f){if(o.addEventListener){o.addEventListener(e,f,true);return true;}else if(o.attachEvent){return o.attachEvent("on"+e,f);}else{return false;}}
function setDefault(name,val){if(typeof(window[name])=="undefined" || window[name]==null){window[name]=val;}}
function expandTree(treeId){var ul = document.getElementById(treeId);if(ul == null){return false;}expandCollapseList(ul,nodeOpenClass);}
function collapseTree(treeId){var ul = document.getElementById(treeId);if(ul == null){return false;}expandCollapseList(ul,nodeClosedClass);}
function expandToItem(treeId,itemId){var ul = document.getElementById(treeId);if(ul == null){return false;}var ret = expandCollapseList(ul,nodeOpenClass,itemId);if(ret){var o = document.getElementById(itemId);if(o.scrollIntoView){o.scrollIntoView(false);}}}
function expandCollapseList(ul,cName,itemId){if(!ul.childNodes || ul.childNodes.length==0){return false;}for(var itemi=0;itemi<ul.childNodes.length;itemi++){var item = ul.childNodes[itemi];if(itemId!=null && item.id==itemId){return true;}if(item.nodeName == "LI"){var subLists = false;for(var sitemi=0;sitemi<item.childNodes.length;sitemi++){var sitem = item.childNodes[sitemi];if(sitem.nodeName=="UL"){subLists = true;var ret = expandCollapseList(sitem,cName,itemId);if(itemId!=null && ret){item.className=cName;return true;}}}if(subLists && itemId==null){item.className = cName;}}}}
function convertTrees(){setDefault("treeClass","mktree");setDefault("nodeClosedClass","liClosed");setDefault("nodeOpenClass","liOpen");setDefault("nodeBulletClass","liBullet");setDefault("nodeLinkClass","bullet");setDefault("preProcessTrees",true);if(preProcessTrees){if(!document.createElement){return;}uls = document.getElementsByTagName("ul");for(var uli=0;uli<uls.length;uli++){var ul=uls[uli];if(ul.nodeName=="UL" && ul.className==treeClass){processList(ul);}}}}
function processList(ul){if(!ul.childNodes || ul.childNodes.length==0){return;}for(var itemi=0;itemi<ul.childNodes.length;itemi++){var item = ul.childNodes[itemi];if(item.nodeName == "LI"){var subLists = false;for(var sitemi=0;sitemi<item.childNodes.length;sitemi++){var sitem = item.childNodes[sitemi];if(sitem.nodeName=="UL"){subLists = true;processList(sitem);}}var s= document.createElement("SPAN");var t= '\u00A0';s.className = nodeLinkClass;if(subLists){if(item.className==null || item.className==""){item.className = nodeClosedClass;}if(item.firstChild.nodeName=="#text"){t = t+item.firstChild.nodeValue;item.removeChild(item.firstChild);}s.onclick = function(){this.parentNode.className =(this.parentNode.className==nodeOpenClass) ? nodeClosedClass : nodeOpenClass;return false;}}else{item.className = nodeBulletClass;s.onclick = function(){return false;}}s.appendChild(document.createTextNode(t));item.insertBefore(s,item.firstChild);}}}
function getScreenRes()
{
    var m_screen_res = screen.width +"x"+ screen.height;
    servlet_page_form.screenres.value = m_screen_res;    
}

function IsNotEmpty(Field, Caption)
{
	if (Field.value == "" || Field.value == null)
	{
		Field.focus();
		return (false);
	}

	return (true);
}

/*function IsEmail(Field, Caption)
{
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@.1234567890ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-~";
var checkStr = Field.value;
var allValid = true;

    allValid =  IsNotEmpty(Field, Caption);
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      }
    }
    if (!allValid)
    {
      Field.focus();
      return false;
   }

	return true;
}*/

function isNotRequiredEmail(field, caption) {

    var email = field.value;
    var atIndex = email.indexOf('@');
    var dotIndex = email.indexOf('.', atIndex);
    
    if (email == null || email == "") return true;

    if (!isnospaces(field, caption) || atIndex < 1 || dotIndex - atIndex < 2) {
        field.focus();
        return false;
    }

    return true;
}

function isRequiredEmail(field, caption) {

    if (!isrequired_alpha(field, caption)) {
        field.focus();
        return false;
    }

    return isNotRequiredEmail(field,caption);
}

function IsInteger(Field, Caption, MinimumValue, MaximumValue)
{
var checkOK = "0123456789-,";
var checkStr = Field.value;
var allValid = true;
var decPoints = 0;
var allNum = "";

	  if (checkStr.length == 0)
	  {
        alert('Please enter only digit characters in the \"' + Caption + '\" field.');
        Field.focus();
        return (false);
	  }

	  for (i = 0;  i < checkStr.length;  i++)
      {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
          if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length)
        {
          allValid = false;
          break;
        }
        if (ch != ",")
          allNum += ch;
      }
      if (!allValid)
      {
        alert('Please enter only digit characters in the \"' + Caption + '\" field.');
        Field.focus();
        return (false);
      }

	  if (MaximumValue > 0)
	  {
		  var chkVal = allNum;
		  var prsVal = parseInt(allNum);

		  if (chkVal != "" && !(prsVal >= MinimumValue && prsVal <= MaximumValue))
		  {
			alert('Please enter a value greater than or equal to \"' + MinimumValue + '\" and less than or equal to \"' + MaximumValue + '\" in the \"' + Caption + '\" field.');
			Field.focus();
			return (false);
		  }
	  }

	  return (true);
}

function IsDecimal(Field, Caption, MinimumValue, MaximumValue)
{
var checkOK = "0123456789-.,";
var checkStr = Field.value;
var allValid = true;
var decPoints = 0;
var allNum = "";

      for (i = 0;  i < checkStr.length;  i++)
      {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
          if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length)
        {
          allValid = false;
          break;
        }
        if (ch != ",")
          allNum += ch;
      }
      if (!allValid)
      {
        alert('Please enter only digit characters in the \"' + Caption + '\" field.');
        Field.focus();
        return (false);
      }

var chkVal = allNum;
var prsVal = parseFloat(allNum);

      if (chkVal != "" && !(prsVal >= MinimumValue && prsVal <= MaximumValue))
      {
        alert('Please enter a value greater than or equal to \"' + MinimumValue + '\" and less than or equal to \"' + MaximumValue + '\" in the \"' + Caption + '\" field.');
        Field.focus();
        return (false);
      }

	  return (true);
}

function isnospaces(Field, m_fieldname)
{
   var m_string = Field.value;
   var m_result = isrequired_alpha(Field, m_fieldname);
   if(!m_result)
     return false;
   for(i=0; i<m_string.length; i++)
   {
        ch = m_string.charAt(i);
        if(ch == ' ' || ch == '' || ch == null)
           return false;
   }
   
   return true;
}

function isrequired_alpha(Field, m_fieldname)
{
   var m_result;
   if(Field.value == "" || Field.value == null)
   {
        Field.focus();
	m_result = false;
   }
   else
        m_result = true;
   return m_result;
}

function isnumeric(Field)
{
   var checkOK = "0123456789";
   var checkStr = Field.value;
   var m_result = true;
   if(Field.value == "" || Field.value == null)
   {
        Field.focus();
	return false;
   }

   try 
   {
        for (i = 0;  i < checkStr.length;  i++) 
        {
            ch = checkStr.charAt(i);
            for(j=0; j<checkOK.length; j++)
            {
                if (ch == checkOK.charAt(j))
                {                     
                     m_result = true;
                     break;
                }
                else
                {                     
                     m_result = false;
                }
            }
            if(m_result == false)
            {                
                return m_result;
            }
        }
   }
   catch(exc)
   {
           m_result = false;           
   }
   return m_result;
}

function radio_onclick(m_pass_primary_values)
{
   servlet_page_form.radioselected.value = m_pass_primary_values;
} 

function radio_onclickMaleFemale(m_pass_primary_values)
{
   servlet_page_form.male_female.value = m_pass_primary_values;
   servlet_page_form.male_female_flag.value = 'true';
} 

function radio_onclickPremiumFree(m_pass_primary_values)
{
   servlet_page_form.premium_or_free.value = m_pass_primary_values;
   servlet_page_form.premium_or_free_flag.value = 'true';
} 

function submitbutton(m_command, m_commandoptions, m_validate)
{
    
   if(m_command == "GETKNOWLEDGEBASE" ||
      m_command == "TASKHISTORY") {

        servlet_page_form.target = "_blank";
   }

   servlet_page_form.command.value = m_command;
   servlet_page_form.target = "";
   servlet_page_form.mustvalidate.value = m_validate;     
   var msg = 'Are you sure you want to delete this record';

   

   if(m_command == "INSERTSTATUS")
   {
        if(servlet_page_form.task_status.value.length > 10)
        {
            alert('Task Status field is longer than 10 characters, data will be truncated');           
        }
   }

   /* gets all tasktypeknowledgebase items */
   if(m_command == "INSERTTASKTYPE" || m_command == "UPDATETASKTYPE")
   {
     getKnowledgebaseTasktypeBoxItems();    
     getSkillsBoxItems();
   }

   if(m_command == "INSERTAGENT" || m_command == "UPDATEAGENT")
   {
         try
         {checkdates();}
         catch(e){}
         getAgentSkillsBoxItems();
   }
   
/*   if(m_command == "GOSUBTASKTYPE")
   {
        getStatiiBoxItems();
        getTaskTypeBoxItems();
        getCustomerBoxItems();
        getAgentBoxItems();
   }

   if(m_command == "GOVIEWALLTASKS") {

        getsubtasktypelistboxitems();
   } */

   if (m_command == "GOCUSTOMERVIEWTASKS" || m_command == "GOAGENTVIEWTASKS" || m_command == "GOVIEWALLTASKS"
        || m_command == "GOVIEWTASKSTATS") {

       var subTypeArr = document.getElementsByName("flickaccrosssubtasktype");

       if (subTypeArr.length > 0) {
            getsubtasktypelistboxitems();
       } else {
           getStatiiBoxItems();
           getTaskTypeBoxItems();
           if (m_command != "GOCUSTOMERVIEWTASKS") {
                /*getCustomerBoxItems();*/
                /* Agent box items may not be present. */
                try {
                    getAgentBoxItems();
                } catch (exc) {}
           }
       }
   }
   

   /* FRAMEWORK DELETE PROMPTS */
   /****************************/
   if(m_command == "DELETEINTERNALUSER")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tinternaluser|dooperations=true";
        }        
   }

   if(m_command == "DELETEINTERNALUSERGROUP")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tinternalusergroup|dooperations=true";
        }        
   }

   if(m_command == "DELETECURRENCY")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tcurrency|dooperations=true";
        }        
   }

   if(m_command == "DELETECOUNTRY")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tcountry|dooperations=true";
        }        
   }

   if(m_command == "DELETEINTERNALMENU")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tinternalmenu|dooperations=true";
        }        
   }

   if(m_command == "DELETEGRID")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tgridproperties|dooperations=true";
        }        
   }

   /* APPLICATION DELETE PROMPTS */
   /******************************/
   if(m_command == "DELETECUSTOMERTYPE")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tcustomertype|dooperations=true";
        }        
   }

   if(m_command == "DELETESKILL")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tskills|dooperations=true";
        }        
   }

   if(m_command == "DELETELOCATION")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tlocation|dooperations=true";
        }        
   }

   if(m_command == "DELETEKNOWLEDGEBASE_CAT")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tknowledgebase_cat|dooperations=true";
        }        
   }

   if(m_command == "DELETEKNOWLEDGEBASE")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tknowledgebase|dooperations=true";
        }        
   }

   if(m_command == "DELETESTATUS")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tstatus|dooperations=true";
        }        
   }

   if(m_command == "DELETECUSTOMER")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tcustomer|dooperations=true";
        }        
   }

   if(m_command == "DELETETHIRDPARTY")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tthirdparty|dooperations=true";
        }        
   }

   if(m_command == "DELETETASKTYPE")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=ttasktype|dooperations=true";
        }        
   }

   if(m_command == "DELETEAGENT")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tagent|dooperations=true";
        }        
   }
   
   if(m_command == "DELETEACCOUNT")
   {   
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "ACCOUNTFILTER";
               /*servlet_page_form.commandoptions.value = "gridname=taccount|dooperations=true";*/
        }        
   }

   if(m_command == "ACCOUNTRESETTRIAL")
   {
        promptscript=confirm("WARNING! If you reset an account that has performed a backup, the backup will be lost. Are you sure you want to reset this account?");
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "ACCOUNTFILTER";
               /*servlet_page_form.commandoptions.value = "gridname=taccount|dooperations=true";*/
        }
   }

   if(m_command == "DELETESYSEMAIL")
   {
        promptscript=confirm(msg);
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tsysemail|dooperations=true";
        }
   }

   if(m_command == "COMPLETEDEBITORDER")
   {
        promptscript=confirm("Are you sure you want to complete this debit order?");
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "grid";
               servlet_page_form.commandoptions.value = "gridname=tdebitorderheader|dooperations=true";
        }
   }
  
   if(m_command == "UPDATEBASEAMOUNTS")
   {
        promptscript=confirm("Are you sure you want to update base amounts?");
        if(promptscript == false)
        {
               servlet_page_form.validationcompleted.value = 'false';
               servlet_page_form.command.value = "parentmenu";
               servlet_page_form.commandoptions.value = "700";
        }
   }
  
   if (m_command == "TESTGRID" || m_command == "FILEUPLOAD" || m_command == "TASKHISTORY" ||
       m_command == "RECORDPICK") {
        servlet_page_form.target = "blank";
        servlet_page_form.commandoptions.value = m_commandoptions;
   }

   if (m_command == "GOAGENTVIEWTASKS" || m_command == "GOCUSTOMERVIEWTASKS" || m_command == "GOVIEWALLTASKS" || m_command == "GOVIEWTASKSTATS") {

        var arr = document.getElementsByName("selectsubtasktype");
        if (arr.length > 0 && arr[0].checked) {

        } else if (servlet_page_form.format.value == "HTML" || servlet_page_form.format.value == "EXCEL" || servlet_page_form.format.value == "GRAPH") {
            
            servlet_page_form.target = "blank";
        }
   }

   if(m_validate == "true")
   { 
            var m_result = validateForm();
            servlet_page_form.validationcompleted.value = m_result; 
   }
  else
            servlet_page_form.validationcompleted.value = "true";
    

   if(m_command == "parentmenu" || m_command == "home")
        servlet_page_form.parentmenuid.value = m_commandoptions;      
   

   if(m_command == "grid" || m_command == "cancelgrid" || m_command == "first" || m_command == "prev" || m_command == "next" || m_command == "last" || m_command == "go" || m_command == "resetfilter" || m_command == "RECORDPICK")
        servlet_page_form.commandoptions.value = m_commandoptions;
   
   if(m_command == "resetfilter")
        servlet_page_form.filterclause.value = "";  

   if (m_command == 'PERFORMDEBITORDERREPORT' || m_command == 'PERFORMDEBITORDERDEALERREPORT' || m_command == 'PERFORMRESTORELOGREPORT' || m_command == 'ACCOUNTCSV' || m_command == 'PERFORMRESTORELOGREPORT' || m_command == 'PREVIEWINVOICE') {
        servlet_page_form.target = "_blank";
   }

}

function changeButtonColour(theObject)
{
    theObject.className = "Button1";
}

function changeButtonColourBack(theObject)
{
    theObject.className = "Button";
}

function changeWorkspaceButtonColour(theObject)
{
    theObject.className = "WorkspaceButton1";
}

function changeWorkspaceButtonColourBack(theObject)
{
    theObject.className = "WorkspaceButton";
}

function changeChildButtonColour(theObject)
{
    theObject.className = "ChildButton1";
}

function changeChildButtonColourBack(theObject)
{
    theObject.className = "ChildButton";
}

function changeExplorerButtonColour(theObject)
{
    theObject.className = "ExplorerFilterButtonAlternate";
}

function changeExplorerButtonColourBack(theObject)
{
    theObject.className = "ExplorerFilterButton";
}

function getKnowledgebaseTasktypeBoxItems()
{
   var int_counter = servlet_page_form.tasktype_selectedlist.length;
   var intIndex;
   servlet_page_form.tasktypeselectedlist.value = "";
   try
   {
       for (intIndex = 0; intIndex < int_counter; )
       {
          servlet_page_form.tasktypeselectedlist.value = servlet_page_form.tasktypeselectedlist.value + '\'' + servlet_page_form.tasktype_selectedlist.options[intIndex].value + '\'' + ",";
          intIndex++;
       }
   }
   catch(e){}
}

function getSkillsBoxItems()
{
   var int_counter = servlet_page_form.skill_selectedlist.length;
   var intIndex;
   servlet_page_form.skillselectedlist.value = "";
   try
   {
       for (intIndex = 0; intIndex < int_counter; )
       {
          servlet_page_form.skillselectedlist.value = servlet_page_form.skillselectedlist.value + '\'' + servlet_page_form.skill_selectedlist.options[intIndex].value + '\'' + ",";
          intIndex++;
       }
   }
   catch(e){}
}

function getAgentSkillsBoxItems()
{
   var int_counter = servlet_page_form.agentskill_selectedlist.length;
   var intIndex;
   servlet_page_form.agentskillselectedlist.value = "";
   try
   {
       for (intIndex = 0; intIndex < int_counter; )
       {
          servlet_page_form.agentskillselectedlist.value = servlet_page_form.agentskillselectedlist.value + '\'' + servlet_page_form.agentskill_selectedlist.options[intIndex].value + '\'' + ",";
          intIndex++;
       }
   }
   catch(e){}
}

function getStatiiBoxItems() {

   var int_counter = servlet_page_form.status_selectedlist.length;
   servlet_page_form.statusselectedlist.value = "";

   for (var intIndex = 0; intIndex < int_counter; intIndex++) {
      servlet_page_form.statusselectedlist.value = servlet_page_form.statusselectedlist.value + servlet_page_form.status_selectedlist.options[intIndex].value + ',';
   }

}

function getTaskTypeBoxItems() {

   var int_counter = servlet_page_form.tasktype_selectedlist.length;
   servlet_page_form.tasktypeselectedlist.value = "";

   for (var intIndex = 0; intIndex < int_counter; intIndex++) {
      servlet_page_form.tasktypeselectedlist.value = servlet_page_form.tasktypeselectedlist.value + servlet_page_form.tasktype_selectedlist.options[intIndex].value + ',';
   }

}

function getCustomerBoxItems()
{
   var int_counter = servlet_page_form.customer_selectedlist.length;
   servlet_page_form.customerselectedlist.value = "";

   for (var intIndex = 0; intIndex < int_counter; intIndex++) {
      servlet_page_form.customerselectedlist.value = servlet_page_form.customerselectedlist.value + servlet_page_form.customer_selectedlist.options[intIndex].value + ',';
   }
}

function getAgentBoxItems()
{
   var int_counter = servlet_page_form.agent_selectedlist.length;
   servlet_page_form.agentselectedlist.value = "";

   for (var intIndex = 0; intIndex < int_counter; intIndex++) {
      servlet_page_form.agentselectedlist.value = servlet_page_form.agentselectedlist.value + servlet_page_form.agent_selectedlist.options[intIndex].value + ',';
   }
}

function checkdates()
{
    var m_month1 = servlet_page_form.out_of_office_from.value.substring(3,5);
    var m_month2 = servlet_page_form.out_of_office_to.value.substring(3,5); 
    var m_day1 = servlet_page_form.out_of_office_from.value.substring(0,2);
    var m_day2 = servlet_page_form.out_of_office_to.value.substring(0,2);
    var m_year1 = servlet_page_form.out_of_office_from.value.substring(6,10); 
    var m_year2 = servlet_page_form.out_of_office_to.value.substring(6,10); 
    m_result = true;

    if(m_year2 < m_year1) 
    {
        alert('\'Out of office to\' year may not be less than \'Out of office from\' year');
        m_result = 'false';
    }
    
    if(m_month2 < m_month1)
    {
        if(m_year1 == m_year2)
        {
            alert('\'Out of office to\' month may not be less than \'Out of office from\' month');         
            m_result = 'false';
        }
    } 

    if(m_day2 < m_day1)
    {
        if(m_month2 <= m_month1)
        {
            if(m_year1 == m_year2)
            {
                alert('\'Out of office to\' day may not be less than \'Out of office from\' day');
                m_result = 'false';
             }
        }
    }
    if(m_result == 'false')
    {
        servlet_page_form.out_of_office_from.value = "";
        servlet_page_form.out_of_office_to.value = "";
    }
    
}

function popupFileUpload(uri) {

    window.open(uri, '_blank', 'directories=no, location=no, menubar=no, resizable=no, toolbar=no');

}

function isurl(Field, m_fieldname ) {

  var m_url = Field.value; 
  if(m_url.substring(0,7) != "http://") {

        var m_urlprefix = "http://";
        Field.value = m_urlprefix + m_url;
  }
  
}

function checkfileattachment() {

    servlet_page_form.attachment_file_name_btn.disabled = false;
    alert('Upload a file'); 
    servlet_page_form.existing_file_url.value = "";
    servlet_page_form.existing_file_url.disabled = true;        
}

function checkfileexisting() {

    servlet_page_form.existing_file_url.disabled = false;
    alert('Enter the url to an existing resource\nThe url must conform to the following format (eg: http://www.mysite.com/resource.html)');
    servlet_page_form.attachment_file_name.value = "";
    servlet_page_form.attachment_file_name_btn.disabled = true; 
}

function checkfilenone() {

    alert('You have selected not to attach a resource document to this Knowledgebase');
    servlet_page_form.existing_file_url.value = "";
    servlet_page_form.existing_file_url.disabled = true;  
    servlet_page_form.attachment_file_name.value = "";
    servlet_page_form.attachment_file_name_btn.disabled = true; 

}

function isinternational_mobile() {

    var m_mobile = servlet_page_form.usermobile.value;
    if(m_mobile != "" || m_mobile != null) {

        var m_msg = "The Mobile Number must conform to International format\n No \'+\' signs are allowed. No spaces are allowed\nEg: 082 000 0000 must read 27820000000 for it to be a valid mobile number\nShould this number be incorrect you can edit it later\nAny sms's sent using an invalid number will not be delivered\nAre you sure this is the number you want to use";
        m_promptscript=confirm(m_msg);
        if(m_promptscript == false) {

            servlet_page_form.usermobile.focus();
            return false;
        }
        return true;

    } else {
        
        return false;
    }
}

function isvalidtime(Field, Caption) {
    
    var checkOK = "0123456789";
    var checkStr = Field.value;
    
    var allValid = true;
    var decPoints = 0;
    var allNum = "";

      if(checkStr.length == 0) {
        allValid = false;
      }
      
      for (i = 0;  i < checkStr.length;  i++)
      {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
          if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length)
        {
          allValid = false;
          break;
        }
        if (ch != ",")
          allNum += ch;
      }

      if (!allValid)
      {
        alert('Please enter only digit characters in the Time Taken Field\nOnly whole numbers are allowed');
        Field.focus();
        return allValid;
      }
      return allValid;       
}

function saveFlickAcross(name) {

    var selectedList = document.getElementsByName(name + "_selected")[0];
    var value = "";

    var index = 0;
    var size = selectedList.options.length;

    while (index < size) {

        value += selectedList.options[index].value;

        index++;
        if (index < size) {
            value += ",";
        }
    }

    document.getElementsByName(name)[0].value = value;
}
