
//********************************************************************
//allows alphabets, numbers, underscore
//********************************************************************
function isAlphaNumeric(txtObj)
{   
	var str = txtObj.value;   
	// Return false if name field is blank.   
	if (str == "")
	{   
		alert("\nThis field is blank.\n\nPlease enter the value.")      
		txtObj.focus();      
		return false;      
	}   
	for (var i = 0; i < str.length; i++)
	{      
		var ch = str.substring(i, i + 1);      
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && ch != '_' && ch !=' ')
		{         
			alert("\nThis field accepts only alphabets, numbers & underscore.\n\nPlease re-enter !!.");
			txtObj.select();         
			txtObj.focus();         
			return false;      
		}      
	}   
}
//********************************************************************


//********************************************************************
//allows alphabets, space, dot, comma
//********************************************************************
function isText(txtObj)
{   
	var str = txtObj.value;   
	// Return false if name field is blank.   
	if (str == "")
	{   
		alert("\nThis field is blank.\n\nPlease enter the value.")      
		txtObj.focus();      
		return false;      
	}   
	// Return false if characters are not a-z, A-Z, or a space and a dot.   
	for (var i = 0; i < str.length; i++)
	{      
		var ch = str.substring(i, i + 1);      
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' && ch != '.' && ch != ',')
		{         
			alert("\nThis field accepts only alphabets, comma, dot & spaces.\n\nPlease re-enter !!.");
			txtObj.select();         
			txtObj.focus();         
			return false;      
		}      
	}   
}
//********************************************************************


//********************************************************************
//allows alphabets only
//********************************************************************
function isAlphabet(txtObj)
{   
	var str = txtObj.value;   
	// Return false if name field is blank.   
	if (str == "")
	{   
		alert("\nThis field is blank.\n\nPlease enter the value.")
		txtObj.focus();      
		return false;      
	}   
	// Return false if characters are not a-z (or) A-Z.   
	for (var i = 0; i < str.length; i++)
	{      
		var ch = str.substring(i, i + 1);      
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))
		{         
			alert("\nThis field accepts only alphabets.\n\nPlease re-enter !!.");
			txtObj.select();         
			txtObj.focus();         
			return false;      
		}      
	}   
}
//********************************************************************




//********************************************************************
//	Function for Email Address validation
//********************************************************************
function isEmail(mailfield)
{
	var mail=mailfield.value
	// Looking for a @,.//Looking for @ in the last position//looking for . in the first position
	if (mail.indexOf("@") == -1 || mail.indexOf("@")+1 == mail.length || mail.indexOf(".") == -1 || mail.indexOf(".")+1 == mail.length  || mail.substring(0,1) == ".")
 	{
 		 	alert("Invalid Email ID")
			mailfield.focus()
			mailfield.select()
     		return false;
		}
 		else
 		{
			//looking for . just before & after @		//looking for @ for the first position
			var n = mail.indexOf("@")
			var n1 = mail.indexOf(".",n)
 		 	var n2 = mail.lastIndexOf(".",n)
			if(n+1 == n1 || n-1 == n2)
 		 	{
 		 		alert("Invalid Email ID")
				mailfield.focus()
				mailfield.select()
				return false;
	 		}
	 	}
		//Looking for two consecutive .'s		//Looking for special characters
		var k=0
 		for(var j=0;j<mail.length;j++)
 		{
			if((mail.substring(j,j+1) >= 'a' && mail.substring(j,j+1) <= 'z') || (mail.substring(j,j+1) >= 'A' && mail.substring(j,j+1) <= 'Z') || (mail.substring(j,j+1) >= '0' && mail.substring(j,j+1) <= '9') || mail.substring(j,j+1) == '.' || mail.substring(j,j+1) == '@' || mail.substring(j,j+1) == '_')
 		 	{}
 		 	else
 		 	{
 		 		alert("Invalid Email ID")
				mailfield.focus()
				mailfield.select()
				return false;
			}
			if(mail.substring(j,j+1) == ".")
			{
				if(k+1 == j && j!=1)
				{
 		 			alert("Invalid Email ID")
					mailfield.focus()
					mailfield.select()
					return false;		
				}
				k = j
			}	
		}
		// looking for .,@ at the last position
		if(mail.lastIndexOf(".")+1 == mail.length || mail.lastIndexOf("@")+1 == mail.length)
		{
 		 	alert("Invalid Email ID")
			mailfield.focus()
			mailfield.select()
			return false;
		}
		//looking for more than one @
		if(mail.indexOf("@") != mail.lastIndexOf("@"))
		{
 		 	alert("Invalid Email ID")
			mailfield.focus()
			mailfield.select()
			return false;
		}
}
//********************************************************************



