﻿// this check drop down whether it is selected (other than 0 index) and show error message						
function validateDropDown(o_dropdownName, o_dropdownErrorMessage)
{				
	var obj = MM_findObj(o_dropdownName);
	var obj2 = MM_findObj(o_dropdownErrorMessage);
	if (obj != null)
	{
		if (obj.selectedIndex == 0)
		{					
			obj2 = (obj2.style) ? (obj2.style):obj2;
			obj2.display = "block";	
			return false;					
		}
		else
		{
			obj2 = (obj2.style) ? (obj2.style):obj2;
			obj2.display = "none";		
			return true;
		}
	}
	else
		return false;
}


function validateTextField2(o_textFieldName)
{
	var obj = MM_findObj(o_textFieldName);					
	if (obj != null)
	{
		if (obj.value.replace(/^\s*|\s*$/g,"") == '')
		{						
			return false;
		}
	}
	else
	{
		return false;
	}
		
	return true;
}

// this check text field whether it is filled and show error message						
function validateTextField(o_textFieldName, o_textFieldErrorMessage)
{
	var obj = MM_findObj(o_textFieldName);				
	var obj2 = MM_findObj(o_textFieldErrorMessage);
	if (obj != null && obj2 != null)
	{
		if (obj.value.replace(/^\s*|\s*$/g,"") == '')
		{			
			obj2 = (obj2.style) ? (obj2.style):obj2;
			obj2.display = "block";	
			return false;
		}
	}
	else
	{
		return false;
	}
		
	obj2 = (obj2.style) ? (obj2.style):obj2;
	obj2.display = "none";	
	return true;
}

function validateTextFieldSize(o_textFieldName, o_textFieldErrorMessage, size)
{
	var obj = MM_findObj(o_textFieldName);				
	var obj2 = MM_findObj(o_textFieldErrorMessage);
	if (obj != null && obj2 != null)
	{
		if (obj.value.length < size)
		{			
			obj2 = (obj2.style) ? (obj2.style):obj2;
			obj2.display = "block";	
			return false;
		}
	}
	else
	{
		return false;
	}
		
	obj2 = (obj2.style) ? (obj2.style):obj2;
	obj2.display = "none";	
	return true;
}



// this check radio button whether it is selected and show error message						
function validateRadioButton(o_radioButtonName, o_radioButtonErrorMessage, no)
{				
	var obj = MM_findObj(o_radioButtonName);
	var obj2 = MM_findObj(o_radioButtonErrorMessage);
	if (obj != null)
	{					
		for (var i = 0; i < no; i++)
		{
			if (obj[i].checked)
			{
				obj2 = (obj2.style) ? (obj2.style):obj2;
				obj2.display = "none";	
				return true;
			}						
		}
		obj2 = (obj2.style) ? (obj2.style):obj2;
		obj2.display = "block";	
		return false;
	}
	else
		return false;		
}	

// this check radio button whether it is selected
function checkRadioButton(o_radioButtonName, no)
{				
	var obj = MM_findObj(o_radioButtonName);	
	if (obj != null)
	{					
		for (var i = 0; i < no; i++)
		{
			if (obj[i].checked)
			{				
				return true;
			}						
		}		
		return false;
	}
	else
		return false;		
}	

// this check radio button whether it is selected and show error message						
function validateRadioButtonList(o_formName, o_radioButtonName, o_radioButtonId, o_radioButtonErrorMessage, no)
{					
	var obj = MM_findObj(o_formName);
	var obj2 = MM_findObj(o_radioButtonErrorMessage);	
	
	if (obj != null)
	{
		for (var i = 0; i < obj.elements.length; i++)
		{
			// check radio button for the same group
			if (o_radioButtonId == '')
			{
				if (obj.elements[i].type == "radio" &&
					obj.elements[i].name == o_radioButtonName)				
				{												
					if (obj.elements[i].checked)
					{				
						obj2 = (obj2.style) ? (obj2.style):obj2;
						obj2.display = "none";	
						return true;
					}												 	
				}
			}
			else	// check more specific
			{
				if (obj.elements[i].type == "radio" &&
					obj.elements[i].name == o_radioButtonName && 
					obj.elements[i].id == o_radioButtonId)				
				{												
					if (obj.elements[i].checked)
					{				
						obj2 = (obj2.style) ? (obj2.style):obj2;
						obj2.display = "none";	
						return true;
					}							
					else
					{
						obj2 = (obj2.style) ? (obj2.style):obj2;
						obj2.display = "block";	
						return false;		
					}
				}
			}
		}		
	}
	else
		return false;
		
	obj2 = (obj2.style) ? (obj2.style):obj2;
	obj2.display = "block";	
	return false;
}	

function validateEmail(o_textFieldName, o_textFieldErrorMessage)
{
	var obj = MM_findObj(o_textFieldName);				
	var obj2 = MM_findObj(o_textFieldErrorMessage);	
	var emailRegExp = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (obj != null && obj2 != null)
	{
		if (!emailRegExp.test(obj.value))
		{			
			obj2 = (obj2.style) ? (obj2.style):obj2;
			obj2.display = "block";	
			return false;
		}
	}
	else
	{
		return false;
	}
		
	obj2 = (obj2.style) ? (obj2.style):obj2;
	obj2.display = "none";	
	return true;
}



