/// JScript File
    var result="";

    //************ Validates website URL **********************
    function validateWebsite(control,name)
    {
        if(control.length == 0)
            result = result + '\n - Enter ' + name ;
        else if(!/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/)([a-z]{1,}[\w-.]{0,}).([a-z]{2,6})(\/{1}[\w_]{1}[\/\w-&?=_%]{0,}(.{1}[\/\w-&?=_%]{0,})*)*$/.test(strip_lspaces(control.value)))
            result = result + '\n - Invalid ' + name ;
        
    }
    
    //************ Validates website URL **********************
    function validate_url(control,name)
    {
        if(control.length == 0)
            result = result + '\n - Enter ' + name ;
        else if (!/^https?:\/\/([\w-]+\.?)+[\w-]+(\/[\w- ./?%&=]*)?$/.test(Url))
            result = result + '\n - Invalid ' + name ;
        
    }  
    
    //************ An floating validation *************
    function isempty_floatnumber(val,name)
	{
	    if(val.length==0)
	        result = result + '\n - Enter ' + name ;
	    else if (isNaN(val))
	        result = result + '\n - Invalid ' + name;
	    
	}
    
    //************ An integer validation *************
    function isempty_number(val,name)
	{
	    if(val.length==0)
	        result = result + '\n - Enter ' + name ;
	    else if (isNaN(val) || val.indexOf('.')!=-1)
	        result = result + '\n - Invalid ' + name;
	}

    //*********** textbox has value or not ***********
    function isempty(controlVal, name)
    {
	    if (controlVal.length==0)
	    {
		    result = result + '\n - Enter ' + name ;
	    }
    }
    
      //*********** File has value or not ***********
    function isemptyFile(controlVal, name)
    {
	    if (controlVal.length==0)
	    {
		    result = result + '\n - Upload ' + name ;
	    }
    }

    //*********** Trims left spaces of a control's value ***********
    function strip_lspaces(element){
        if (element != ''){
	        while('' + element.charAt(0) == ' '){
	        element = element.substring(1,element.length);
	        }
        }
        return element;
    }
    
    //************* Validates Zip Code (US-codes only) **************
    function validate_zip(zip)
	{
		if(zip.length==0)
			result=result + "\n - Enter Zip Code";
		else if((zip.length!=0) && (zip.length < 6 || zip.length > 6))
			result=result + "\n - Invalid Zip Code";
		else if(isNaN(zip)) 
			result=result + "\n - Invalid Zip Code";
	}
			
	//************* Validates Phone number (US format) *****************
    function validate_phone(phone, name)
	{
		if (phone.length!=0)
			var sep = getseparator(phone);
		if((phone.length!=0) && (phone.length < 12 || phone.length >12))
			result=result + "\n - Invalid " + name ;
		else if((isNaN(phone.substring(0,3))) || (isNaN(phone.substring(4,7))) || (isNaN(phone.substring(8,12)))) 
			result=result + "\n - Invalid " + name;				
		else if ((sep !="") && (phone.length!=0))
		{
			if((phone.indexOf(sep)!=3) || (phone.lastIndexOf(sep)!=7))
				result=result + "\n - Invalid " + name ;		
		}
		else if(sep =='') 
			result=result + "\n - Invalid " + name ;
	}
	
	//***************** returns separator in phone column **************
	function getseparator(phone_)
	{
		if(phone_.indexOf('-')!=-1)
			return '-';
		else
			return '';
	}
    
    //****************** Checks whether dropdown is selected or not *************************
    function isddlSelected(ddl,type)
    {
        if(ddl.selectedIndex==0)
            result=result + '\n - Select ' + type ;
    }
    
    //***************** Validates emil *************************
    function validate_email(s, type)
    {				
	    var email=s;
	    if(email.length==0 )
		    result=result +  '\n - Enter ' + type;
	    else if ((email.indexOf('@')== -1) || (email.indexOf('.')==-1))
		    result= result + '\n - Invalid ' + type;
	    else if((email.indexOf('@')==0) || (email.indexOf('.')==0))
		    result= result + '\n - Invalid ' + type;
	    else if(((email.indexOf('.')==email.indexOf('@')+1))||(email.indexOf('@')> email.lastIndexOf('.')))
		    result= result + '\n - Invalid ' + type;
	    else if(email.lastIndexOf('.')==email.length-1)
		    result= result + '\n - Invali ' + type;
        else if (email.substring(email.lastIndexOf('.') + 1,email.length).length > 3)
        {
            result= result + '\n - Invalid ' + type;
        }
	    else
	    {
		    var chararray =new Array('\\','\'','~','!','#',' ','$','%','^','&','*','-','+','<','>','=','(',')','|','"','/',';',':','`',',')
		    if(s=validate_chars(email,chararray))
			    result= result + '\n - Invalid ' + type;
	    }
	    for(count=0,j=0;j<email.length;++j)
	    {
		    if(email.charAt(j)=='@')
			    count++
		    if(count==2) {
		        result= result + '\n - Invalid ' + type;
		        break;
		        }
	    }
    }

    //This function checks whether the mail
    //contains any special characters other then
    //'@' and '.'.
    function validate_chars(field,arraychars)
    {
	    for(p=0;p<field.length;++p)
		    for(j=0;j<arraychars.length;++j)
			    if(field.charAt(p)==arraychars[j])			
				    return arraychars[j];
    }
    
    //******************** Validates date ******************************
    //          Accepts mm-dd-yyyy, mm/dd/yyyy and mm.dd.yyyy formats
    function validate_textdate(edate, name)
	{
		var date1=edate;
		var mm,dd,yy,sptr;
		sptr=getseparator_date(date1);
		if (sptr != null)
		{       
		    mm=date1.substring(0,date1.indexOf(sptr));
		    dd=date1.substring(date1.indexOf(sptr)+1,date1.lastIndexOf(sptr));
		    yy=date1.substring(date1.lastIndexOf(sptr)+1,date1.length);
		    if(date1.length==0)
		        result= result + '\n - Invalid ' + name;
		    else if(isNaN(mm)||isNaN(dd)||isNaN(yy))
			    result= result + '\n - Invalid ' + name;
		    else if(parseInt(dd)>31)
		    	result= result + '\n - Invalid ' + name;
		    else if(parseInt(mm)>12)
			    result= result + '\n - Invalid ' + name;
		    else if(yy.length==3 || yy.length==1 || yy.length>4 || yy.length==0)
			    result= result + '\n - Invalid ' + name;
		    else if((parseInt(mm)==4 || parseInt(mm)==6 || parseInt(mm)==9 || parseInt(mm)==11) && (parseInt(dd)>30))
		    	result= result + '\n - Invalid ' + name;
		    else if( (parseInt(yy))%4 == 0 && parseInt(dd)>28 && parseInt(mm)==2)
			    result= result + '\n - Invalid ' + name;
			else if(parseInt(yy)%4!=0 && parseInt(dd)>29 && parseInt(mm)==2)
		    	result= result + '\n - Invalid ' + name;
		 }
		else if(sptr == null && date1.length!=0)
		    result= result + '\n - Enter '+ name+" in MM/DD/YYYY Format";		
	}
    
    function getseparator_date(u_date)
    // returns separator in date column
    {
        alert(u_date);
        if((u_date.indexOf('/')!=-1) && (u_date.indexOf('.')!=-1))
            return ;
        else if((u_date.indexOf('.')!=-1) && (u_date.indexOf('-')!=-1))
            return ;
        else if((u_date.indexOf('-')!=-1) && (u_date.indexOf('/')!=-1))
            return ;
        else if(u_date.indexOf('/')!=-1)
            return "/";
        else if(u_date.indexOf('.')!=-1)
            return ".";
        else if(u_date.indexOf('-')!=-1)
            return "-";
    }
    
    //********************************* Validates Time **********************************
    function validateTime(controlVal,name)
    {
        var time = controlVal;
        if(time.length == 0)
            result = result + '\n - Enter ' + name;
        else if(!(/^(\d{1,2}):(\d{2})(:(\d{2}))?(\s(AM|am|PM|pm))?$/.test(time)))
            result = result + '\n - Invalid ' + name;
        else
        {
            var splitTime = time.split(':');
            var hrs = splitTime[0];
            var _min = splitTime[1].split(' ');
            var min = _min[0];
            var am_pm = _min[1].toLowerCase();
            if (hrs == '' || min == '' || am_pm == '')
                result = result + '\n - Invalid ' + name;
            else if (hrs > 12)
                result = result + '\n - Invalid Hours in ' + name;
            else if(min >= 60)
                result = result + '\n - Invalid Minitues in ' + name;
        }
    }
    
    //********************************* Validate Graphic Verification Code **********************************
    function validateGVC(val1,val2)
    {
        if(val1.length==0)
        {
            result = result + '\n - Enter Graphic Verification Code';            
        }
        else if(val1!=val2)
        {
            result = result + '\n - Invalid Graphic Verification Code';
        }
    }
    
     //********************************* Validate File Upload Control **********************************
     function validateFileUpload(val1, val2)
     {
    
            if (strip_lspaces(val1) != "")
            {	
				ext	=	val1.substr(val1.lastIndexOf(".")).toLowerCase();
				if (ext!=".jpg" && ext!=".gif" && ext!=".jpeg" && ext!=".bmp" ){
			   		result = result + '\n - Invalid ' + val2;  
			   	}
			}
    }
    
    
    
    function displayErrors()
    {
        if (result.length==0 || result=='')
		    return true;
	    else
	    {
		    alert('Please Check the following information \n '+ result);
		    result='';
		    return false;
	    }
	    return false;
	}

    function formatphonenumber(phone)
    {
        /// Created on : 26-03-2008
        /// Created by : Sarma
        var p = phone;
        var pp = '';
        phone = phone.value;
        
        if(phone.length > 0)
        {
           if(phone.length <=3)
            {   
                pp='';
                for(c=0;c<phone.length;c++)
                {
                    if(isNaN(phone.charAt(c))  || phone.charAt(c) ==' ')
                       continue; 
                    else
                        pp = pp + phone.charAt(c);   
                }
                
                p.value = pp;
            }
            else if(phone.length > 3 )
            {
                var pAry = phone.split('-');
                phone ='';
                
                for(r=0;r<pAry.length; r++)
                    if(pAry[r])
                        phone += pAry[r];
                
                pp='';
                for(c=0;c<phone.length;c++)
                {
                    if(isNaN(phone.charAt(c)) || phone.charAt(c) ==' ')   
                       continue; 
                    else
                        pp = pp + phone.charAt(c);
                }
                
                if(pp.length > 10)
                    pp = pp.substring(0,3) + '-' + pp.substring(3,6) + '-' + pp.substring(6,10);
                else if(pp.length > 6)
                    pp = pp.substring(0,3) + '-' + pp.substring(3,6) + '-' + pp.substring(6);
                else
                    pp = pp.substring(0,3) + '-' + pp.substring(3,6) ;
                p.value = pp;
            }
        }
        if(p.value == '-') p.value = '';
    }

