function validdates1(theform)

{



	with(theform)

	{

		if (validate_required(year,"Please select Year")==false)

		{year.focus();return false;}
		
		if (validate_required(state,"Please select State")==false)

		{state.focus();return false;}

		if (validate_required(location,"Please select location")==false)

		{location.focus();return false;}

		
	}

	return true;

}


function submitlogin()

{

	if(validloginform(document.loginform)==true)

	{

	document.loginform.submit();

	}



}

function submit_search()

{

	if(validsearch(document.frm)==true)

	{
		document.frm.action="course.php?search=Y";

	document.frm.submit();

	}



}

function submit_updatecoursetype()

{
//alert("in");

	//if(validsearch(document.myform)==true)

	//{
		document.myform.action="update_coursetype.php";

	document.myform.submit();

	//}



}



function submit_updatecourse()

{
//alert("in");

	//if(validsearch(document.myform)==true)

	//{
		document.myform.action="update_course.php";

	document.myform.submit();

	//}



}

function validsearch(thisform)

{

	with (thisform)

	{

		if (validate_required(year,"Please Select a Year")==false)

		{year.focus();return false;}

		/*if (validate_required(location,"Please Select a location")==false)

		{location.focus();return false;}*/

		}

	return true;

}
function submitform()

{


	if(validform(document.myform)==true)

	{

	document.myform.submit();	

	}

	

}

function submitform1()

{

	

	if(validform(document.myform)==true)

	{

	document.myform.submit();	

	}

	

}





 function submit_upload()

{

	if(validzip(document.myform)==false)
	{}
	else
{
	document.myform.submit();	
}
	

}



 function submit_uploadtest()

{

if(validupload(document.myform)==true)

{

alert("Done");	

}

}



function validupload(thisform)

{



	for(i=0; i<thisform.elements.length; i++)

	{

	with (thisform)

	{

				

	

		

	if (validate_required(student[i],"Please enter student's full name")==false)

		{student[i].focus();return false;}

				

		if (validate_required(projectname[i],"Please enter a project name")==false)

		{projectname[i].focus();return false;}

		

	



	

	}

	}

	return true;

}

function validform(thisform)

{

	with (thisform)

	{

		if (validate_required(course,"Please Select a Course")==false)

		{course.focus();return false;}

		

		

		if (validate_required(state,"Please Select a State")==false)

		{state.focus();return false;}

		

		

		if (validate_required(location,"Please Select a Location")==false)

		{location.focus();return false;}

		

		

		if (validate_required(dates,"Please Select a date")==false)

		{dates.focus();return false;}

		

		

		if (validate_required(year,"Please Select a Year")==false)

		{year.focus();return false;}

	

	}

	return true;

}


function validsearch(thisform)
{
	with (thisform)
	{

		if (validate_required(year,"Please select Year")==false)

		{year.focus();return false;}

	}

	return true;

}



function validloginform(thisform)

{

	with (thisform)

	{

		if (validate_required(login,"Please Enter a User Name")==false)

		{login.focus();return false;}

		

		

		if (validate_required(password,"Please Enter a Password")==false)

		{password.focus();return false;}

		

		

	}

	return true;

}





function submit_changepass()

{

document.myform.action="update_location.php";

document.myform.submit();



}



function validpasschange()

{



	for(i=0; i<document.myform.elements.length; i++)

	{

		if (validate_required(document.myform.login[i],"Please enter user name")==false)

		{document.myform.login[i].focus();return false;}

				

		if (validate_required(document.myform.newpassword[i],"Please enter new password name")==false)

		{document.myform.newpassword[i].focus();return false;}

	}

	return true;

}



///////////////////////end main

// Required Field Validation

function validate_required(field,alerttxt)

{

with (field)

{

if (value==null||value=="")

  {alert(alerttxt);return false;}

else {return true;}

}

}



//combo validation like state-

function validate_selectcombo(field1)

{

	

if (field1.value=="")

{



return false;

}

else

return true;

}







