function TextAreaValidation(TextBox, Type)
{
var field = "";

//Lecture Title
if(Type == 0)
{
MaxSize = 500;
}
//Lecture Description
else if(Type == 1)
{
MaxSize = 1000;
}
//Question
else if(Type == 2)
{
MaxSize = 1000;
}
//Solution
else if(Type == 3)
{
MaxSize = 2000;
}
//Message Book
else if(Type == 4)
{
MaxSize = 5000;
}
//billing address for payment
else if(Type == 5)
{
MaxSize = 200;
}

var field = document.getElementById(TextBox);

if (field && field.value.length >= MaxSize) 
{
field.value =  field.value.substring(0, MaxSize); 
}
}

function MacAddresswithHyphen(str, name)
{
var alphaExp = "([\A-F0-9]{2}-[\A-F0-9]{2}-[\A-F0-9]{2}-[\A-F0-9]{2}-[\A-F0-9]{2}-[\A-F0-9]{2})";
if(str.value.match(alphaExp))
{
if(str.value.length == 17)
{
return true;
}
}
else
{
alert("* Please enter correct " + name);
str.focus();
return false;
}
}

function IsEmpty(str,name)
{
var retval=true;
var count=0;

if (str.value=="")
{
alert("Please enter " +name);
str.focus();
retval=false;
}
else
{
for(i=0;i<str.value.length;i++)
{
if(str.value.charAt(i)==" ")
{
count++;
}
}
if (count==str.value.length)
{
alert("Please enter " +name);
str.focus();
retval=false;
}
}

return retval;
}

function IsPasswordMatching(str1, str2)
{
if(str1.value != str2.value)
{
alert("New Password and Confirm Password do not match");
str2.focus();
return false;
}
else
{
return true;
}
}

function CheckPasswordLength(str)
{
if(str.value.length < 6)
{
alert("The new Password should have a length of minimum 6 characters");
str.focus();
return false;
}
else
{
return true;
}
}

function IsEmailValid(str)
{
var retval=true;
var AtSym=str.value.indexOf('@');
var Period=str.value.lastIndexOf('.');
var Space=str.value.indexOf(' ');
var Length=str.value.length-1;
var index = str.value.indexOf('@');
var substr = str.value.substring(index+1);
var index2 = substr.indexOf('@');
var count=0;

if (str.value=="")
{
str.focus();
retval=false;
}
else
{
for(i=0;i<str.value.length;i++)
{
if(str.value.charAt(i)==" ")
count++;
}

if (count==str.value.length)
{
str.focus();
retval=false;
}
else if((AtSym<1)||(str.value.charAt(0)=='_')||(str.value.charAt(Length)=="_")|| //'@' can't be in first position
(str.value.indexOf("_")==AtSym+1)||(str.value.charAt(AtSym-1)=="_")||
(Period<=AtSym+1)|| //Must be atleast one valid char between '@' and '.'
(Period==Length)|| //Must be atleast one valid char after '.'
((Space>0) && (Space!=Length))||
(index2 != -1)) //No empty spaces permitted
{
alert("Please enter a valid Email");
str.focus();
retval=false; 
}
}

return retval;
}

function CheckSelectedIndex(obj, name)
{
if (obj.selectedIndex == 0)
{
alert("Please select a " +name);
obj.focus();
return false;
}
else
{
return true;
}
}

function TagSpaceCheck(str, name)
{
var WhiteSpace = new RegExp(/\s/);

if (WhiteSpace.test(str)) 
{
alert("Please do not enter any space in " +name);
str.focus();
return false;
}

return true;
}

function NumericCheck(str, name)
{
for(var j=0; j<str.length; j++)
{
var alphaa = str.charAt(j);
var hh = alphaa.charCodeAt(0);


if(hh > 47 && hh < 58)
{

}
else
{
alert("Please enter only numeric value in " +name);
return false;
}
}

return true;
}

function AlphanumericCheck(str, name)
{
for(var j=0; j<str.length; j++)
{
var alphaa = str.charAt(j);
var hh = alphaa.charCodeAt(0);

if((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123))
{

}
else
{
alert("Please enter only alphanumeric characters in " +name);
return false;
}
}

return true;
}

function AlphanumericSpaceCheck(str, name)
{
for(var j=0; j<str.length; j++)
{
var alphaa = str.charAt(j);
var hh = alphaa.charCodeAt(0);

if((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (hh == 32))
{

}
else
{
alert("Please enter only alphanumeric characters (or space) in " +name);
return false;
}
}

return true;
}

function AlphanumericSpaceCommaFullStopCheck(str, name)
{
for(var j=0; j<str.length; j++)
{
var alphaa = str.charAt(j);
var hh = alphaa.charCodeAt(0);

if(((hh == 32) || (hh > 47 && hh < 59) || (hh == 46) || (hh == 44)) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123))
{
//http://cwashington.netreach.net/main/library/ascii_chart.html
}
else
{
alert("Please enter only alphanumeric characters (or space, comma, fullstop) in " +name);
return false;
}
}

return true;
}

function AlphanumericUnderscoreCheck(str, name)
{
for(var j=0; j<str.length; j++)
{
var alphaa = str.charAt(j);
var hh = alphaa.charCodeAt(0);

if((hh > 47 && hh < 59) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (hh == 95))
{
//http://cwashington.netreach.net/main/library/ascii_chart.html
}
else
{
alert("Please enter only alphanumeric characters (or underscore) in " +name);
str.focus();
return false;
}
}

return true;
}

function displayKeyCode(evt, name)
{
var charCode = (evt.which) ? evt.which : event.keyCode

if (charCode == 32) 
{
var sString1 = name.value;
alert("Please do not enter any space")

while (sString1.substring(0,1) == ' ')
{
sString1 = sString1.substring(1, sString1.length);
}

name.value = sString1;
return false;
}
}