﻿/********************************************************************

            Created by  :   Computer Castle Corp., Tirunelveli.
            Date        :   Wed, 08 Apr, 2007
            Client Name :   www.astrology.com.au
            Description :   This Utitilies js file is created for the
                            commonly used client-side scripting

********************************************************************/

function GetDayOfMonth(DayCtrl, MonthCtrl, YearCtrl){		        
    
    var DayValue = DayCtrl.options[DayCtrl.selectedIndex].value;
    
    var DaysCount=31;
    
    if (MonthCtrl.selectedIndex=='2' && (parseInt(YearCtrl.options[YearCtrl.selectedIndex].value)%4)==0){
        DaysCount=29;
    }else if (MonthCtrl.selectedIndex=='2'){
        DaysCount=28;
    }else if (MonthCtrl.selectedIndex=='4' || MonthCtrl.selectedIndex=='6' || MonthCtrl.selectedIndex=='9' || MonthCtrl.selectedIndex=='11'){
        DaysCount=30;		                    		            
    }
    DayCtrl.options.length=0;
    var oOption;
    var i;
    oOption=new Option('Day','-1');
    DayCtrl.options.add(oOption);
    for (i=1;i<=DaysCount;i++){        
        oOption=new Option(i,i);
        DayCtrl.options.add(oOption);            
        if (DayValue==i) oOption.selected=true;
    }
}

function trim( s ){
    var i, startPos = 0, endPos = 0;    for( i = 0; i < s.length; i++ ){
        if( s.charAt(i) != ' ' ){
            startPos = i;
            break;
        }
    }
    for( i = s.length - 1; i >= 0; i-- ){
        if( s.charAt(i) != ' ' ){
            endPos = i + 1;
            break;
        }
    }	s = s.substring( startPos, endPos );
    return s;}function IsEmpty(s){    return (trim(s)=='');    }function IsEmailId( s ){
    if( IsEmpty( s ) )
        return false;

    return s.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{3,3})$|(\..{2,2}))$)\b/gi);
}




function CheckForValidEmail(Ctrl){       
	
	   if (!IsEmailId(Ctrl.value)){       
	   	 alert('The Email Id provided is not a valid Email Id.');      
	   	 Ctrl.focus();      
	   	 return false;    }      
	   return true;}    
	   

function CheckForValidString(Ctrl, Message){     
	
	   if (trim(Ctrl.value)==''){       
	   	 alert('The ' + Message +' should not be null.');      
	   	 Ctrl.focus();       
	   	 return false;    
	   }
	   
	   if(Message=='First Name'){
	   	if (IsEmailId(Ctrl.value)){
	   	alert('Invalid input!');
	   	Ctrl.focus();
	   	return false;   
	   	 }
	   	
	   	}
	   	
	   if(Message=='Last Name'){
	   	if (IsEmailId(Ctrl.value)){
	   	alert('Invalid input!');
	   	Ctrl.focus();
	   	return false;   
	   	 }
	   	
	   	}
	   	
	   if(Message=='City / Town'){
	   	if (IsEmailId(Ctrl.value)){
	   	alert('Invalid input!');
	   	Ctrl.focus();
	   	return false;   
	   	 }
	   	
	   	}
	   	
	   if(Message=='State'){
	   	if (IsEmailId(Ctrl.value)){
	   	alert('Invalid input!');
	   	Ctrl.focus();
	   	return false;   
	   	 }
	   	
	   	}
	   	
	   if(Message=='Country'){
	   	if (IsEmailId(Ctrl.value)){
	   	alert('Invalid input!');
	   	Ctrl.focus();
	   	return false;   
	   	 }
	   	
	   	}
	   	
	   if(Message=='Time of Birth'){
	   	if (IsEmailId(Ctrl.value)){
	   	alert('Invalid input!');
	   	Ctrl.focus();
	   	return false;   
	   	 }
	   	
	   	}
	   	
	   	    
	   return true;
	   
	}