/*
Function Name	:	descOver()
Descriotion	:	It displays passed message in the <div> named as CaptionTitle specified in the include file. So that
			it gives effect like information getting updated for each and every image or link.
Argument		:	Input - Message (message to get displayed in div)
*/
function descOver(Message)
{

	//document.getElementById('CaptionTitle').innerHTML = Message;
}

/*'**************************************************************************************'
'* Function		- Validation
'* Description	- This is an object created using javascript with 9 various methods
'* Methods 		- There are seven methods associated with this object.
'**************************************************************************************'*/
function Validation()
{
	this.isNull = isNull;
	this.isNumeric = isNumeric;
	this.isNumericwodot=isNumericwodot;
	this.trim = trim;
	this.isValidEmail = isValidEmail;
	this.isValidDate = isValidDate;
	this.checkAll = checkAll;
	this.isChecked = isChecked;
	this.iscboSelected = iscboSelected;
	this.isoptSelected = isoptSelected;
	this.isoptSelectedSpl = isoptSelectedSpl;
	this.isNumericWithSpace = isNumericWithSpace;
	
}
/*'**************************************************************************************'
'* Function		- isoptSelected(opt)
'* Args.		- opt 	- The name of the radio button
				
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function isoptSelectedSpl(opt)
{
	if(opt.checked == false)
	{
		return false;	
	}
	else
	{
		return true;
	}

}


function isoptSelected(opt,msg)
{
	if(opt.checked == false)
	{
		alert(msg)
		opt.focus();
		return false;	
	}
	else
	{
		return true;
	}

	
}

/*'**************************************************************************************'
'* Function		- isoptSelected(cbo, msg)
'* Args.		- opt 	- The name of the radio button
				- msg	- A string which would be displayed in alert if MyString
'						  is empty one.
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function iscboSelected(cbo,msg)
{
	if(cbo.selectedIndex == 0)
	{
			alert(msg)
			cbo.focus();
			return false;	
	}
	else
	{
		return true;
	}
	
}


/*'**************************************************************************************'
'* Function		- isNull(MyString, msg)
'* Args.		- MyString 	- A string which would be checked.
			- msg		- A string which would be displayed in alert if MyString
'					  is empty one.
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function isNull(MyString, msg)
{
			var retflag=true;
			if (MyString.value == "")
			{
				alert(msg);
				MyString.select();
				MyString.focus();
				retflag=true;
				return(retflag);
			}
			else
			{
				var blank = true;
				var textlength = MyString.value.length;
				for (var i=0;i<textlength;i++)
				{
					var theChar = MyString.value.substring(i, i+1);
					if ((theChar < "0" || theChar > "9") && (theChar < "a" || theChar > "z") && (theChar < "A" || theChar > "Z"))
					{
						if (theChar != " ")
						{
							blank = false;
							break;
						}
					}
					else
					{
						blank = false;
					}
				}		
				if (blank)
				{
					alert(msg);
					MyString.select();
					MyString.focus();
					retflag = true;
					return(retflag) ;
				}
			
	}	
}
//**************************************************************************************

/*
'**************************************************************************************'
'* Function		- isNumeric(MyString, msg)
'* Args.		- MyString 	- A string which would be checked.
			- msg		- A string which would be displayed in alert if MyString
'					  contains characters other than Numeric.
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/

function isNumeric(MyString,msg)
{
	if(!(isNaN(MyString.value)))
	{
		return true;
	}
	else
	{
		alert(msg)
		MyString.select();
		MyString.focus();
		return false;
	}
}

function isNumericwodot(MyString,msg)
{
	if (MyString.value == "")
	{
		alert(msg);
		MyString.focus();
		return false;
	}
	else
	{
		var goodqty = true;
		var qtylength = MyString.value.length;
		
		for (var i=0;i<qtylength;i++)
		{
			var theChar = MyString.value.substring(i, i+1);
			if (theChar < "0" || theChar > "9")
			{
				goodqty = false;
			}
		}		
		if (goodqty == false)
		{
			alert(msg);
			MyString.focus();
			return false;
		}
	}
}

//**************************************************************************************


/*
'**************************************************************************************'
'* Function		- trim(field_name)
'* Args.		- field_name- A string which needs to get left trimmed.
'* Return Value 	- It returns a string after having left trimmed.
'**************************************************************************************'*/
function trim(field_name)
{
	pos = field_name.indexOf(" ")
	while (pos == 0) 
	{ 
		field_name = field_name.substring(1)
		pos = field_name.indexOf(" ")
	}
	
	len = field_name.length
    blank = field_name.charAt(len-1)
    while (blank == " " )
    {
      field_name = field_name.substring(0,len-1)
      len=field_name.length
      blank = field_name.charAt(len-1)
    }
    
	//rtrim(field_name)
	return field_name
}

/*
'**************************************************************************************'
'* Function		- allTrim(field_name)
'* Args.		- field_name- A string which needs to get trimmed.
'* Return Value 	- It returns a string after having trimmed.
'**************************************************************************************'*/

function allTrim(strName)
{
	
	var len=strName.length
	var temp
	var str=""
	for(i=0;i<len;i++)
		{
			temp=strName.substring(i,i+1)
			if(temp!=" ")
				{
					str=str+temp
				}	
		}
	
	return str
}

