function call_profile(usr_id,profile)
{
	var url = "";
	var theHeight=160;
	var theWidth=335;
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features= "dependant=yes,height="+theHeight+",width="+theWidth+",top="+theTop+",left="+theLeft+",scrollbars=yes,resizable=yes, scrollbars=no,menubar=no,toolbar=no,status=yes";
	url = "forum_profile.asp?usr_id="+usr_id+"&profile="+profile;
	theWin=window.open(url,'',features);
	theWin.location.reload(true);
}
function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}
function openWindow(url)
{	
	//var theHeight=260;
	var theHeight=322;
	var theWidth=700;
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features= "dependant=yes,height="+theHeight+",width="+theWidth+",top="+theTop+",left="+theLeft+",scrollbars=yes,resizable=no, scrollbars=no,menubar=no,toolbar=no,status=yes";
	theWin=window.open(url,'',features);
	theWin.location.reload(true);
}
function validateForm(objlist)
{	//alert("From messages.validateForm");
	// parsing validation specification line and alert if not valid.
	// else return true
	// String will be in the form of "document.myform.T1|M|C9"
	// ie. <Object Name><seperator><Manderory flag>
	//     where '|' is seperator
	
	seperator = '|';

	for( i = 0 ; i < objlist.length ; i++)
	{	specificstr = objlist[i] ;
		v =  specificstr.indexOf(seperator) ;
	   	objname		=	specificstr.substring( 0 , v ); // returns object name
		specificstr =	specificstr.substring( v+1 );	//Removing object name from speficstring 

		obj = eval ( objname ) ;
		objvalue = obj.value ;							// Get value of the object in 'objvalue'
		
		flag = true ;
		varlist = "";
		while(specificstr.length != 0)
		{	if(specificstr.indexOf(seperator) > -1)
			{	type		=	specificstr.substring( 0 , specificstr.indexOf(seperator) ); // Type of validation need to apply on the field
				specificstr	=	specificstr.substring( specificstr.indexOf(seperator)+1 );	
			}
			else
			{	type		=	specificstr	
				specificstr =	"" ;
			}
			//******** Validate field value according to type

			if(type == "M" && Number(objvalue) == 0)
			{	errno = "MSG000" ;
				flag = false ;
			}
			else if( type.charAt(0) == 'C' && objvalue.length > 0 )
			{	if(type.indexOf('-') > -1)
				{	min		=	Number(type.substring(2, type.indexOf('-')));   // C(1-12)
					max		=	Number(type.substring(type.indexOf('-')+1, type.indexOf(')')));   // C(1-12)
					if( objvalue.length < min ||  objvalue.length > max  )
					{	errno = "MSG004" ;
						flag = false ;
					}
					varlist = varlist + ":" + min + ":" + max ;					// set variable list to send to display function
				}
				else
				{	min		=	Number(type.substring(2, type.indexOf(')')));   // C(12)
					max		=	min ;
					if( objvalue.length < min ||  objvalue.length > max  )
					{	errno = "MSG007" ;
						flag = false ;
					}
					varlist = varlist + ":" + min ;					// set variable list to send to display function
				}
				
				
				
			}
			else if( type.charAt(0) == 'L' )
			{	varlist	=	varlist + ":" +type.substring(1); // each variable value is prefix by ':'
			}
			else if( type.charAt(0) == 'P' && objvalue.length > 0 )
			{	if(type.substring(1) == "EMAIL" && (! isValidEmail(objvalue)) )
				{	errno = "MSG005" ;
					flag = false ;
				}
			}
			/* Added by Rakesh to cater negative values */
			/* Commented
			else if( type.charAt(0) == 'Z' )
			{
			    myObjLength = type.charAt(1);
			    alert("inside mine length : "+myObjLength);
				if(  myObjLength != Number(myObjLength) )
				{	errno = "MSG006" ;
					flag = false ;
				}
			}
			*/
			/* Added by Rakesh to cater negative values */
			else if( type.charAt(0) == 'N' && objvalue.length > 0 )
			{	
				if(  objvalue != Number(objvalue) )
				{	errno = "MSG006" ;
					flag = false ;
				}
				else if(type.indexOf('-') > -1)
				{	min		=	Number(type.substring(2, type.indexOf('-')));   // C(1-12)
					max		=	Number(type.substring(type.indexOf('-')+1, type.indexOf(')')));   // C(1-12)
					if( Number(objvalue) < min ||  Number(objvalue) > max  )
					{	errno = "MSG011" ;
						flag = false ;
					}
					varlist = varlist + ":" + min + ":" + max ;					// set variable list to send to display function
				}
			}
			else if( type.charAt(0) == 'I' && objvalue.length > 0 )
			{	
				//alert( Number(objvalue) != parseInt(Number(objvalue))  );
				if(  objvalue != Number(objvalue) )
				{	errno = "MSG006" ;
					flag = false ;
				}
				else if(  Number(objvalue) != parseInt(Number(objvalue)) )
				{	errno = "MSG012" ;
					flag = false ;
				}
				else if(type.indexOf('-') > -1)
				{	min		=	Number(type.substring(2, type.indexOf('-')));   // C(1-12)
					max		=	Number(type.substring(type.indexOf('-')+1, type.indexOf(')')));   // C(1-12)
					if( Number(objvalue) < min ||  Number(objvalue) > max  )
					{	errno = "MSG011" ;
						flag = false ;
					}
					varlist = varlist + ":" + min + ":" + max ;					// set variable list to send to display function
				}
				
			}
			if(! flag )
			{	display( errno , varlist );
				obj.focus();
				return false ;
			}

		} // end of while()


	} // end  of for ()
	return true ;
}

