function chkmax(txtbox, txtlen, txtname)
{
if (txtbox.value.length > txtlen)
{
//alert('Please limit ' + txtname + ' to only ' + txtlen + ' characters.')
alert("You have exceeded the character limit for this text field. Please restrict your text length to "+ txtlen +" characters only.");

txtbox.focus();
return false;
}
return true;
}
function emailCheck(str) {


var at="@"

var dot="."

var lat=str.indexOf(at)

var lstr=str.length

var ldot=str.indexOf(dot)


// Check If the @ sign is present in Email, invalid if not present ...

if (str.indexOf(at)==-1){

return false

}

// Check If the @ sign is first or last character of Email, invalid if it is first or last ...

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1){

return false

}


// Check If the Dot '.' is present in the Email and is first or last character

// invalid if not present and Invalid if first or last character ...

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot,lstr-1)==lstr-1){

return false

}

// Check If the @ sign is used more than once in Email ...

// Invalid if used more than once .

if (str.indexOf(at,(lat+1))!=-1){

return false

}


// Check If the '.' appears just before or after '@' sign, than that is Invalid ...

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

return false

}

// Check If the '.' exists after '@' sign (with 1 char gap), Invalid if it does not ...

if (str.indexOf(dot,(lat+2))==-1){

return false

}


// Check If there is any space in the Email, than that is Invalid ....

if (str.indexOf(" ")!=-1){

return false

}


return true 

}

//*********************************** Trim Spaces ************************
function trimSpaces(str)
{
if (str != null)
{
var i;
for (i=0; i < str.length; i++)
{
if (str.charAt(i)!=" ")
{
str=str.substring(i,str.length);
break;
}
}
for (i = str.length-1; i >= 0; i--)
{
if (str.charAt(i)!=" ")
{
str = str.substring(0,i+1);
break;
}
}
if (str.charAt(0)==" ")
{
return "";
}
else
{
return str;
}
}
}
//*********************************** Check Null ******************************

function chknull(txtbox, txtname)

{
if (trimSpaces(txtbox.value) == '')
{
alert(txtname);
txtbox.focus();
return false; 
}

return true;

}

//********************* Check for Max length reached **************************

function chkmax(txtbox, txtlen, txtname)

{

if (txtbox.value.length > txtlen)

{

alert('Please limit ' + txtname + ' to only ' + txtlen + ' characters.')

txtbox.focus();

return false;

}

return true;

}

//********************* Authenticate Combo Selection ******************************

function chkcombo(cmbbox,cmbname)

{

cmbValue = cmbbox.options[cmbbox.selectedIndex].value; 

if (cmbValue == "-1")

{

alert(cmbname);

cmbbox.focus();

return false; 

}

return true; 

}

//********************* Simple Email Validity ******************************

function chkemailsimple(txtbox, txtname) {

if (!chknull(txtbox, txtname)) return false;

if(txtbox.value.indexOf('@') == -1 || txtbox.value.indexOf('.') == -1) {

alert("Please enter valid Email Address.");

txtbox.focus();

return false; 

}

return true;

}

//*******************Set Deadline Date**********************************************

function chkValidDate(mm,dd,yy)

