﻿// JScript File
function ValidateFamilyTree()
{     
						
			
                        if (Trim(document.getElementById("TxtMemName").value) != '')
						{
						    if(!CheckAlphabet(Trim(document.getElementById("TxtMemName").value),true,true,'Name'))
						    {
                                document.getElementById("TxtMemName").value='';
                                document.getElementById("TxtMemName").focus();
		                        return false;
						    }
						}
	
}

function ValidateNew_Search_Family(pagefor)
{       
        if (pagefor == 'NewFamily')
        {
            if (Trim(document.getElementById("TxtFamilyName").value) == '' || Trim(document.getElementById("TxtLocation").value) == '')
            {
                alert("Please enter both Family Name and Location");
                document.getElementById("TxtFamilyName").focus();
                return false;
            }   
        }        
		if (Trim(document.getElementById("TxtFamilyName").value).length > 49)
        {
                alert("Family Name length exceeds the limit. Please reduce the size.");
                document.getElementById("TxtFamilyName").focus();
                return false;
        }
        if (Trim(document.getElementById("TxtFamilyName").value) != '')
        {
            if(!CheckAlphabet(Trim(document.getElementById("TxtFamilyName").value),true,true,'Family Name'))
            {
            document.getElementById("TxtFamilyName").value='';
            document.getElementById("TxtFamilyName").focus();
            return false;
            }
        }
        if (Trim(document.getElementById("TxtLocation").value).length > 49)
        {
                alert("Location length exceeds the limit. Please reduce the size.");
                document.getElementById("TxtLocation").focus();
                return false;
        }
        if (Trim(document.getElementById("TxtLocation").value) != '')
        {
            if(!CheckAlphabet(Trim(document.getElementById("TxtLocation").value),true,true,'Location'))
            {
            document.getElementById("TxtLocation").value='';
            document.getElementById("TxtLocation").focus();
            return false;
            }
        }
        if (pagefor == 'NewFamily')
        {
            if (Trim(document.getElementById("TxtPassword").value) == '')
            {
                alert("Please enter Password");
                document.getElementById("TxtPassword").focus();
                return false;
            }
            if (Trim(document.getElementById("TxtPassword").value).length < 6)
            {
                alert("Please enter minimum 6 charecters for password.");
                document.getElementById("TxtPassword").focus();
                return false;
            }
            if (Trim(document.getElementById("TxtPassword").value).length > 19)
            {
                alert("Password length exceeds the limit. Please reduce the size.");
                document.getElementById("TxtPassword").focus();
                return false;
            }   
        }        
}
function ValidateCalendar()
{
        if (Trim(document.getElementById("TxtNewEvent").value) == '')
        {
                alert("Please enter an event before submiting");
                document.getElementById("TxtNewEvent").focus();
                return false;
        }
        
       if (Trim(document.getElementById("TxtNewEvent").value).length > 249)
        {
                alert("Event length exceeds the limit. Please reduce the size.");
                document.getElementById("TxtNewEvent").focus();
                return false;
        }
       if (Trim(document.getElementById("TxtSelectedDate").value)=='')
        {
                alert("Please select a date before submitting");
                return false;
        }
}
//------++Check Alphabet or not
function CheckAlphabet(addr,man,db,fieldname) {
        if (addr == '' && man) 
	        {
		        if (db) alert(fieldname + ' is mandatory');
		        return false;
	        }
        var invalidChars = '\/\\\";:?!()[]\{\}^|!#$%^&*~`=';
        for (i=0; i<invalidChars.length; i++) 
           {
           if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
              if (db) alert(fieldname + ' contains invalid characters');
              return false;
           }
        }
        for (i=0; i<addr.length; i++) 
        {
           if (addr.charCodeAt(i)>127) 
           {
              if (db) alert(fieldname + ' contains non ascii characters');
              return false;
           }
        }
        var atPos = addr.indexOf('@',0);
        if (atPos > -1) 
        {
           if (db) alert(fieldname + ' must not contain an @');
           return false;
        }

        return true;
}



