/*
This file includes all the functions which are often used,  as mentioned below 

the following is the description of the functions created in javascript 

takes text obj name as a param and msg to display, check for the numberic value 
function isnumberc(obj,msg) 

takes text obj name as a param and msg to display, check for the non-numberic value
function isnotnumberc(obj,msg)

takes text obj name as a param and msg to display, check for the blank value
function isblank(obj,msg)

takes listbox object name as a param and error msg to display, checks for the value = 0 means nothing is selected
function isselected(obj,msg)

checks for the checkbox checked or not , returns false when not checked 
function ischecked(obj,msg)

date function 
function isdate(dd,mm,yyyy)

takes obj name and num as para 
function putcomma(obj,num){

function replacesubstring( originalString , searchForString , replaceWithString )

takes 3 parameters the 3rd is checks for the special character , words param can be true/false , if true means there can be many words in a field and space is allowed
function chkspchar(obj,msg,words)

*/

//takes text obj name as a param and msg to display, check for the numberic value
function isnumberc(obj,msg)
{
var o = eval("document.form1." + obj)
val = o.value
val =  val.replace(/\s+/g,'')						//trims the spaces  
	if((isNaN(val)) || (val.length < 1))	
	{
		alert(msg)
		o.focus()
		o.select()	
		flag = false
	}
	else
		flag = true	
}

//takes text obj name as a param and msg to display, check for the non-numberic value
function isnotnumberc(obj,msg)
{
	var o = eval("document.form1." + obj)
	if(!isNaN(o.value)) 
	{
		alert(msg)
		o.focus()
		o.select()	
		flag = false
	}
	else
	{
		flag = true	
	}
}

// takes text obj name as a param and msg to display, check for the blank value
function isblank(obj,msg)
{
		var o = eval("document.form1." + obj)
		val = o.value

		val =  val.replace(/\s+/g,'')
		if((val == "") || (val.length < 1)) 	
		{
			alert(msg)
			o.focus()
			o.select()	
			flag = false
		}
		else
		{
			flag = true 
		}
}

// takes text obj name as a param and returns true or false, but doesn't display any msg, check for the blank value
function isblankNM(obj)
{
		var o = eval("document.form1." + obj);
		val = o.value;

		val =  val.replace(/\s+/g,'');
		if((val == "") || (val.length < 1)) 	
		{						
			//flag = false;
			return true;
		}
		else
		{
			//flag = true ;
			return false;
		}
}

// this takes listbox object name as a param and error msg to display , returns false if the value is 0 or null
//value = 0 means nothing is selected
function isselected(obj,msg)
{
	var o = eval("document.form1." + obj)
	
	if (o.length==0)
		{ flag = false; alert(msg); return;}
	else
		{ 
			if((o.options[o.selectedIndex].value == "0") 	|| (o.options[o.selectedIndex].value == ""))
			{
				alert(msg)
				o.focus()
				flag = false
			}
			else
				flag = true	
		}
}


//// this takes listbox object name as a param and  returns false if the value is 0 or null
//does NOT display error message
function isselectedNM(obj)
{
	var o = eval("document.form1." + obj)
	if (o.length==0)
		{ flag = false; return;}
	else
		{ 
			if((o.options[o.selectedIndex].value == "0") 	|| (o.options[o.selectedIndex].value == ""))
			{
				o.focus()
				flag = false
			}
			else
				flag = true;	
		}
}

//date function 
function isdate(dd,mm,yyyy) {
	var dat=dd;
	var mon=mm;
	var yer=yyyy;
	
	if (dat == 0 || mon == 0 || yer == 0) 
	{	return false; }
	else
	{		
	switch (mon) {
		case '2':
			if ((yer%4==0) && (dat > 29)) 
			{   return false; }

			else if ((yer%4>0) && (dat > 28)) 
			{   return false; }
			else
			{   return true; }

			break;
		case '4':
		case '6':
		case '9':
		case '11':
			if (dat>30) 
			   return false; 
			else
				return true;

			break;
		default :
			return true;
	}
	}	
} 

