﻿// JScript File
//Written By: Varghese John
//Date :8-sep-2006
function vallogin()
{
document.getElementById("Login1_lblerror").innerHTML="";
//purpose checking the login section in public web page
if(trim(document.forms[0].Login1$txtuname.value)=="")
{
document.getElementById("Login1_lblerror").innerHTML="Please Enter User Name";
//alert("Please Enter User Name ");
document.forms[0].Login1$txtuname.focus();
return false;
}
if(trim(document.forms[0].Login1$txtpass.value)=="")
{
document.getElementById("Login1_lblerror").innerHTML="Please Enter Password";
//alert("Please Enter Password ");
document.forms[0].Login1$txtpass.focus();
return false;
}
return true;
}
function ltrim(string)
{
string=new String(string);
var string1=new Array();
var i,j;
for(i=0,j=0;i<string.length;i++)
{
if(j==0)
{
if(string.charAt(i)!=" ")
{
string1[j++]=string.charAt(i);
}
}
else
{
string1[j++]=string.charAt(i);
}

}
string="";
for(i=0;i<string1.length;i++)
{
string+=string1[i];
}
return string;
}

//This function is to eliminate the trailing spaces in a string.
function rtrim(string)
{
string=new String(string);
var string1=new Array();
var i,j;
for(i=string.length;i>=0;i--)
{
if(string.charAt(i-1)==" ")
{
continue;
}
else
{
for(j=0;j<i;j++)
{
string1[j]=string.charAt(j);
}
break;
}

}
string="";
for(i=0;i<string1.length;i++)
{
string+=string1[i];
}


return string;
}
//This function combines the above two functions to elimnate the leading and trailing spaces from the string
function trim(string)
{
string=ltrim(string); // // This function is used to trim the left side of a String
string=rtrim(string);// This function is used to trim the right side of a String
return string;
}




function checkchar(val)
{
var flag=0;
var str ;

str = val;
var Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
for (var i = 0; i < str.length; i++)
{
if (Chars.indexOf(str.charAt(i)) == -1)
{
flag=1;
}
}

if(flag==1)
{
return false;
}
else
{
return true;
}
}




function valemailfn()
{
    document.getElementById("lblerr").innerHTML="";
    if(document.forms[0].chknews.checked==false && document.forms[0].chkevents.checked==false)
    {
        document.getElementById("lblerr").innerHTML="Please Check any one announcement";
        return false;
    }

    else if(trim(document.forms[0].txtfname.value)=="")
    {
        document.getElementById("lblerr").innerHTML="Please Enter First Name";
        document.forms[0].txtfname.focus();
        return false;
    }
    else if(trim(document.forms[0].txtlname.value)=="")
    {
        document.getElementById("lblerr").innerHTML="Please Enter Last Name";
        document.forms[0].txtlname.focus();
        return false;
    }
    else if(trim(document.forms[0].txtemail.value)=="")
    {
        document.getElementById("lblerr").innerHTML="Please Enter Email Address";
        document.forms[0].txtemail.focus();
        return false;
    }

    else if(checkemail(document.forms[0].txtMail.value)!=true)
    {
        document.getElementById("lblerr").innerHTML="Please Enter Valid Email Address";
        document.forms[0].txtMail.focus();
        return false;
    }
    return true;
}

function checkemail(val)
{
    var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
    if(!email.test(val))
        return false;
    else
        return true;
}


function check_Help()
{

        if(trim(document.forms[0].txtName.value)=="")
        {
            document.getElementById("sp").innerHTML="Please enter Name";
            document.forms[0].txtName.focus();
            return false;
        }
        else if(trim(document.forms[0].txtstreet.value)=="")
        {
            document.getElementById("sp").innerHTML="Please enter Street";
            document.forms[0].txtstreet.focus();
            return false;

        }
        else if(trim(document.forms[0].txtCity.value)=="")
        {
            document.getElementById("sp").innerHTML="Please enter City";
            document.forms[0].txtCity.focus();
            return false;

        }
        else if(checkchar(trim(document.forms[0].txtCity.value))==false)
        {
            document.getElementById("sp").innerHTML="Numbers not allowed in City";
            document.forms[0].txtCity.focus();
            return false;

        }
        else if(trim(document.forms[0].txtPin.value)=="")
        {
            document.getElementById("sp").innerHTML="Please Enter Pin/Zip";
            document.forms[0].txtPin.focus();
            return false;

        }
        else if(checkpin(trim(document.forms[0].txtPin.value))!=true)
        {
            document.getElementById("sp").innerHTML="Please Enter Valid Pin/Zip";
            document.forms[0].txtPin.focus();
            return false;

        }
        else if(document.forms[0].txtTelephone.value=="")
        {
            document.getElementById("sp").innerHTML="Please Enter Telephone Number";
            document.forms[0].txtTelephone.focus();
            return false;
        }
        else if(checkphone(document.forms[0].txtTelephone.value)!=true)
        {
            document.getElementById("sp").innerHTML="Please Enter Valid Telephone Number";
            document.forms[0].txtTelephone.focus();
            return false;

        }
        else if(trim(document.forms[0].txtMail.value)=="")
        {
            document.getElementById("sp").innerHTML="Please enter Email-Id";
            document.forms[0].txtMail.focus();
            return false;

        }
        else if(checkemail(document.forms[0].txtMail.value)!=true)
        {
            document.getElementById("sp").innerHTML="Please Enter Valid Email Address";
            document.forms[0].txtMail.focus();
            return false;

        }
        else if(trim(document.forms[0].txtQuery.value)=="")
        {
            document.getElementById("sp").innerHTML="Please enter Subject";
            document.forms[0].txtQuery.focus();
            return false;

        }
        else if(trim(document.forms[0].txtQueryDetails.value)=="")
        {
            document.getElementById("sp").innerHTML="Please enter Details";
            document.forms[0].txtQueryDetails.focus();
            return false;

        }

        return true;
}

function checkformatpin1(val)
{
    var flag=0;
    var str ;
    str = val;
    var Chars = "0123456789-";
    for (var i = 0; i < str.length; i++)
    {
        if (Chars.indexOf(str.charAt(i)) == -1)
         flag=1;
    }

    if(flag==1)
        return false;
    else
     return true;
}
function checknum(val)
{
    var flag=0;
    var str ;
    str = val;
    var Chars = "0123456789";
    for (var i = 0; i < str.length; i++)
    {
        if (Chars.indexOf(str.charAt(i)) == -1)
         flag=1;
    }

    if(flag==1)
        return false;
    else
     return true;
}
function checkformatpin2(val)
{
    arr=val.split("-");
    if(arr.length != 2 || arr[0].length !=5 || arr[1].length !=4)
        return false;
    return true;
}
function checkpin(val)
{
    if(checkformatpin1(val)==false)
        return false;
    if(val.length > 5)
    {
        if(checkformatpin2(val)==false)
            return false;
    }
    if(val.length==5)
        if(checknum(val)==false)
            return false;
    
    if(val.length < 5)
        return false;
    return true;
}

function checkphone(val)
{
    if(checkformatpin1(val)==false)
        return false;
    if(val.length !=12)
        return false;
    arr=val.split("-");
    if(arr.length!=3 || arr[0].length !=3 || arr[1].length !=3 || arr[2].length !=4)
        return false;
    return true;
}