NS4 = (document.layers) ? true : false;

function checkEnterMA(event)
{     
    var code = 0;
    
    if (NS4)
        code = event.which;
    else
        code = event.keyCode;
    if (code==13) {
    	document.form_members_area.action = "http://www.casinocanberra.com.au/cs/members/members_area_process.php";
     	document.form_members_area.submit;
    }
}

var phone_exp=/^\d{10}$/g
var reWhitespace = /^\s+$/
var email_exp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
var zip_exp = /^\d{4}$/
var letter_exp = /[a-z'-]/ig
var noDBQuote_exp = /[a-z'-.,d]/ig
var digits_exp = /\d/ig
var date_exp = /^0?(\d{1,2})\D+0?(\d{1,2})\D+(\d{2}|\d{4})$/;
var date_out = "$1/$2/$3";
//edits by Natasha McTigue to replace all non=word characters with &#163
var simple_char=/\^w|\^W[^\,\!\?\|\\]/ig;
var single_exp1 = /[\’]/ig
var single_exp2 = /[\‘]/ig
var single_exp3 = /[\”]/ig
var single_exp4 = /[\“]/ig
var single_exp5 = /[\—]/ig
var single_exp6 = /[\…]/ig

var graphic_exp=/gif|jpg|jpeg|bmp|pic/i;
var NetscapeVerArray=false;

// Determin Netscape Browser Virsions
if (navigator.appName == "Netscape") {
    // Get Netscape 4.x
    if (navigator.appVersion.substring(0,4)=="4.03") {
       var NetscapeVerArray=true;
    }
    // Get Netscape 3.x
    else if (navigator.appVersion.substring(0,1)=="3") {
		if (confirm("To view this site your have to install a new version of Netscape Navigator. \n Would you like to upload one now?")){
			window.open("http://home.netscape.com/download/index.html?cp=djuc1")
		}
        
    }
    // Get Netscape 2.x
    else if (navigator.appVersion.substring(0,1)=="2") {
		if (confirm("To view this site your have to install a new version of Netscape Navigator. \n Would you like to upload one now?")){
			window.open("http://home.netscape.com/download/index.html?cp=djuc1")
		}
    }
 
    
}
//alert(navigator.appVersion.substring(0,4))

//Vallidate no double quotes fields
function validate_noDBquote(inputValue, fieldName){
	if((inputValue.value=="") || (isWhitespace (inputValue.value)))
	                return ERRORS+="No " + fieldName + " entered \n";
	        else { 	
					value=inputValue.value.replace(/\s/g, "")			                 
	                result=value.replace(letter_exp, "")
	                if (result.length>0)  	                
	                return ERRORS+="Invalid " +fieldName +"\nThis field must contain only letters\n";           
	            }      
	}
	

//function removes leading and ending spaces from string
function trimLeadSpace(inputValue){

	//beggining spaces 
	while(''+ inputValue.charAt(0)==' '){	
		inputValue=inputValue.substring(1,inputValue.length);
	}
	
	//ending spaces
	while(inputValue.charAt(inputValue.length-1)+''==' '){	
		inputValue=inputValue.substring(0,inputValue.length-1);
	}
	
	return inputValue;	
}



//Check for curly quotes (Microsoft Office) and replace them with straight quotes 
function replace_quotes(inputValue){
	if(!(inputValue.value=="") || !(isWhitespace (inputValue.value)))
				{
					value=inputValue.value
					replaceChar=value.replace(single_exp1, "'")					
					replaceChar1=replaceChar.replace(single_exp2, "'") 
					replaceChar2=replaceChar1.replace(single_exp3, '"') 
					replaceChar3=replaceChar2.replace(single_exp4, '"') 
					replaceChar4=replaceChar3.replace(single_exp5, "--") 
					replaceChar5=replaceChar4.replace(single_exp6, "...")
					inputValue.value=replaceChar5
	            }      
	}

//Vallidate text fields
function validate_text(inputValue, fieldName){
	if((inputValue.value=="") || (isWhitespace (inputValue.value)))
	                return ERRORS+="No " + fieldName + " entered \n";
	        else { 	
					value=inputValue.value.replace(/\s/g, "")			                 
	                result=value.replace(letter_exp, "")
	                if (result.length>0)  	                
	                return ERRORS+="Invalid " +fieldName +"\nThis field must contain only letters\n";           
	            }      
	}

//Vallidate digits fields
function validate_digits(inputValue, fieldName){
	if((inputValue.value=="") || (isWhitespace (inputValue.value)))
	                return ERRORS+="No " + fieldName + " entered \n";
	        else { 	
					value=inputValue.value.replace(/\s/g, "")			                 
	                result=value.replace(digits_exp, "")
	                if (result.length>0)  	                
	                return ERRORS+="Invalid " +fieldName +"\nThis field must be a digit input\n";           
	            }      
	}


//Vallidate radio button BOAL 3-8-2003
function validate_radioBtn(inputValue, fieldName){		        
   if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
                return ERRORS+=fieldName;
} 

//boal trying again for radio button
function validate_radiovoucher(fieldName)
{
for(var i=0;i<document.form1.voucher.length;i++)
     if (document.form1.voucher[i].checked)
          return true;
return ERRORS+=fieldName;
}

//boal trying again for radio button
function validate_radioage(fieldName)
{
for(var i=0;i<document.form1.age.length;i++)
     if (document.form1.age[i].checked)
          return true;
return ERRORS+=fieldName;
}










function validate_radio_info_email_M(inputValue, fieldName) {
	for(var i=0;i<document.form_members.info_email.length;i++)
    	if (document.form_members.info_email[i].checked)
        	return true;
	return ERRORS+=fieldName;
}

function validate_radio_info_postage_M(inputValue, fieldName) {
	for(var i=0;i<document.form_members.info_postage.length;i++)
    	if (document.form_members.info_postage[i].checked)
        	return true;
	return ERRORS+=fieldName;
}

function validate_radio_info_email_S(inputValue, fieldName) {
	for(var i=0;i<document.form_subscribers.info_email.length;i++)
    	if (document.form_subscribers.info_email[i].checked)
        	return true;
	return ERRORS+=fieldName;
}

function validate_radio_info_postage_S(inputValue, fieldName) {
	for(var i=0;i<document.form_subscribers.info_postage.length;i++)
    	if (document.form_subscribers.info_postage[i].checked)
        	return true;
	return ERRORS+=fieldName;
}

function validate_radio_visit_casinocanberra(inputValue, fieldName) {
	for(var i=0;i<document.form_members.visit_casinocanberra.length;i++)
    	if (document.form_members.visit_casinocanberra[i].checked)
        	return true;
	return ERRORS+=fieldName;
}

function validate_radio_preferred_game(inputValue, fieldName) {
	for(var i=0;i<document.form_members.preferred_game.length;i++)
    	if (document.form_members.preferred_game[i].checked)
        	return true;
	return ERRORS+=fieldName;
}







//boal trying again for radio button
function validate_radio_html_or_text(fieldName)
{
for(var i=0;i<document.form1.html_or_text.length;i++)
     if (document.form1.html_or_text[i].checked)
          return true;
return ERRORS+=fieldName;
}

//Validate password confirmation 
function validate_confirmation(inputValue, compareValue, fieldName){
	if(((inputValue.value=="") || (isWhitespace (inputValue.value))) || ((compareValue.value=="") || (isWhitespace (compareValue.value))))
	                return ERRORS+=fieldName;
	        else { 
					if (!(inputValue.value==compareValue.value))
					return ERRORS+=fieldName;
	        }

}


//Validate password confirmation 
function validate_Logins(inputValue, compareValue, fieldName){
	if(((inputValue.value=="") || (isWhitespace (inputValue.value))) || ((compareValue.value=="") || (isWhitespace (compareValue.value))))
	                return ERRORS+="No " + fieldName + " entered \n";
	        else { 
					if (trimLeadSpace(inputValue.value)==trimLeadSpace(compareValue.value))
					return ERRORS+="Admin and Sales Login must be unique.\n";
	        }

}

//Validate zip code
function validate_zip(inputValue, fieldName ){	
	if((inputValue.value=='')||(isWhitespace (inputValue.value)))
                 return ERRORS+=fieldName;
        else {   
        
                             
            if (!isValid(zip_exp,trimLeadSpace(inputValue.value))) 
            return ERRORS+=fieldName;
            }               
}                        


//validate phone      
function validate_phone(inputValue, fieldName){	
	if((inputValue.value=='')||(isWhitespace (inputValue.value)))
                return ERRORS+="No " + fieldName + "  entered \n";
       else {                        
            value=inputValue.value.replace(/\s/g, "")
   			var phoneNum= value.replace( /[\(\)-]/g, "" )
   			if ((isNaN(phoneNum)==true ) || (!(phoneNum.length==10)))
   			return ERRORS+=("Invalid " + fieldName + "\nThis field must be a 10 digit phone number with area code, like (xx) xxxx-xxxx\n");
   		  }             
}                        
 
 
//validate Email 
function validate_email(inputValue, fieldName){
	if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
                return ERRORS+=fieldName;
       else {
                       if (!(isValid(email_exp, inputValue.value))) 
                       return ERRORS+=fieldName;
            }
 
}

function validate_multEmail(inputValue, fieldName){   
   var arrayElements;
   var trimedValue="";
      
   //Check for empty or null value
   if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
       return ERRORS+="No " + fieldName + "  entered \n";
       
   else {
       
        //check what delimiter is being used (Comma or Semicolon) for multiple emails 
                        
		arrayElements=inputValue.value.split(",");	//Comma Section
		
			if (arrayElements.length!=1){
				 
				 for(var i=0; i < arrayElements.length; i++){
					
					trimedValue=trim(arrayElements[i])
					if (trimedValue.split("@").length > 2)
						ERRORS+="Please remember to separate your addresses with Semicolon (;) like  john@yahoo.com; bob@yahoo.com.\n";
						
					if(trimedValue!=""){ 					
						if (!(isValid(email_exp, trimedValue))) 
						ERRORS+=("This " + trimedValue + " email must be a valid email address like john@yahoo.com\n");
					}
				}		
				
					
			}
			
			
			else {
					
					arrayElements=inputValue.value.split(";"); //Semicolon Section
					
					if (arrayElements.length!=1){
						 
						 for(var k=0; k<arrayElements.length; k++){						
						
							trimedValue=trim(arrayElements[k])
							if (trimedValue.split("@").length > 2)
								ERRORS+="Please remember to separate your addresses with Semicolon (;) like  john@yahoo.com; bob@yahoo.com.\n";
						
							if(trimedValue!=""){ 							
								if (!(isValid(email_exp, trimedValue))) 
								ERRORS+=("This " + trimedValue + " email must be a valid email address like john@yahoo.com\n");
							}
						}	
					}
					
					//check for number of emails in the field		
					else if (inputValue.value.split("@").length > 2)
						{							
							ERRORS+="Please remember to separate your addresses with Semicolon (;) like  john@yahoo.com; bob@yahoo.com.\n";
						}	
						
					else
					{
						if (!(isValid(email_exp, inputValue.value)))
							ERRORS+=("This " + inputValue.value + " email must be a valid email address like john@yahoo.com\n");	
						else return true;	  
					}		
			}
		
		return ERRORS;
    }
 
}
                
       		
//validate required fields
function validate_required(inputValue, fieldName){
   if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
                return ERRORS+=fieldName;
}      

//validate required fields for phone
function validate_required_phone(inputValue, fieldName){
   if((inputValue.value=='') ||(isWhitespace(inputValue.value)) || (isNaN(inputValue.value)==true))
                return ERRORS+=fieldName;
}

//validate required fields for at least one of the 4 vouchers selected
function validate_required_4vouchers(inputValue0,inputValue1,inputValue2,inputValue3, fieldName){
   if((inputValue0.checked == false) && (inputValue1.checked == false) && (inputValue2.checked == false) && (inputValue3.checked == false))
                return ERRORS+=fieldName;
}

//validate pulldown box
function validate_pulldown(inputValue, fieldName){
	if(inputValue.selectedIndex==0)
      return ERRORS+=fieldName;  
}      
      
//validate Date
function validate_date(inputValue, fieldName){
	if((inputValue.value=='') ||(isWhitespace(inputValue.value)))
		return ERRORS+="No " + fieldName + " entered\n";

	else return validate_DateEntry(trimLeadSpace(inputValue.value), fieldName)
			 
}

//Vallidate date digits, isNumber and greater then 0
function isNumber(Num, fieldName){
	if(Num!="")
	
		if (Num!=0){	             
			value=Num.replace(/\s/g, "")			                 
			result=value.replace(digits_exp, "")
			if (result.length>0)  	                
			return ERRORS+="Invalid " +fieldName +"\nThis field must be a digit input\n"; 
			}
		else
			return ERRORS+="Invalid " +fieldName +"\nThis field must be a digit input greater then 0 \n";           
	            
	}




function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 


// Check whether string s is empty.
function isEmpty(str)
{   return ((str == null) || (str.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (str)
{   // Is s empty?
    return (isEmpty(str) || reWhitespace.test(str));
}

//validate graphic file type
function validate_graphic(inputValue, fieldName){
	if ((!(inputValue.value=='')) || (!(isWhitespace(inputValue.value))))
	              { 	
					var value=inputValue.value.replace(/\s/g, "") 
	                var imageName=(value.split("\\"))[value.split("\\").length-1]
					var fileType=(imageName.split("."))[imageName.split(".").length-1]
					if (!isValid(graphic_exp, fileType)) 
					return ERRORS+="File " + imageName + " contains incorrect format \n";	               
					else return true;					 
	            }   
	// else 	return ERRORS+="No " + fieldName + " entered\n";   
	}



function isValid(pattern, str) {
        return pattern.test(str)
}

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


//check two dates values. If date 1 is less then date 2/
function dateDiffLess(inputValue1, fieldName1, inputValue2, fieldName2){	

	var vDate1=Date.parse(inputValue1.value);
	var vDate2=Date.parse(inputValue2.value);	
	
	if(vDate1>vDate2)return ERRORS+=("Invalid " + fieldName2 +" \n Begin date can't be less than end date.\n");	 
}


//content validation. In this case checks for correct dates
function validate_DateEntry(inputValue, fieldName) {	
	var value;
	var now = new Date();
	var nowDate=now.getTime();//get today's date
	var userDate=Date.parse(inputValue);//convert number in milliseconds for comparing	
	var daysInMonth = new Array(12);
		daysInMonth[1] = 31;
		daysInMonth[2] = 29;   
		daysInMonth[3] = 31;
		daysInMonth[4] = 30;
		daysInMonth[5] = 31;
		daysInMonth[6] = 30;
		daysInMonth[7] = 31;
		daysInMonth[8] = 31;
		daysInMonth[9] = 30;
		daysInMonth[10] = 31;
		daysInMonth[11] = 30;
		daysInMonth[12] = 31;		
	
	
		
	//check for correct date input	
	if( date_exp.test(inputValue) ) value = inputValue.replace( date_exp, date_out ); else return ERRORS+=("Invalid "+fieldName+". Example:(mm/dd/yyyy) \n");
	var intSplit=inputValue.split("/");//split date to check individual day, month and year
	
	

	//Only for Netscape 4.03 version does not read array well
	if (NetscapeVerArray==true){
		var intMonth=intSplit[1]
		var intDay=intSplit[2]
		var arrayYear=intSplit[3]
		if(intSplit.length!=6) return ERRORS+=("Invalid " +fieldName+". \nEnter date:(mm/dd/yyyy)\n");
	}
	else{
		var intMonth=intSplit[0]
		var intDay=intSplit[1]		
		var arrayYear=intSplit[2]
		if(intSplit.length!=3) return ERRORS+=("Invalid " +fieldName+". \nEnter date:(mm/dd/yyyy)\n");
	}
	

	//check if Month, Day and Year is a digit number
	isNumber(intMonth, "Month Entry in " + fieldName )
	isNumber(intDay, "Day Entry in " + fieldName)
		
	//checks if date was entered in the correct format: mm/dd/yyyy			
	//check for the year digits 2 vs.4 and convert it to 4 digit format if necessary
	if (arrayYear.length==2) {
		intYear="20"+ arrayYear
		userDate=Date.parse(intMonth + "/" + intDay + "/" +intYear)		
		}
	else if ((arrayYear.length==4) && (arrayYear.charAt(0, 1)==0))//date was entered like mm/dd/0002
	   return ERRORS+=("Invalid " +fieldName+". \nEnter correct year:(mm/dd/yyyy)\n");
	
	else if ((arrayYear.length==3)||(arrayYear.length==1))//only 3 digits entered for the year
		return ERRORS+=("Invalid " +fieldName+". \nEnter correct year:(mm/dd/yyyy)\n");
	
	else var intYear = parseFloat(arrayYear);
	
	//check for the valid month    
    if(intMonth>12 || intMonth<0) return ERRORS+=("Invalid " + fieldName+". \nThis field must be a month number between 1 and 12 \n");
	
	// check for invalid days, except for February
    if (intDay > daysInMonth[intMonth])return ERRORS+=("Invalid " +fieldName+". \nThis field must be a day number between 1 and " + daysInMonth[intMonth]+ "\n");
    
    //check for February
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return ERRORS+=("Invalid " +fieldName+ ". \nThis field must be a day number between 1 and " + daysInFebruary(intYear)+ "\n");

	//check if entered date is less then today's date
	//if(nowDate>userDate)return ERRORS+=("Invalid " +fieldName+" \n Date can't be less than today's date.\n");	 
	//if((intYear<2000)||(intYear>2010)) return ERRORS+=("Invalid " +fieldName+" \n Invalid year.\n");	 	
	//list of days by month
   
    return true;
}