//takes obj name and num as para and format the numeric data with commas e.g. 100,000
function putcomma(obj,num){
var tmpNumStr = replacesubstring(num,",","")

if(!isNaN(tmpNumStr))
{
	if ((num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}
}

	x = eval("document.form1." + obj )
	x.value = tmpNumStr
}

function replacesubstring(originalString , searchForString , replaceWithString ){
var reg = /,/
	if(reg.test(originalString))
	{
		var objRegExp = eval( "/" + searchForString + "/g" );
		return (originalString.replace( objRegExp , replaceWithString ) );
	}
	else
		return  originalString
}


//function with 3 parameters, checks for the special character, words param can be true/false , if true means there can be many words in a field and space is allowed
function chkspchar(obj,msg,words)
{
flag = true 
var obj = eval("document.form1." + obj)
var objval =  obj.value
	for(i=0;i<objval.length;i++)
	{					
	  if(words=="false")		//also checks for the space char
	  {		
		keycode=objval.charCodeAt(i)
		if (((keycode<65) || (keycode>90)) && ((keycode<97) || (keycode>122)) && ((keycode<48) || (keycode>57)) )   
		{
			alert(msg)
			obj.focus()
			obj.select()
			flag = false
			i = objval.length
		}
	  }
	  else 				//words ="true"	 ignores for the space char
	  {	
		keycode=objval.charCodeAt(i);
		if (((keycode<65) || (keycode>90)) && ((keycode<97) || (keycode>122)) && ((keycode<48) || (keycode>57)) && (keycode!=32))   
		{
			alert(msg)
			obj.focus()
			obj.select()
			flag =  false
			i = objval.length
		}
	  }				 
	}
}


//this function cheks for the special character (not currently used)
function chkspcharx(obj,msg)
{
var obj = eval("document.form1." + obj)
var objval =  obj.value
	for(i=0;i<objval.length;i++)
	{					
		keycode=objval.charCodeAt(i);
		if (((keycode<65) || (keycode>90)) && ((keycode<97) || (keycode>122)) && ((keycode<48) || (keycode>57)) )   
		{
			alert(msg);
			obj.focus();
			obj.select();
			return false;
		} 
	}
			return true;	
}

//this funtion is used to set the taax to the statue bar. 
function showstatus()
{
	window.status = "Tata - Mutual Fund"
}

if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);

//on mouse click event calling the function showstatus
document.onmousemove=showstatus;
document.onmouseover=showstatus;

// function to check email validation

function check_email(thisField)
{
	var thisField = eval("document.form1." + thisField)
	if (thisField.value.indexOf('@') == -1 ) 
	{
		alert('Please enter valid e-mail ID');
		thisField.focus();
		thisField.select();
		flag=false;
	}	
	else if(thisField.value.substring(thisField.value.indexOf('@')+2).indexOf('@') >= 0||
		thisField.value.substring(thisField.value.indexOf('@')+2).indexOf('.') < 0 ) 
	{
			alert('Please enter valid e-mail ID');
			thisField.focus();
			thisField.select();			
			flag=false;
	}
	else if(thisField.value.charAt(thisField.value.length - 1) == '.') 
	{
			alert('Please enter valid e-mail ID');
			thisField.focus();
			thisField.select();			
			flag=false;
	}
	else
		flag=true;
}


function chk_alpha_numeric(obj,msg)
{
	
	var obj = eval("document.form1." + obj)
	var objval =  obj.value

	var has_chars = false
	var has_nos = false

	for(i=0;i<objval.length;i++)
	{					
		keycode=objval.charCodeAt(i);
		if (((keycode>=65) && (keycode<=90)) || ((keycode>=97) && (keycode<=122))  )   
			{
				has_chars = true
			} 
	}

	for(i=0;i<objval.length;i++)
		{
			keycode=objval.charCodeAt(i);
			if ( (keycode>=48) && (keycode<=57) )
				{
					has_nos = true
				}
		}

	if (has_chars == true && has_nos == true)
		{
			flag = true
		}	
	else
		{
			alert(msg);
			obj.focus();
			obj.select();
			flag = false
		}			   

}

function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}