//********************************************************************
//allows numbers and dot
//********************************************************************
function isNumber(txtObj)
{
	var x=txtObj.value
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x))
		return true
	else
	{
		alert("Please input a valid number!")
		txtObj.focus()
		txtObj.select()
		return false
	}
}
//********************************************************************


//********************************************************************
//allows numbers only
//********************************************************************
function isOnlyNumber(txtObj)
{
	for (var i = 0; i < txtObj.value.length; i++)
	{      
	var ch = txtObj.value.substring(i, i + 1);      
	if (ch < "0" || "9" < ch)
	{
		alert("Please input a valid number!")
		txtObj.focus()
		txtObj.select()
		return false
	}
	}
}
//********************************************************************


//********************************************************************
//allows alphabets, numbers & underscore
//checks for identity in the given two password fields
//********************************************************************
function isPassword(objpw1,objpw2)
{
	pw1 = objpw1.value;
	pw2 = objpw2.value;
	for (var i = 0; i < pw1.length; i++)
	{      
		var ch = pw1.substring(i, i + 1);      
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && ch != '_')
		{
			alert("\nThis field accepts only alphabets, numbers and underscore.\n\nPlease re-enter...");
			objpw1.focus();         
			objpw1.select();         
			return false;      
		}      
	}  
	if (pw1.length < 4)
	{
		alert("Password should be alteast 4 characters")
		objpw1.focus()
		objpw1.select()
		return false;
	}
	for (var i = 0; i < pw2.length; i++)
	{      
		var ch = pw2.substring(i, i + 1);      
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && ch != '_')
		{
			alert("\nThis field accepts only alphabets, numbers and underscore.\n\nPlease re-enter...");
			objpw2.focus();         
			objpw2.select();         
			return false;      
		}      
	}  
	if (pw1 != pw2)
	{
		alert ("\nPassword should be same. Please re-enter your password.")
		objpw2.focus()
		objpw2.select()
		return false;
	}
}





//********************************************************************
//allows alphabets, numbers & underscore
//checks for identity in the given two password fields
//********************************************************************
function isPassword1(objpw1)
{
	pw1 = objpw1.value;
	for (var i = 0; i < pw1.length; i++)
	{      
		var ch = pw1.substring(i, i + 1);      
		if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && ch != '_')
		{
			alert("\nThis field accepts only alphabets, numbers and underscore.\n\nPlease re-enter...");
			objpw1.focus();         
			objpw1.select();         
			return false;      
		}      
	}  
	if (pw1.length < 4)
	{
		alert("Password should be alteast 4 characters")
		objpw1.focus()
		objpw1.select()
		return false;
	}
}



//********************************************************************
//Function to trap all the special characters listed below
//********************************************************************
function isValue(txtObj)
{
	str = "@#$%^`~'|?"
	val = txtObj.value
	for (i=0;i<=val.length-1;i++)
		{
		ch = val.substring(i,i+1)
		if (str.indexOf(ch)>-1)
			{
			alert(ch + "   is not allowed");
			txtObj.focus();
			txtObj.select();
			return false;	
			}
		}
}
//********************************************************************