/*
'**************************************************************************************'
'* Function		- isValidEmail(Email,msg) 
'* Args.		- Email - A string which would be checked whether it can be worked as 
'						  an email address.
				- msg   - A string which is displayed if the given mail address is not a 
						  valid email address
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function isValidEmail(Email,msg) {
   pos1 = Email.indexOf("@");
   len = Email.length;
   if ((pos1 <= 0 ) || (pos1 == (len - 1))) {
		alert(msg)
		return false;
   } else {
	   pos1 = Email.indexOf(".");
	   len = Email.length;
	   if ((pos1 <= 0 ) || (pos1 == (len - 1))) {
			alert(msg);
   		return false
	   }
   }
   
	return true;	
}
//**************************************************************************************

/*
'**************************************************************************************'
'* Function		- isValidDate(CDate)
'* Args.		- CDate - A string which would be checked whether it is a valid date or not.
				
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function isValidDate(dtCDate)
{
	//This will replace all the blank value from the dtCDate variable
	//and replace it into the CDate variable
	
	var CDate=allTrim(dtCDate)
	
	// Date's length should be 10 characters....
	if (CDate.length != 10)
	{
		return false;
	}
	
	var ValidInputs = true;
	var InputLength = CDate.length;
		
	for (var i=0;i<InputLength;i++)
	{
		var theChar = CDate.substring(i, i+1);
		if (theChar < "0" || theChar > "9")
		{
			if (theChar != "/")
			{
				ValidInputs = false;
			}
		}
	}		
	
	if (ValidInputs == false)
	{
		return false;
	}
	
	
	// Date should contain 2 "/"s and it should be at the position of 3 and 6 only...
	if (CDate.substring(3,2) != "/" || CDate.substring(6,5) != "/")
	{
		return false;
	}
	
	//Taking Day, Month and Year into mem variables...
	var Day, Month, Year;
	Month = CDate.substring(2,0);
	Day = CDate.substring(5,3);
	Year = CDate.substring(10,6);

	// Month having value more than 12 is not valid one...
	if (Month > 12 || Day == 0 || Day == 00 || Month == 0 || Month == 00 || Year == 0000)
	{	
		return false;		
	}
	
	//Checking month and its days....
	if (Year%4 == 0)
	{
		if (Month == 2 && Day > 29)
		{
			return false;
		}
	}
	else
	{
		if ((Month == 2 && Day > 28))
		{
			return false;
		}
	}
	
	if ((Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) && Day > 31)
	{
		return false;
	}
	
	if ((Month == 4 || Month == 6 || Month == 9 || Month == 11) && Day > 30)
	{
		return false;
	}
	
	if(isNaN(Month))
	{
		return false;
	}
	
	if(isNaN(Day))
	{
		return false;
	}
	
	if(isNaN(Year))
	{	
		return false;
	}	
	
	return true;
	
}
//**************************************************************************************


/*
function newNumericCheck()
{

var goodqty = true
var qtylength = MyString.value.length
		
for (var i=0;i<qtylength;i++)
{
	var theChar = MyString.value.substring(i, i+1)
	if (theChar < "0" || theChar > "9")
	{
		if (theChar != ".")
		{
			goodqty = false
					
		}
	}
}		
if (goodqty == false)
{
	alert(msg)
	MyString.select()
	return false
}

}
*/

/*'**************************************************************************************'
'* Function		- checkAll(main,sub)
'* Args.		- main	- The chkbox which when checked will check all the 
						  checkboxes. 	
			    - id - This should be the  chkbox id which will be checked.It should 
						  be a common name for all the checkboxes to be checked 
		
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function checkAll(main,id)
{
	chk = document.all.item(id)
	if(main.checked == true)
	{
		for(i=0;i<chk.length;i++)
		{
			chk[i].checked = true
		}	
	}
	else
	{
		for(i=0;i<chk.length;i++)
		{
			chk[i].checked = false
		}	
	
	}

}

//**************************************************************************************
/*'**************************************************************************************'
'* Function		- checkAll(main,sub,msg)
'* Args.		- main	- The chkbox which when checked will check all the 
						  checkboxes. 	
			    - id   - The chkbox which will be checked.It should be a
						  common name for all the checkboxes to be checked 
			    - msg	- A string which would be displayed in alert if not even one 
						  checkbox is checked
'							
'* Return Value 	- It returns a boolean value.
'**************************************************************************************'*/
function isChecked(main,id,msg)
{
chk = document.all.item(id)
checked = false
	if(chk.length > 1)
	{
		for(i=0;i<chk.length;i++)
		{
			if(chk[i].checked == true)
			{
				checked = true
			}
		}
		
		if(!checked)
		{
			alert(msg)
			return false;
		
		} 
	
	}
	else
	{
		if(sub.checked == false)
		{
			alert(msg)
			sub.focus();
			return false;
		}
	}
	

}


function isNumericWithSpace(MyString,msg)
{
	if (MyString.value == "")
	{
		alert(msg);
		MyString.focus();
		return false;
	}
	else
	{
		var goodqty = true;
		var qtylength = MyString.value.length;
		
		for (var i=0;i<qtylength;i++)
		{
			var theChar = MyString.value.substring(i, i+1);
			if (theChar < "0" || theChar > "9")
			{
				if (theChar != " ")
				{
					goodqty = false;
				}
			}
		}		
		if (goodqty == false)
		{
			alert(msg);
			MyString.focus();
			return false;
		}
	}
	return true;
}

/*'**************************************************************************************'
'* Function		- ChangeOver(strImageName,strImagePath)
'*				- ChangeOut(strImageName,strImagePath)
'* Args.		-strImageName: Name Attribute of the Image Tag
				-strImagePath: Path of the Image

'**************************************************************************************'*/


function ChangeOver(strImageName,strImagePath)
	{	
		document.images[strImageName].src=strImagePath
	}
			
function ChangeOut(strImageName,strImagePath)
	{	
		document.images[strImageName].src=strImagePath
	}	
			
	
	