//****************************************************************
// Created By 			:Nayan Rakholiya
// Created Date			:19/01/2007
// Last Modified Date	:20/01/2007
// Page Description		:Collection Of Common Javascript Functions
//*****************************************************************



//**************** Digit Function**********************
// This Function Allows Only Digits (0-9) in Textbox.
//******************************************************

function digit(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		return false;
	}
	return true;
}

//******************* Instruction For Implementation ********************
//write this in your textbox tag : onkeypress="return digit(event)"
//***********************************************************************

//**************** Digit Function End **********************


//**************** Digit Function 1**********************
// This Function Allows Only Digits (0-9) and . in Textbox.
//******************************************************


function digit1(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && charCode != 46 && (charCode < 48 || charCode > 57))
	{
		return false;
	}
	return true;
}

//******************* Instruction For Implementation ********************
//write this in your textbox tag : onkeypress="return digit1(event)"
//***********************************************************************

//**************** Digit Function 1 End **********************




//**************** Alpha Function**********************
// This Function Allows Only Alphabets (A-Z and a-z and blank space) in Textbox.
//******************************************************

function alpha(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode!=32 && (charCode < 65 || charCode > 90)&&(charCode < 97 || charCode > 122))
	{
		return false;
	}
	return true;
}

//******************* Instruction For Implementation ********************
//write this in your textbox tag : onkeypress="return alpha(event)"
//***********************************************************************

//**************** Alpha Function End **********************


//**************** Alphanumeric Function**********************
// This Function Allows Only Alphabets (A-Z and a-z and blank space) and Digits (0-9) in Textbox.
//******************************************************

function alphanumeric(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if ( charCode!=32 &&(charCode < 48 || charCode > 57) && (charCode < 65 || charCode > 90 ) && (charCode < 97 || charCode > 122))
	{
		return false;
	}
	return true;
}


//******************* Instruction For Implementation ********************
//write this in your textbox tag : onkeypress="return alphanumeric(event)"
//***********************************************************************

//**************** Alphanumeric Function End **********************


//**************** Email Function**********************
// This Function Valifdates Email address in textbox
//******************************************************
function email(obj)
{
	if(obj.value!="")
	{
		var email,AtPos,StopPos,Message
		email = obj.value
		AtPos = email.indexOf("@")
		StopPos = email.lastIndexOf(".")
		Message = ""		
		if (AtPos == -1 || StopPos == -1) 
		{
			Message = "Not a valid email address"
		}
		if (StopPos < AtPos) 
		{
			Message = "Not a valid email address"
		}
		if (StopPos - AtPos == 1) 
		{
			Message = "Not a valid email address"
		}
		if (Message!="")
		{
			alert(Message);
			obj.focus();
			return(false);
		}
	}
}


//******************* Instruction For Implementation ********************
//write this in your textbox tag : onBlur="return email(this)"
//***********************************************************************

//**************** Email Function End **********************


//**************** New Window **********************
// This Function Opens newwindow
//******************************************************

var win = null;
function NewWindow(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=0,status=0'
	win = window.open(mypage,myname,settings)
}

//******************* Instruction For Implementation ********************
//write this :javascript:NewWindow('page link','page title',800,600,1)
//***********************************************************************

//**************** New window Function End **********************

//**************** Check pincode **********************
// This Function Checks pincode
//******************************************************

//function pin(obj)
//{
//	if (obj.value.length<6 && obj.value.length!=0)
//	{
//		alert("Please Enter 6 Digit Number.");
//		obj.focus();
//		return (false);
//	}
//}

//******************* Instruction For Implementation ********************
//write this : onBlur="javascript:pin(this);"
//***********************************************************************

//**************** check pincode Function End **********************

//**************** website addresscheck **********************
// This Function validate website address
//******************************************************
function webcheck(obj)
{
	if(obj.value!="")
	{
		var email,AtPos,StopPos,Message
		email = obj.value
		AtPos = email.indexOf("www")
		StopPos = email.lastIndexOf(".")
		Message = ""
		if (AtPos == -1 || StopPos == -1 || http == -1) 
		{
			Message = "Not a valid Website address"
		}
		
		if (StopPos < AtPos) 
		{
			Message = "Not a valid Website address"
		}
		if (StopPos - AtPos == 1) 
		{
			Message = "Not a valid Website address"
		}
		if (Message!="")
		{
			alert(Message);
			obj.focus();
			return(false);
		}
	}
}
//******************* Instruction For Implementation ********************
//write this :javascript:onBlur="return webcheck(this)"
//set value="http://" of your textbox
//***********************************************************************
//**************** webcheck Function End **********************



//**************** uppercase ***************************
// This Function converts all characters to uppercase
//******************************************************

function uppercase(obj)
{
	obj.value=obj.value.toUpperCase();
}
//******************* Instruction For Implementation ********************
//write this :javascript:onKeyup="uppercase(this);"
//***********************************************************************



//**************** Maxlength in textarea ***************************
// This Function sets maxlength of text area
//******************************************************
function maxlength(obj,obj1)
{
	if(obj.value.length>obj1)
	{
		obj.value=obj.value.substring(0, obj1);	
	}
}
//******************* Instruction For Implementation ********************
//write this :javascript:onKeypress="maxlength(this,5);"
//***********************************************************************