//********************************************************************
//Function to check trailing spaces and leading spaces
//********************************************************************
function isTrimmed(txtObj) {

// This function will trim leading and/or trailing spaces from a string
// arg = the value you wish to have trimmed..
// func = "left" for Ltrim(), "right" for RTrim() or "both" for Trim()

//alert(txtObj.name)
var arg,func
arg = txtObj.value
func = "both"
var trimvalue = "";
arglen = arg.length;

//alert(arg)
if (func == "left" || func== "both") {
i = 0;
pos = -1;
while (i < arglen) {
if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
pos = i;
break;
}
i++;
}
}

if (func == "right" || func== "both") {
var lastpos = -1;
i = arglen;
while (i >= 0) {
if (arg.charCodeAt(i) != 32 && !isNaN(arg.charCodeAt(i))) {
lastpos = i;
break;
}
i--;
}
}

if (pos!=0)
	{
	alert("Remove the leading spaces")
	txtObj.focus()
	txtObj.select()
	return false
	}

if (lastpos!=arglen-1)
	{
	alert("Remove the trailing spaces")
	txtObj.focus()
	txtObj.select()
	return false
	}
}
//********************************************************************


//********************************************************************
// Date Validation Version 2 (both month and year should be in combo).
//********************************************************************
function isDate(df,mf,yf)
{
	if (mf.options[mf.selectedIndex].value=="###")
	{
		alert("Please Select the Month");
		mf.focus();
		return false;
	}
	if (df.options[df.selectedIndex].value=="###")
	{
		alert("Please Select the Day");
		df.focus();
		return false;
	}
	if (yf.options[yf.selectedIndex].value=="###") 
	{
		alert("Please Select the Year");
		yf.focus();
		return false;
	}
	if (yf.options[yf.selectedIndex].value>=0)
		{	i=0	}
	else
		{	i=1	}
	yy = yf.options[yf.selectedIndex].value
	mm = mf.options[mf.selectedIndex].value
	dd = df.options[df.selectedIndex].value
	le = yy%4
	mo = mm%2

	if(mm > 12) 
	{
		alert("Invalid Month")
		mf.focus()
		return false
	}
	else 
	{
		if(mo==0)
		{
			if(mm==2)
			{
				if (le == 0)
				{
					if(dd>29)
					{
						alert("Invalid Date")
						df.focus()
						return false
					}
				}
				else
				{
					if(dd>28)
					{
						alert("Invalid Date")
						df.focus()
						return false
					}				
				}
			}
			if(mm==8 || mm==10 || mm==12)
			{
				if(dd>31)
				{
					alert("Invalid Date")
					df.focus()
					return false
				}
			}
			else
			{
				if (dd>30)
				{
					alert("Invalid Date")
					df.focus()
					return false
				}
			}
		}
		else		//if mm = 1
		{
			if (mm == 9 || mm == 11)
			{
				if(dd>30)
				{
					alert("Invalid Date")
					df.focus()
					return false
				}
			}
			else
			{
				if (dd>31)
				{
					alert("Invalid Date")
					df.focus()
					return false
				}
			}
		}	
	}
}	
//********************************************************************


//********************************************************************
//Function for phone number validation
//********************************************************************
function isPhone(txtObj)
{
	str = "0123456789+,-()"
	val = txtObj.value
	for (i=0;i<=val.length-1;i++)
		{
		ch = val.substring(i,i+1)
		if (str.indexOf(ch)>-1)
			{}
		else
			{
			alert("Enter a valid Phone Number\n");
			txtObj.focus();
			txtObj.select();
			return false;	
			}
		}
}
//********************************************************************


//********************************************************************
//Function for fax number validation
//********************************************************************
function isFax(txtObj)
{
	str = "0123456789+,-()"
	val = txtObj.value
	for (i=0;i<=val.length-1;i++)
		{
		ch = val.substring(i,i+1)
		if (str.indexOf(ch)>-1)
			{}
		else
			{
			alert("Enter a valid Fax Number\n");
			txtObj.focus();
			txtObj.select();
			return false;	
			}
		}
}
//********************************************************************