{

//mm = parseInt(document.form1.month.options[document.form1.month.selectedIndex].value);

//dd = parseInt(document.form1.day.options[document.form1.day.selectedIndex].value);

//yy = parseInt(document.form1.year.options[document.form1.year.selectedIndex].value);

if(mm == 4 || mm == 6 || mm == 9 || mm == 11)

{

max_days = 30;

}

else if(mm == 2)

{ // February 

if(yy % 4 == 0)

{ // Leap Year

max_days = 29;

}

else

{ // Not a Leap Year

max_days = 28; 

} 

}

else

{

max_days = 31; 

}

if (dd >max_days )

return false;

else

return true; 

}
//***** ORDER FOR DEADLINE CHECKS ************************************************************************
function setDeadLineDate(){

var max_days;

mm	= parseInt(document.Form1.ddlMonth.options[document.Form1.ddlMonth.selectedIndex].value);
dd	= parseInt(document.Form1.ddlDay.options[document.Form1.ddlDay.selectedIndex].value);
yy	= parseInt(document.Form1.ddlYear.options[document.Form1.ddlYear.selectedIndex].value);

min_mm = parseInt(document.Form1.min_mm.value);
min_dd = parseInt(document.Form1.min_dd.value);
min_yy = parseInt(document.Form1.min_yy.value);		


min_days = 1;
l = (max_days -  min_days) + 1		
//filling the data combo
for(i=0;i<l;i++ ){
document.Form1.ddlDay.options[i] = new Option(i+min_days,i+min_days);
}


}
//***** ORDER FOR DEADLINE CHECKS ************************************************************************
function chkDeadLine(){

var sel_date,min_date;
var str_sel_date,str_min_date;
var fi;

//fi	=	document.form1.fi.value;
//if (fi == '' )
{ 
mm	= parseInt(document.Form1.ddlMonth.options[document.Form1.ddlMonth.selectedIndex].value);
dd	= parseInt(document.Form1.ddlDay.options[document.Form1.ddlDay.selectedIndex].value);
yy	= parseInt(document.Form1.ddlYear.options[document.Form1.ddlYear.selectedIndex].value);
str_sel_date = mm+"/"+dd+"/"+yy;

min_mm = parseInt(document.Form1.min_mm.value);
min_dd = parseInt(document.Form1.min_dd.value);
min_yy = parseInt(document.Form1.min_yy.value);

min_text = document.Form1.ddlMonth.options[min_mm-1].text; 	
str_min_date = min_mm+"/"+min_dd+"/"+min_yy;
str_min_date_to_display = min_text+" "+min_dd+", "+min_yy;

sel_date = new Date(str_sel_date)
min_date = new Date(str_min_date)		

if(sel_date < min_date){
//alert("The deadline cannot be for the date, before "+str_min_date_to_display+".")
alert("Please choose a valid deadline of at least 48 hours. (Example: "+str_min_date_to_display+" or any date after that).");
document.Form1.ddlMonth.options[min_mm-1].selected = true;
setDeadLineDate();
document.Form1.ddlDay.options[min_dd-1].selected = true;
document.Form1.ddlMonth.focus();
return false;
}else{

if(mm == 4 || mm == 6 || mm == 9 || mm == 11){
max_days = 30;	
}else if(mm == 2){		// February			
if(yy % 4 == 0){	// Leap Year
max_days = 29;
}else{				// Not a Leap Year
max_days = 28;	
}			
}else{
max_days = 31;
}

if ( parseInt(dd) > parseInt(max_days) ) {
alert("Please select a valid Day of the Month for your deadline.")
document.Form1.ddlDay.focus();

return false;
} else {

return true;
}

}
}	
//else	{
//	return true;
//}		
}





function Validate()
{
	
var strDate=new Date();
strDate= strDate.getMonth() + "/" +  (strDate.getDay() + 2) + "/" + strDate.getFullYear();
//alert(Date);
if (!chknull(document.Form1.txtFName, "Please enter your first name. (Example: Michael)."))
{
return false;
} 

if (!chknull(document.Form1.txtLName, "Please enter your last name. (Example: Andrew)."))
{
return false;
}
if (!chknull(document.Form1.txtEmail, "Please enter your E-mail Address"))
{
return false;
} 
if(!emailCheck(document.Form1.txtEmail.value)) 
{
alert("Please enter valid E-mail Address");
document.Form1.txtEmail.focus();
return false;
}
if (trimSpaces(document.Form1.txtAEmail.value)!='')
{
if(!emailCheck(document.Form1.txtAEmail.value)) 
{
alert("Please verify valid E-mail Address");
document.Form1.txtVEmail.focus();
return false;
}				
}
if (!chknull(document.Form1.txtPhone1, "Please enter your Phone No."))
{
	return false;
} 
if (!chknull(document.Form1.txtTopic, "Please enter your topic's actual title. (Example: Human Resource Management)."))
{
return false;
}
if (!chkmax(document.Form1.txtTopic,1000,"your topic")) 
{
return false;
} 

if (document.Form1.ddlType.options[document.Form1.ddlType.selectedIndex].value == -1)
{
	alert ('Please select document type.');	
	document.Form1.ddlType.focus();
	return false;
}


if (document.Form1.ddlAcademicLevel.options[document.Form1.ddlAcademicLevel.selectedIndex].value == -1)
{
	alert ('Please select academic level.');	
	document.Form1.ddlAcademicLevel.focus();
	return false;
}



if (!chknull(document.Form1.txtDetail, "Please provide the description of your topic."))
{
return false;
}
if (!chkmax(document.Form1.txtDetail,5000,"your topic's description")) 
{
return false;
} 
if(!chkDeadLine())
{
return false;
}
if(document.Form1.rdReject.checked==true) 
{
alert("Please first choose I accept terms and conditions");
return false;
}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->

