function confirmDel()
{
	var ans = confirm("Are you sure you want to delete this record");
	if(ans)
		return true;
	else
		return false;
}

	//----------------------------------------------------------------	
	//handle the post data
	function confirmSwithUser(indx,userId,userType,backUrl)
	{
		if(indx==0)
			return false;
		var ans = window.confirm("Are you sure you want to switch this user.");
		if(ans)
		{
			 window.location.href="switchUser.php?userId="+userId+"&userType="+userType+"&backUrl="+backUrl;
			 return true;
		}
		else
			return false;
	}

  
function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];

	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length >= 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}

function validateform()
{
	var  msg,k;
	var dm= eval("document."+arguments[0]);
	
	var elementslength=dm.length;
		var not_needed_elements=arguments["1"];
	//alert(validateform.arguments["1"]);
	msg="";
	for( var i=0;i<elementslength;i++)

	{
		k=0;

		if(dm.elements[i].value=="")
		{ 
		 for(var j in not_needed_elements)
			{ 
				if(not_needed_elements[j]==dm.elements[i].name)
					{
						k=1;
					}
			}
			if(k==0)
				msg=msg+"\n"+dm.elements[i].name.substring(4)+",";
		}
		
	}
	
	return(msg);
}
function ValidateForm1()
{	var  msg,k;
	var dm= eval("document."+arguments[0]);
	
	var elementslength=dm.length;
		var not_needed_elements=arguments["1"];
	//alert(validateform.arguments["1"]);
	msg="";
	for( var i=0;i<elementslength;i++)

	{
		k=0;

		if(dm.elements[i].value=="")
		{ 
		 for(var j in not_needed_elements)
			{ 
				if(not_needed_elements[j]==dm.elements[i].id)
					{
						k=1;
					}
			}
			if(k==0)
				if(dm.elements[i].id!="")
					msg=msg+"\n"+dm.elements[i].id+",";
		}
		
	}
	
	return(msg);
}

function compare_two_values()
{
	var  msg;
	if(arguments["1"]==arguments["2"])
	 	msg=1;
	else
		msg=0;
	return(msg);
	 
}
function new_window(url) 
				{ 
					link =
window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=300,left=40,top=50;scrollbar=no;"); 
				}

function validate_current_form(frmObj)
{
	var msg = "";
	var flag = 0;
	for(i=0;i<frmObj.length;i++)
	{
		if(frmObj[i].value=="")
		{
			msg += frmObj[i].id+" is empty.\n";			
			flag=1;
		}
	/*	
		if(frmObj[i].id=="num")
		{
			if(isNaN(frmObj[i]))
			{
				alert(frmObj[i].name+'is not a valid nunber.');				
				return false;
			}
		}
	*/

	}
	if(flag==1)
	{	
		alert("Please enter the following fields as mentioned.\n___________________________________________\n"+msg);
		return false;
	}
	else
		return true;
}

function validate_questionnaire(frmObj)
{
	var str="";
	var numlist = new Array(0,1,2,3);
	var replist = new Array("First","Second","Third","Fourth");

	if(frmObj[0].value=="")
	{
		str += frmObj[0].id + " is empty\n"
	}

	for(i=0;i<parseInt(frmObj['hdn_record_no'].value);i++)
	{
		oldstr = new String(i);
		newstr = oldstr.replace(numlist[i],replist[i]);
		if(frmObj['option'+i].value=="")
		{
			str += newstr + " answer option field is empty.\n"
			
		}
		else
		{
			if(frmObj['points'+i].value=="")
			{
				str += newstr + " answer score field is empty.\n"
			}
			else
			{
				if(isNaN(frmObj['points'+i].value))
					str += newstr + " answer score field must be in valid number format.\n"
			}
		}
	}
	                 
	if(str=="")
		return true;
	else
	{
		alert("Please enter the following fields as mentioned.\n___________________________________________\n"+str);
		return false;
	}

}

// -- check the characters------------------------------------------------

function isLetter (c)
{  
 return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}
function isDigit (c)
{ 
  return ((c >= "0") && (c <= "9"))
}
function isLetterOrDigit (c)
{  
 return (isLetter(c) || isDigit(c))
}

function isValidSpecialCharacter(c)
{
	return ((c=="-") || ((c=="_")))
}

function checkAllCharacter(c)
{
	 return (isLetter(c) || isDigit(c) || isValidSpecialCharacter(c))
}

function isValidUsername(str)
{
	err = "";
	for(i=0;i<str.value.length;i++)
	{
		if(!checkAllCharacter(str.value.charAt(i)))
		{
			err += str.value.charAt(i);	
		}
	}
	if(err!="")
	{
		alert("Your username contains the invalid character " + err + " . Usernames can only contain the characters a-z, 0-1, -, or _");
		str.focus();		
		str.select();
		return false;				

	}
}