function stripCharsInBag(s, bag){

	var i;

    var returnString = "";

    // Search through string's characters one by one.

    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++){   

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}









function validmultiform(thisform)

{

	

	

}

 



function wc(str) {

            var sa = str.split(" ");

            return sa.length;

        }

		

String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }



function validupload1(thisformfield)

{

	var theval = thisformfield.value.trim();

    if(theval != "" )

	{

	if(wc(theval)<=1)

	{

	alert("Please enter First Name and Last Name Both");	

	thisformfield.focus();return false;

	}

	if(IsAlfa(theval)==false)

	{

	alert("Please enter only valid Alphabets and Space");

	thisformfield.focus();return false;

	}

	}

	return true;

}







function IsAlfa(strString)

   //  check for valid numeric strings	

   {

   var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

   var strChar;

   var blnResult = true;



   if (strString.length == 0) return false;



   //  test strString consists of valid characters listed above

   for (i = 0; i < strString.length && blnResult == true; i++)

      {

      strChar = strString.charAt(i);

      if (strValidChars.indexOf(strChar) == -1)

         {

         blnResult = false;

         }

      }

   return blnResult;

   }





 function locationdelete()

{

document.myform.action="delete_location_conf.php";

document.myform.submit();

}


 function coursedelete()

{

document.myform.action="delete_course_conf.php";

document.myform.submit();

}


 function datesdelete()

{
	

document.myform.action="delete_dates_conf.php";

document.myform.submit();

}

 function coursetypedelete()

{

document.myform.action="delete_coursetype_conf.php";

document.myform.submit();

}





 function submit_savelocation()

{

	document.myform.action="save_location.php";

	if(validlocation(document.myform)==true)

					 {

document.myform.submit();

					 }

}



function validlocation(theform)

{



	with(theform)

	{

		if (validate_required(year,"Please enter Year")==false)

		{year.focus();return false;}
		
		if (validate_required(location,"Please enter location")==false)

		{location.focus();return false;}

		if (validate_required(state,"Please enter State")==false)

		{state.focus();return false;}

		if (validate_required(no_week,"Please enter No of Weeks")==false)

		{no_week.focus();return false;}

		if (validate_required(login,"Please enter Login Name")==false)

		{login.focus();return false;}

		if (validate_required(password,"Please enter Password")==false)

		{password.focus();return false;}

				

	}

	return true;

}

 function submit_savecourse()

{

	document.myform.action="save_course.php";

	if(validcourse(document.myform)==true)

					 {

document.myform.submit();

					 }

}

function submit_savecoursetype()
{

	document.myform.action="save_coursetype.php";

	if(validcoursetype(document.myform)==true)

	 {

		document.myform.submit();

	 }

}

function validcoursetype(theform)
{

with(theform)
	{
	
 		if (validate_required(coursetype,"Please choose Course Type")==false)

		{coursetype.focus();return false;}
		else
		{
		return true;	
		}
	}
}

function validcourse(theform)

{



	with(theform)

	{
		
			
		if (validate_required(coursetype,"Please choose Course Type")==false)

		{coursetype.focus();return false;}


		if (validate_required(coursename,"Please choose Course Name")==false)

		{coursename.focus();return false;}

		if (validate_required(internetdelivery,"Please choose Internet Delivery Type")==false)

		{internetdelivery.focus();return false;}
	

	}

	return true;

}



function IsNumeric(strString)

   //  check for valid numeric strings	

   {



   var strValidChars = "0123456789.-";

   var strChar;

   var blnResult = true;



   if (strString.length == 0) return false;



   //  test strString consists of valid characters listed above

   for (i = 0; i < strString.length && blnResult == true; i++)

      {

      strChar = strString.charAt(i);

      if (strValidChars.indexOf(strChar) == -1)

         {

         blnResult = false;

         }

      }

   return blnResult;

   }

   

   

function submit_dates()
{

if(validatedate(document.myform)==false)
{
//alert("in");	
}
else
{
	document.myform.submit();
}

}

