﻿// JScript File

// 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;
}


