// function for checking string
function checkString(str_temp, str_fld)
{
	temp=new String(str_temp);
	if(str_temp=="")
	{
		window.alert("Please enter the " + str_fld);
		return false;
	}
	
	if(temp.charAt(0)==" ")
	{
		window.alert("The " + str_fld + " cannot start with a space");
		return false;
	}
	
	str=new String("!@$%^&*()+=-[]\\\';,/{}|\":<>?");
	
	var flag=1;
	
	for (c=0; c<temp.length; c++)
	{
		if(str.indexOf(temp.charAt(c))>=0)
		{
			flag=0;
			break;
		}
	}
	
	if (flag==0)
	{
		window.alert("The " + str_fld + " cannot contain special character.");
		return false;
	}
	return true;
}

// function for checking number
function checkNumber(str_temp, str_fld)
{
	temp=new String(str_temp);
	if(str_temp=="")
	{
		window.alert("Please enter the " + str_fld);
		return false;
	}
	
	if(temp.charAt(0)==" ")
	{
		window.alert("The " + str_fld + " cannot start with a space");
		return false;
	}
	
	if (isNaN(str_temp))
	{
		window.alert("The " + str_fld + " can contain only numbers");
		return false;
	}
	return true;
}
function checkStringForFileUpload(str_temp, str_fld) // validation for file uploading 
{
	temp=new String(str_temp);
	if(str_temp=="")
	{
		window.alert("Please enter the " + str_fld);
		return false;
	}
	
	if(temp.charAt(0)==" ")
	{
		window.alert("The " + str_fld + " cannot start with a space");
		return false;
	}
	
	str=new String("!@$%^&*()+=-[]\\\';/{}|\":<>?");
	
	var flag=1;
	
	for (c=0; c<temp.length; c++)
	{
		if(str.indexOf(temp.charAt(c))>=0)
		{
			flag=0;
			break;
		}
	}
	
	if (flag==0)
	{
		window.alert("The " + str_fld + " cannot contain special character.");
		return false;
	}
	return true;
}

function isEmailAddr(email)
{
	var result = false
  	var theStr = new String(email)
  	var index = theStr.indexOf("@");
 	if (index > 0)
  	{
    	var pindex = theStr.indexOf(".",index);
    	if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
 	}
  return result;
}

function checkStringEmail(str_temp, str_fld)
{
	temp=new String(str_temp);
	if(str_temp=="")
	{
		window.alert("Please enter the " + str_fld);
		return false;
	}
	
	if(temp.charAt(0)==" ")
	{
		window.alert("The " + str_fld + " cannot start with a space");
		return false;
	}
	
	str=new String("!#$%^&*()+=-[]\\\';,/{}|\":<>?");
	
	var flag=1;
	
	for (c=0; c<temp.length; c++)
	{
		if(str.indexOf(temp.charAt(c))>=0)
		{
			flag=0;
			break;
		}
	}
	
	if (flag==0)
	{
		window.alert("The " + str_fld + " cannot contain special character.");
		return false;
	}
	return true;
}
// simple test for URL format
function testURL(url) {
	if (url == "" || url.indexOf("http://",0) == -1) {
		alert("Please provide a valid URL. Like (http://yourdomain.com)");
		return (false);
	} else
		return (true);
}