//********************************************************************
//allows alphabets, numbers & underscore
//Function for User ID validation
//********************************************************************
function isUserID(txtObj)
{
var str = txtObj.value;
if((str.substring(0,1)<"a" || str.substring(0,1)>"z") && (str.substring(0,1)<"A" || str.substring(0,1)>"Z"))
	{
	alert("The Field should begin with an alphabetic character.");
	txtObj.focus();
	txtObj.select();
	return false;
	}
for (var i = 1; i < str.length; i++) 
	{
	var ch = str.substring(i, i + 1);
	if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_')) 
	{
	alert("\nThe field accepts letters,numbers & underscore.\n\nPlease re-enter");
	txtObj.focus();
	txtObj.select();
	return false;
	}
	}
}
//********************************************************************



//********************************************************************
// - can be used ISBN validation
//********************************************************************
function isISBN(txtObj)
{   
	var str = txtObj.value;   
	// Return false if name field is blank.   
	for (var i = 0; i < str.length; i++)
	{      
		var ch = str.substring(i, i + 1);      
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && ch != '-')
		{         
			alert("\nEnter Valid ISBN\n\nPlease re-enter !!.");
			txtObj.select();
			txtObj.focus();
			return false;
		}      
	}   
}
//********************************************************************


//********************************************************************
// - can be used to validate From .. To Date
//********************************************************************

function isFromToDate(od,om,oy,cd,cm,cy)
{
//alert(od+"\n"+om+"\n"+oy)
//alert(od+"\n"+om+"\n"+oy)

	if(oy<cy)
		{}
	else if(oy==cy)
		{	return checkMonth(od,om,oy,cd,cm,cy)	}
	else
		{	return false	}

}

//********************************************************************
// - can be used to validate  Text Area length
//********************************************************************

function txtAreaLen(txtObj,txtLen)
		{
			
			objValue=txtObj.value
		if (objValue.length >txtLen)
		{
			alert(" The Value You Have Given Should Not Exceed the Limit.\n\n It Allows Only "+txtLen+" Char")
			txtObj.focus();
			
				  
		  return false
		  		}
			}   
		
		
//********************************************************************
// - can be used to validate  Text Area length
//********************************************************************

function IstxtAreaLen(txtObj,txtLen)
		{
			
		objValue=txtObj.value
		if (objValue.length >txtLen)
		{
			alert(" The Value You Have Given Should Not Exceed the Limit.\n\n It Allows Only "+txtLen+" Char")
			txtObj.focus();
			
				  
		  return false
		  		}
			}   
		
//****************************************************************************************		
		//Function for Address validation
		//Accepts only Alphabets, Numbers, Comma, Hyphen, Dot, Slash & Spaces.
//***************************************************************************************		
		
function isAddress(txtObj)

{   
	var str = txtObj.value;   
	// Return false if name field is blank.   
	if (str == "")
	{   
		alert("\nThis field is blank.\n\nPlease enter the value.")      
		txtObj.focus();      
		return false;      
	}   
	// Return false if characters are not a-z, A-Z, 0-9 or a space and a dot.   
	for (var i = 0; i < str.length; i++)
	{      
		var ch = str.substring(i, i + 1);      
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && ch != ' ' && ch != '.' && ch != ',' && ch != '-' && ch != '/')
		{  
		
		    alert(ch + "   is not allowed");   
			//alert("\nThis field accepts only Alphabets, Numbers, Comma, Hyphen, Dot, Slash & Spaces.\n\nPlease Re-Enter !!.");
			txtObj.select();         
			txtObj.focus();         
			return false;      
		}      
	}   
}


function addimage(intImageID,mode)
{
//	alert(mode)
	var imagewin,style,filename;
	//filename = "fnaddimage222.asp?imgid="+intImageID+"&Mode="+mode+""
		filename = "upload.asp?imgid="+intImageID+"&Mode="+mode+""
	style="toolbar=no,height=250,width=300,top=150,left=200"
	imagewin = window.open(filename,"imagewin",style)
	imagewin.focus()
}