function chkbutton(btn,n)
{
	
	
    var cnt = 0;
	var n=n;
    
    for (var i=0; i<n; i++)
	{
        if (btn[i].checked) 
		{
			//alert("in");
			cnt = 1;
		}
    }
	
    if (cnt > 0) 
	{
	return true;
	}
    else 
	{	
		return false;
	}
	
}



		
		
	function chkdates(dtarr,len,frm)
	{
		     var dtarr=dtarr;
			  dml=document.forms['myform'];
				len = dml.elements.length;
			// alert(len);
			 for(var i=0 ; i<len ; i++)
			 {
				
				//check the textbox with the elements name
				if (dml.elements[i].name==dtarr)
				{
					
					// alert(dml.elements[i].value);
				  // if exists do the validation and set the focus to the textbox
				     
					if(dml.elements[i].value!="")
					{
						
						if(test(dml.elements[i])==false)
						{
							dml.elements[i].value="";
							alert("Date format is wrong, It should be like 14July-20July");
							return false;
						}
						
					}
				}
				
				
			 }
		
		
		return true;
			
	}
		
		
function validatedate(frm)
{
	

	with(frm)
	{
		if(chkdates("dates[]",frm)==false)
		{
			return false;	
		}
		
	}
	return true;
}	
		
function test(txt)  { 	
var iChars = "!@#$%^&*()+=_[]\';,./{}|\":<>?";   
var iChars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- ";   
for (var i = 0; i < txt.value.length; i++) {   
	if (iChars1.indexOf(txt.value.charAt(i)) == -1)    
	{   	
	return false;  
	} 
	
}   }




function validzip(frm)
{
	
	with(frm)
	{
		if(chkaddproject("files[]",frm)==false)
		{
			return false;	
		}
		
		if(chkzip("files[]",frm)==false)
		{
			return false;	
		}
		
	}
	return true;
}	

function chkaddproject(dtarr,len,frm)
	{
		     var dtarr=dtarr;
			  dml=document.forms['myform'];
			if(dml.elements[0].value=="" || dml.elements[1].value=="" || dml.elements[2].value=="" || dml.elements[3].value=="" ||dml.elements[4].value=="" || dml.elements[5].value=="")
					{
						
								   alert("Please enter project detail");    								
									return false;
										
					}
			 
		return true;		
	}


function chkzip(dtarr,len,frm)
	{
		     var dtarr=dtarr;
			  dml=document.forms['myform'];
				len = dml.elements.length;
			// alert(len);
			 for(var i=0 ; i<len ; i++)
			 {
				
				//check the textbox with the elements name
				if (dml.elements[i].name==dtarr)
				{
					
					//alert(dml.elements[i].value);
				  // if exists do the validation and set the focus to the textbox
				     
					if(dml.elements[i].value!="")
					{
						img=dml.elements[i].value;
						 if(img=="")
						 {
							 alert("Please Upload the file");  
							 return false;
						  }
						  else
						  {
								var filelength = parseInt(img.length) - 4;
								var fileext = img.substring(filelength,filelength + 4);
								
								// Check file extenstion
								if (fileext.toLowerCase() != ".zip")
								{   alert("Please Upload zip files only");    
									dml.elements[i].value="";
									return false;
								
								}
						
						  }
						
						/*if(test(dml.elements[i])==false)
						{
							dml.elements[i].value="";
							alert("Please upload zip file");
							return false;
						}*/
						
					}
				}
				
				
			 }
		return true;		
	}



function validfile(frm)
 { 
 with(frm)
 {
 var img;
 img=uploadlogo.value;
 }
 if(img=="")
 {
	 alert("Please Upload the file");  
	 return false;
  }
  else
  {
var filelength = parseInt(img.length) - 4;
var fileext = img.substring(filelength,filelength + 4);

// Check file extenstion
if (fileext.toLowerCase() != ".jpeg" && fileext.toLowerCase() != ".jpg" && fileext.toLowerCase() != ".gif" && fileext.toLowerCase() != ".bmp")
{   alert("Please Upload the valid extension of file");    
	return false;

}
else
  {
   return true;
  }
 }
return true;
}