function CheckAlphabet1(addr)
{
        var invalidChars = '\/\\\";:?!()[]\{\}^|!#$%^&*~`=';
        for (i=0; i<invalidChars.length; i++) 
        {
           if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
              return false;
           }
        }
        for (i=0; i<addr.length; i++) 
        {
           if (addr.charCodeAt(i)>127) 
           {
              return false;
           }
        }
        var atPos = addr.indexOf('@',0);
        if (atPos > -1) 
        {
           return false;
        }
        return true;
}

function checkEmailAddress(addr,man,db) 
{
        if (addr == '' && man) 
	        {
		        if (db) alert('email address is mandatory');
		        return false;
	        }
        var invalidChars = '\/\'\\ ";:?!()[]\{\}^|!#$%^&*~`=';
        for (i=0; i<invalidChars.length; i++) {
           if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
              if (db) alert('email address contains invalid characters');
              return false;
           }
        }
        for (i=0; i<addr.length; i++) {
           if (addr.charCodeAt(i)>127) {
              if (db) alert("email address contains non ascii characters.");
              return false;
           }
        }
        var atPos = addr.indexOf('@',0);
        if (atPos == -1) {
           if (db) alert('email address must contain an @');
           return false;
        }
        if (atPos == 0) {
           if (db) alert('email address must not start with @');
           return false;
        }
        if (addr.indexOf('.', atPos) == -1) {
           if (db) alert('email address must contain a period in the domain name');
           return false;
        }
        if (addr.indexOf('@.',0) != -1) {
           if (db) alert('period must not immediately follow @ in email address');
           return false;
        }
        if (addr.indexOf('.@',0) != -1){
           if (db) alert('period must not immediately precede @ in email address');
           return false;
        }
        if (addr.indexOf('..',0) != -1) {
           if (db) alert('two periods must not be adjacent in email address');
           return false;
        }
        if (addr.indexOf('@@',0) != -1) {
           if (db) alert('two @@ must not be adjacent in email address');
           return false;
        }
        var suffix = addr.substring(addr.lastIndexOf('.')+1);
        if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
           if (db) alert('invalid primary domain in email address');
           return false;
   }
   return true;
}
function checkEmailAddress1(addr) 
{
        var invalidChars = '\/\'\\ ";:?!()[]\{\}^|!#$%^&*~`=';
        for (i=0; i<invalidChars.length; i++) {
           if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
              
              return false;
           }
        }
        for (i=0; i<addr.length; i++) {
           if (addr.charCodeAt(i)>127) {
              
              return false;
           }
        }
        var atPos = addr.indexOf('@',0);
        if (atPos == -1) {
           
           return false;
        }
        if (atPos == 0) {
           
           return false;
        }
        if (addr.indexOf('.', atPos) == -1) {
           
           return false;
        }
        if (addr.indexOf('@.',0) != -1) {
           
           return false;
        }
        if (addr.indexOf('.@',0) != -1){
           
           return false;
        }
        if (addr.indexOf('..',0) != -1) {
           
           return false;
        }
        if (addr.indexOf('@@',0) != -1) {
           
           return false;
        }
        var suffix = addr.substring(addr.lastIndexOf('.')+1);
        if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
           
           return false;
   }
   return true;
}

//----------------------------
function funValidateNum()
	{	
		if(event.shiftKey == false)
			{
				if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode >= 37 && event.keyCode <= 40) || (event.keyCode == 8) || (event.keyCode == 13) || ( event.keyCode == 46) || ( event.keyCode == 9)) //check for alphabets 	
				return true;
				else
				{	
					event.returnValue =0
					return false;
				}
			}
		else if(event.shiftKey == true && event.keyCode==9)
			{
				return true
			}
			else
			{
				event.returnValue =0
				return false;
			}		
	}
//---------------
function CheckFieldLength(control_name,lengthrequired)
{
    var control_value = control_name.value;
    if (control_value.length >= lengthrequired)
    {
        event.returnValue =0;
        return false;
    }
    else
    {  
        return true;
    }    
}

