﻿function getfileextension(inputId) 
{ 
 var fileinput = document.getElementById(inputId); 
 if(!fileinput ) return ""; 
 var filename = fileinput.value; 
 if( filename.length == 0 ) return ""; 
 var dot = filename.lastIndexOf("."); 
 if( dot == -1 ) return ""; 
 var extension = filename.substr(dot,filename.length); 
 return extension; 
} 
function checkVideofileType(inputId) 
{ 
 allowedExt1 = ".flv,.f4v,.mp4,.m4v,.mov,.3gp,.3g2,.swf".toUpperCase();
 var ext = getfileextension(inputId); 
 if (allowedExt1.indexOf(ext.toUpperCase()) == 0)
 {
 	return true;
 }
 else
 {
 	return false;
 }
} 

function checkfileType(inputId) 
{ 
 allowedExt = ".jpg,.jpeg,.gif,.png,.bmp".toUpperCase();
 var ext = getfileextension(inputId); 
  if (allowedExt.indexOf(ext.toUpperCase()) == 0)
  {
  	return true;
  }
  else
  {
  	return false;
  }
} 

function numbersonly(e){

var unicode=e.charCode? e.charCode : e.keyCode

if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57 ) //if not a number
return false //disable key press
}
}


function alphaonly(e){

var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8)
{ 
if( (unicode >= 97 && unicode <= 122) || (unicode >= 65 && unicode <= 90) || (unicode==32)|| (unicode==09)|| (unicode==46) )
return true
else
return false 
}
}

function trim(sStr) 

{

     return sStr.replace(/^\s+|\s+$/g, "") ;

}


function alphanumeric(e){

var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8)
{ 
if( (unicode >= 97 && unicode <= 122) || (unicode >= 65 && unicode <= 90) ||(unicode >=48 && unicode <=57)|| (unicode==09) || (unicode==46))
return true
else
return false 
}
}

function fnvalidateemail(valmail)
{

  for(i=0;i<fnvalidateemail.arguments.length;i++)
   {
    valmailtext= fnvalidateemail.arguments[i];
    valmail=valmailtext.value;
    if( (valmail!="") || (valmail.length > 0 ))
    {
	var n,atCount,dotCount,temp_1,temp_2,temp_ascii;
	var temp_3=0;
	atCount=0;
	dotCount=0;
	n=0;
	var st=new String;
	st = valmail.split(" ");
	st = st.join("");
	st = st.toLowerCase();
	temp_1 = st.charAt(0);
	temp_ascii = st.charCodeAt(0);
	
	for(n=0;n<st.length;n++)
	{
		temp_2 = st.charCodeAt(n);
		if ((temp_2<48) || (temp_2>57))
		{
			if ((temp_2<97) || (temp_2>122))
			{ 
				if ((temp_2 == 95) || (temp_2==46) || (temp_2==64)||(temp_2==45))
				{
				//alert("special but correct");
				}
				else
				{ 
				alert("Invalid Email Address");
				valmailtext.focus();
				count=0;
				return false;
				}
			}
		}
		if(st.charAt(n)=='@' && n==0) atCount=atCount+1;
		if(st.charAt(n)=='@' && st.charAt(n+1)=='.') atCount=atCount+1;
		if(st.charAt(n)=='@') atCount=atCount+1;
		if(st.charAt(n)=='.') 
		{
			if(st.charAt(n+1)=='.' || n==st.length-1 ) atCount=2;
			dotCount=dotCount+1;
		}
	}
	
	if(atCount!=1 || dotCount<1) 
	{
	   alert("Invalid Email Address");
	   valmailtext.focus();
		return false;
	}
	else if ((temp_ascii < 48) || (temp_ascii > 122)) 
	{
	   
		alert("Invalid Email Id on Field "+valmailtext.id);
		valmailtext.focus();
		count=0;
		return false;
	}
	else
	{
		x=st.lastIndexOf("@");
		y=st.lastIndexOf(".");
		if(y < x )
		{
			alert("Invalid Email Address");
			valmailtext.focus();
			return false;
		}
		
	}
  }	
 }	
 
}
