// trim functions
function lTrim(s) { return s.replace(/^\s+/g,''); }
function rTrim(s) { return s.replace(/\s+$/g,''); }
function trim(s) { return rTrim(lTrim(s)); }

//text field validation

function FormValidate(lst, lstnames)
{
        var lstarray1 = lst.split(",");
        var lstarray2 = lstnames.split(",");
        for(i=0;i<=lstarray1.length-1; i++ )
        {
                if(trim(document.getElementById(lstarray1[i]).value) == "" )
                {
                        alert ("Please enter value in" + " " + lstarray2[i] + " " + "field.");
                        return (false);
                }

        }


        return (true);
}

function captchaValidate ()
		{	captcha = jcap();
		if ( captcha  ) {
						document.getElementById('subscribeform').secret_word.value = "you_may_pass";
		}
		else 
		{				alert("please enter the word you see in the box"); return (false);
		}
		}

// check match password
function PassValidate(pwd1, pwd2)
{
        var pass1 = trim(document.getElementById(pwd1).value);
        var pass2 = trim(document.getElementById(pwd2).value);
	if (pass1 != pass2)
        {
                alert ("Confirm Password field doesn't match.");
                return (false);
        }
        else
        {
                return(true);
        }
}

//dropdown validation

function DropValidate(dd,ddisplay)
{
        var lstarray1 = dd.split(",");
        var lstarray2 = ddisplay.split(",");
        var flag=0;

         for(i=0;i<=lstarray1.length-1; i++ )
        {
                if(document.getElementById(lstarray1[i]).selectedIndex == '' )
                {
                        alert ("Please select " + " " + lstarray2[i]);
                        flag=1;
                        return (false);
                }
        }
                if(!flag) return(true);

}

// check the character count for SMS messsages

function char_count(msg_sms)
{
     msgobj=document.getElementById(msg_sms);
     var count=msgobj.value.length;
     if (count > 160)
     {
          alert ('Message can not be longer than 160 characters for sending SMS.');
          return (false);
     }
     else
     {
        return (true);
     }
}

function RadioValidate(rb, msg)
{
        var lstarray = rb.split(",");

        for (j=0;j<lstarray.length;j++)
        {

                var obj1 = document.getElementsByName(lstarray[j]);

                for (var i = 0; i < obj1.length; i++)
                {
                        if (obj1[i].checked)
                        {
                                break;
                        }
                }

                if ( i >= obj1.length)
                {
                        alert (msg);
                        return (false);
                }


        }
        return(true);
}

//used to edit adjuster information

function ShowForm(hideid, showid)
{
	/*
	ele_obj1=document.getElementById(hideid);
	ele_obj2=document.getElementById(showid);

	if(ele_obj1.style.display == '')
		ele_obj1.style.display = 'none';
	else
		ele_obj1.style.display = '';
	*/

        var hidearr = hideid.split(",");
        var showarr = showid.split(",");

	if(document.getElementById(hidearr[0]).style.display=='')
	{
          for(i=0;i<=hidearr.length-1; i++ )
          {
		document.getElementById(hidearr[i]).style.display = 'none';
		document.getElementById(showarr[i]).style.display = '';
          }
          return (true);
	}
        if(document.getElementById(hidearr[0]).style.display=='none')
        {
          for(i=0;i<=hidearr.length-1; i++ )
          {
                document.getElementById(hidearr[i]).style.display = '';
                document.getElementById(showarr[i]).style.display = 'none';
          }
          return (true);
        }
}

// used for payroll processing

function CheckTotal(lst, tot)
{
        var lstarray1 = lst.split(",");
	var total = 0;
        for(i=0;i<=lstarray1.length-1; i++ )
        {
		var chk = document.getElementById(lstarray1[i]).value;
		total = parseInt(total) + parseInt(chk);
	}
	if(total!=parseInt(tot))
	{
		alert("Check total does not match with the total amount.");
		return false;
	}
		
        else return (true);
}


function LimitAttach(form, file,msg)
{
        allowSubmit = true;
        if (!file)
                allowSubmit = false;
        /*while (file.indexOf('\') != -1)
        file = file.slice(file.indexOf('\') + 1);
        ext = file.slice(file.indexOf('.')).toLowerCase();
        for (var i = 0; i < extArray.length; i++)
        {
                if (extArray[i] == ext) { allowSubmit = true; break; }
        }*/
        if (allowSubmit) form.submit();
        else
        {
                alert(msg);
                return false;
        }
}