//****************************************************************
//	Use this function to design/format the message
//****************************************************************
function display( msgid , varlist )
{	messages = new messagelist();
	alert( addvariables(	messages[msgid] , varlist ));
}


//****************************************************************
//	Define messages here
//****************************************************************
function messagelist()
{	this.MSG000	=	"Please fill in '#01'.";	
	this.MSG001	=	"Please enter a value for '#01' in '#02' format.";
	this.MSG002	=	"Please enter a valid email id in the '#01' field."
	this.MSG003 	=   	"The number of characters in the field '#01' should not exceed more than '#02' characters." ;
	this.MSG004 	=	"The number of characters in the field '#01' should not exceed more than #03 characters.";
	this.MSG005	=	"Please enter valid E-mail address e.g. name@domain.com";
	this.MSG006	=	"Please enter a Numeric value for the field '#01'. ";
	this.MSG007	=	"The number of characters in the field '#01' should be #02 characters not more than or less than #02 characters. ";	
	this.MSG008 	=   	"Please enter values in the fields 'NRIC' or 'User Name'. The fields cannot be left blank.";
	this.MSG009 	=   	"Please select minimum one record for deletion. " ;
	this.MSG010 	=	"Please enter value of '#01' in the range of #02-#03 .";
	this.MSG011 	=	"Value for '#01' should be in the range of #02-#03 .";
	this.MSG012 	=	"Please enter an integer value for '#01' e.g. 12 , 34 , 2 . \n A Decimal value like 3.4 cannot be accepted.";
}

function addvariables(	msgstr ,	varlist )
{	varvalues = new Array() ;						// Array to handle variable values 
	i = 0 ;											// initialize i again for next use 
	
	varlist = varlist + ":";						// ':' has been postfixed for building following logic
	while(	varlist.indexOf(":") > -1 && varlist.length > 1)
	{	
		varlist = varlist.substring(1);				// remove first char ie ":"
		varvalues[i] = varlist.substring( 0 , varlist.indexOf(":") );	// get and assign variable value
		varlist = varlist.substring(varlist.indexOf(":"));			// remove variable value
		i++ ;
	}

	
	finalmsg = msgstr ;
	while( finalmsg.indexOf('#') > -1 )
	{	hashindex = finalmsg.indexOf('#') ;
		finalmsg =	finalmsg.substring( 0 , hashindex) + varvalues[Number( finalmsg.substring( hashindex + 1 , hashindex + 3) )-1] +	finalmsg.substring( hashindex + 3) ;	
	}
	return finalmsg ;
}

//****************** Pattern checking functions 
//
//***********************************************
function isValidEmail(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   return false
		 }

 		 return true					
	}