function IsNumeric(sText)
{
   var ValidChars = "0123456789.-";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function validateTextFieldAsNumber(o_textFieldName, o_textFieldErrorMessage)
{
	var obj = MM_findObj(o_textFieldName);				
	var obj2 = MM_findObj(o_textFieldErrorMessage);	
	if (obj != null && obj2 != null)
	{
		if (!IsNumeric(obj.value))
		{			
			obj2 = (obj2.style) ? (obj2.style):obj2;
			obj2.display = "block";	
			return false;
		}
	}
	else
	{
		return false;
	}
		
	obj2 = (obj2.style) ? (obj2.style):obj2;
	obj2.display = "none";	
	return true;
}

function validateAddBooking()
{
    var isOK  = true;
    	
    if (!validateTextField('ctl00_ContentPlaceHolder1_AddBooking1_DateTimePicker1_tbDate', 'reg_date_error'))
        isOK = false;
    
	if (!validateTextField('ctl00_ContentPlaceHolder1_AddBooking1_tbBookingName', 'reg_name_error'))
		isOK = false;
	
	var isPhoneOk = false;			
	var obj1 = MM_findObj('reg_hphone_error');	
    var obj2 = MM_findObj('reg_wphone_error');	
    obj1 = (obj1.style) ? (obj1.style):obj1;
    obj2 = (obj2.style) ? (obj2.style):obj2;
	if (validateTextField2('ctl00_ContentPlaceHolder1_AddBooking1_tbHomePhone') || 
	    validateTextField2('ctl00_ContentPlaceHolder1_AddBooking1_tbWorkPhone'))
		isPhoneOk = true;
    
    if (!isPhoneOk)		
    {        
        obj1.display = "block";	
        obj2.display = "block";	
        isOK = false;
    }
    else
    {
        obj1.display = "none";	
        obj2.display = "none";	
    }
	
	if (!validateTextField('ctl00_ContentPlaceHolder1_AddBooking1_tbEmail', 'reg_email_error1'))
		isOK = false;
		
	if (!validateEmail('ctl00_ContentPlaceHolder1_AddBooking1_tbEmail', 'reg_email_error2'))
		isOK = false;			
		
    if (!validateRadioButtonList('aspnetForm', 'ctl00$ContentPlaceHolder1$AddBooking1$rblProducts', '', 'reg_products_error', ''))
	    isOK = false;
	    
	var obj3 = MM_findObj('lbDetails');
	var obj4 = MM_findObj('reg_bDetails_error');
	obj4 = (obj4.style) ? (obj4.style):obj4;
	if (obj3.options.length <= 0)
	{
        obj4.display = "block";	    	    
	    isOK = false;	    
	}   
	else
	{
	    obj4.display = "none";
	}
			
	return isOK;
}

function validateAddEnquiries()
{
    var isOK  = true;
    	
	if (!validateTextField('ctl00_ContentPlaceHolder1_AddEnquiry1_tbName', 'reg_name_error'))
		isOK = false;
				
    var isPhoneOk = false;			
	var obj1 = MM_findObj('reg_hphone_error');	
    var obj2 = MM_findObj('reg_wphone_error');	
    obj1 = (obj1.style) ? (obj1.style):obj1;
    obj2 = (obj2.style) ? (obj2.style):obj2;
	if (validateTextField2('ctl00_ContentPlaceHolder1_AddEnquiry1_tbHomePhone') || 
	    validateTextField2('ctl00_ContentPlaceHolder1_AddEnquiry1_tbWorkPhone'))
		isPhoneOk = true;
    
    if (!isPhoneOk)		
    {        
        obj1.display = "block";	
        obj2.display = "block";	
        isOK = false;
    }
    else
    {
        obj1.display = "none";	
        obj2.display = "none";	
    }				
	
	if (!validateTextField('ctl00_ContentPlaceHolder1_AddEnquiry1_tbEmail', 'reg_email_error1'))
		isOK = false;
		
	if (!validateEmail('ctl00_ContentPlaceHolder1_AddEnquiry1_tbEmail', 'reg_email_error2'))
		isOK = false;			
		
	return isOK;
}



function validateBuyGiftVoucher()
{
    var isOK  = true;
    	
	if (!validateTextField('ctl00_ContentPlaceHolder1_BuyGiftVoucher1_tbName', 'reg_from_error'))
		isOK = false;
		
	if (!validateTextField('ctl00_ContentPlaceHolder1_BuyGiftVoucher1_tbEmail', 'reg_email_error1'))
		isOK = false;
		
	if (!validateEmail('ctl00_ContentPlaceHolder1_BuyGiftVoucher1_tbEmail', 'reg_email_error2'))
		isOK = false;	
				
	if (!validateTextField('ctl00_ContentPlaceHolder1_BuyGiftVoucher1_tbPhoneNumber', 'reg_phone_error'))
		isOK = false;
    		
	if (!validateTextField('ctl00_ContentPlaceHolder1_BuyGiftVoucher1_tbRecipientName', 'reg_recipient_error'))
		isOK = false;	
	
	if (!validateRadioButtonList('aspnetForm', 'ctl00$ContentPlaceHolder1$BuyGiftVoucher1$rblProducts', '', 'reg_products_error', ''))
	    isOK = false;
		
	return isOK;
}
