// JavaScript Document

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

/* function for control the limited characters in Textarea */

function limitedCharAddForm()
{
var count = "1000";   //Example: var count = "500";
var tex = document.form1.description.value;
var len = tex.length;
if(len > count)
{
        tex = tex.substring(0,count);
        document.form1.description.value=tex;
        return false;
}
document.form1.limit_char.value = count-len;
}

/***************************************/


/* function for control the limited characters in Textarea */

function limitedCharEditForm()
{
var textCount = "1000";   //Example: var count = "500";
var text = document.form1.description.value;
var textLen = text.length;
if(textLen > textCount)
{
        text = text.substring(0,textCount);
        document.form1.description.value=text;
        return false;
}
document.form1.limit_char.value = textCount-textLen;
}


/***************************************/



function schoolSearchValid()
{
	//alert("State:"+document.school_search.state.value);
	if(document.school_search.speciality.value=="Select")
	{
		alert("Please select a speciality");
		document.school_search.speciality.focus();
		return false;
	}
}


function schoolAddValid()
{

   var str=document.form1.email.value;
   var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,15})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	

   var logoExt = new Array ('jpg', 'gif', 'jpeg', 'jpe');
   var theLogoFile = document.getElementById('logo').value; // i.e. the file name passed to the function
   var logoFileOK = 0;
   var logoPosition = theLogoFile.lastIndexOf(".");
   var readLogoExt = theLogoFile.substr(logoPosition+1).toLowerCase();

   var pictureExt = new Array ('jpg', 'gif', 'jpeg', 'jpe');
   var thePictrueFile = document.getElementById('picture').value; // i.e. the file name passed to the function
   var pictureFileOK = 0;
   var picturePosition = thePictrueFile.lastIndexOf(".");
   var readPictureExt = thePictrueFile.substr(picturePosition+1).toLowerCase();


//alert(theFile);
	if(document.form1.first_name.value.trim()=="")
	{
		alert("Please enter your first name");
		document.form1.first_name.focus();
		return false;
	}
	if(document.form1.last_name.value.trim()=="")
	{
		alert("Please enter your last name and title");
		document.form1.last_name.focus();
		return false;
	}
	/*if(document.form1.speciality2.value=="")
	{
		alert("Please select the field of study from the dropdown");
		document.form1.speciality1.focus();
		return false;
	}*/

	if(document.form1.other.value.trim()!="")
	{
			   //var otherSpeciality=document.form1.other.value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/\s/g,' ').replace(/[\s]{2,}/g,' ').replace(/[\s]{1,}/g,' ').replace(/\,$/,'');
			   var otherSpeciality=document.form1.other.value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/\s/g,' ').replace(/[\s]{2,}/g,' ').replace(/[\s]{1,}/g,' ').replace(/\,$/,'').replace(/\s,/, ",").replace(/,\s/, ",").replace(",,", ",")

			   if(otherSpeciality.charAt(0)==",")
			    {
			        alert("Do not start with a comma (,)");
			        document.form1.other.focus();
			        return false;
			    }
			    if(otherSpeciality.charAt(parseInt(otherSpeciality.length)-1)==",")
			    {
			        alert("Do not end with a comma (,)");
			        document.form1.other.focus();
			        return false;
			    }
				document.form1.other.value=otherSpeciality.trim();
	}

	else if(document.form1.speciality2.options.length<=0)
	{
		alert("Please select the field of study and/or \nenter your field of study into 'Other' box");
		document.form1.speciality1.focus();
		return false;
	}

	
	if(document.form1.school.value.trim()=="")
	{
		alert("Please enter name of the school/insitution");
		document.form1.school.focus();
		return false;
	}
	if(document.form1.address.value.trim()=="")
	{
		alert("Please enter the address details (address line)");
		document.form1.address.focus();
		return false;
	}
	if(document.form1.country.value=="Select")
	{
		alert("Please select the address details (country)");
		document.form1.country.focus();
		return false;
	}

	if(document.form1.country.value=="229") 
	{
		if(document.form1.state.value=="Select")
		{
			alert("Please select the address details (state)");
			document.form1.state.focus();
			return false;
		}
	}
	else
	{
		if(document.form1.non_us_state.value.trim()=="")
		{
			alert("Please enter the address details (state)");
			document.form1.non_us_state.focus();
			return false;
		}
			   /*var otherState=document.form1.non_us_state.value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/\s/g,' ').replace(/[\s]{2,}/g,'').replace(/[\s]{1,}/g,'').replace(/\,$/,'');

			   if(otherState.charAt(0)==",")
			    {
			        alert("No need to have a starting with ','");
			        document.form1.non_us_state.focus();
			        return false;
			    }
			    if(otherState.charAt(parseInt(otherState.length)-1)==",")
			    {
			        alert("No need to have a end with ','");
			        document.form1.non_us_state.focus();
			        return false;
			    }
				document.form1.non_us_state.value=otherState;*/
	}
	if(document.form1.city.value.trim()=="")
	{
		alert("Please enter the address details (city)");
		document.form1.city.focus();
		return false;
	}
	/*if(document.form1.state.value.trim()=="")
	{
		alert("Please enter the address details (state)");
		document.form1.state.focus();
		return false;
	}*/
	
	if(document.form1.zip.value.trim()=="")
	{
		alert("Please enter the address details (zip code)");
		document.form1.zip.focus();
		return false;
	}
	if(thePictrueFile=="")
	{
	alert("Please upload a copy of your school flyer");
	document.form1.picture.focus();
	return false;
	}
	if(document.form1.email.value.trim()=="")
	{
		alert("Please enter an email id for communication");
		document.form1.email.focus();
		return false;
	}
	
	if (filter.test(str))
	{
	testresults=true
	}
	else
		{
	alert("Please enter a valid email id")
	document.form1.email.focus();
	testresults=false;
	return (testresults)
	}
	
	/*if(document.form1.speciality.value=="")
	{
		alert("Please select the speciality");
		document.form1.speciality.focus();
		return false;
	}


	var dess=tinyMCE.getInstanceById('description').getHTML();*/
	if(document.form1.description.value.trim()=="")
	{
	
	alert("Please enter a few lines about the school/insititution (1000 chars max.)");
	document.form1.description.focus();
	return false;
	}

   if(theLogoFile!="")
   {
   for (i = 0; i < logoExt.length; i++)
   {
   if (logoExt[i] == readLogoExt) 
   {
   logoFileOK = 1; // one of the file extensions found
   } 
   }
   if (logoFileOK!=1) { 
   alert ("Please upload the logo in JPEG/JPG format");
   return false;
   }
   }


   if(thePictrueFile!="")
   {
   for (i = 0; i < pictureExt.length; i++)
   {
   if (pictureExt[i] == readPictureExt) 
   {
   pictureFileOK = 1; // one of the file extensions found
   } 
   }
   if (pictureFileOK!=1) { 
   alert ("Please upload the flyer in JPEG/JPG format");
   return false;
   }
   }

   }
   
   /* Validation for Edit the School Information before update/delete */
   
   function schoolUpdDel()
{

   var str=document.form1.email.value;
   var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,15})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	

   var logoExt = new Array ('jpg', 'gif', 'jpeg', 'jpe');
   var theLogoFile = document.getElementById('logo').value; // i.e. the file name passed to the function
   var logoFileOK = 0;
   var logoPosition = theLogoFile.lastIndexOf(".");
   var readLogoExt = theLogoFile.substr(logoPosition+1).toLowerCase();

   var pictureExt = new Array ('jpg', 'gif', 'jpeg', 'jpe');
   var thePictrueFile = document.getElementById('picture').value; // i.e. the file name passed to the function
   var pictureFileOK = 0;
   var picturePosition = thePictrueFile.lastIndexOf(".");
   var readPictureExt = thePictrueFile.substr(picturePosition+1).toLowerCase();


//alert(theFile);
	if(document.form1.first_name.value.trim()=="")
	{
		alert("Please enter your first name");
		document.form1.first_name.focus();
		return false;
	}
	if(document.form1.last_name.value.trim()=="")
	{
		alert("Please enter your last name and title");
		document.form1.last_name.focus();
		return false;
	}

	if(document.form1.other.value.trim()!="")
	{
			   //var otherSpeciality=document.form1.other.value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/\s/g,' ').replace(/[\s]{2,}/g,'').replace(/[\s]{1,}/g,'').replace(/\,$/,'');
			   var otherSpeciality=document.form1.other.value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/\s/g,' ').replace(/[\s]{2,}/g,' ').replace(/[\s]{1,}/g,' ').replace(/\,$/,'').replace(/\s,/, ",").replace(/,\s/, ",").replace(",,", ",")

			   if(otherSpeciality.charAt(0)==",")
			    {
			        alert("Do not start with a comma (,)");
			        document.form1.other.focus();
			        return false;
			    }
			    if(otherSpeciality.charAt(parseInt(otherSpeciality.length)-1)==",")
			    {
			        alert("Do not end with a comma (,)");
			        document.form1.other.focus();
			        return false;
			    }
				document.form1.other.value=otherSpeciality.trim();
	}
	else if(document.form1.speciality2.options.length<=0)
	{
		alert("Please select the field of study and/or \nenter your field of study into 'Other' box");
		document.add_school.speciality1.focus();
		return false;
	}
	if(document.add_school.school.value.trim()=="")
	{
		alert("Please enter name of the school/insitution");
		document.add_school.school.focus();
		return false;
	}
	if(document.add_school.address.value.trim()=="")
	{
		alert("Please enter the address details (address line)");
		document.add_school.address.focus();
		return false;
	}
	if(document.add_school.country.value.trim()=="Select")
	{
		alert("Please enter the address details (country)");
		document.add_school.country.focus();
		return false;
	}
	if(document.add_school.country.value=="229") 
	{
		if(document.add_school.state.value=="Select")
		{
			alert("Please select the address details (state)");
			document.add_school.state.focus();
			return false;
		}
	}
	else
	{
		if(document.add_school.non_us_state.value.trim()=="")
		{
			alert("Please enter the address details (state)");
			document.add_school.non_us_state.focus();
			return false;
		}
	}
	
	if(document.add_school.city.value.trim()=="")
	{
		alert("Please enter the address details (city)");
		document.add_school.city.focus();
		return false;
	}
	/*if(document.add_school.state.value.trim()=="")
	{
		alert("Please enter the address details (state)");
		document.add_school.state.focus();
		return false;
	}*/

	if(document.add_school.zip.value.trim()=="")
	{
		alert("Please enter the address details (zip code)");
		document.add_school.zip.focus();
		return false;
	}
	if(document.add_school.email.value.trim()=="")
	{
		alert("Please enter an email id for communication");
		document.add_school.email.focus();
		return false;
	}
	
	if (filter.test(str))
	{
	testresults=true
	}
	else
		{
	alert("Please enter a valid email id")
	document.add_school.email.focus();
	testresults=false;
	return (testresults)
	}
	/*if(document.add_school.speciality.value=="")
	{
		alert("Please select the speciality");
		document.add_school.speciality.focus();
		return false;
	}


	var dess=tinyMCE.getInstanceById('description').getHTML();*/
	if(document.add_school.description.value=="")
	{
	
	alert("Please enter a few lines about the school/insititution (1000 chars max.)");
	document.add_school.description.focus();
	return false;
	}

	
   if(theLogoFile!="")
   {
   for (i = 0; i < logoExt.length; i++)
   {
   if (logoExt[i] == readLogoExt) 
   {
   logoFileOK = 1; // one of the file extensions found
   } 
   }
   if (logoFileOK!=1) { 
   alert ("Please upload the flyer in JPEG/JPG format");
   return false;
   }
   }


   if(thePictrueFile!="")
   {
   for (i = 0; i < pictureExt.length; i++)
   {
   if (pictureExt[i] == readPictureExt) 
   {
   pictureFileOK = 1; // one of the file extensions found
   } 
   }
   if (pictureFileOK!=1) { 
   alert ("Please upload the flyer in JPEG/JPG format");
   return false;
   }
   }
    var user_clicks=confirm("Are you sure you want to update this record?");
		if (user_clicks==true)
		{
		}
		else
		{
			return false;
		}
   
   }

   function schoolDel()
   {
	    var user_clicked=confirm("Are you sure you want to delete this record?");
		if (user_clicked==true)
		{
		document.add_school.action="SchoolsEdit1.jsp";
		document.add_school.submit();
		}
		else
		{
			return false;
		}
   }
   
   /*******************************************************************/
   
   
   
   /* Validation for School Request form in SchoolRequest.jsp */
   
function requestValidate()
{
var str=document.request_form.email.value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,15})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

var requestSchooName=document.request_form.school_name.value.trim();
var requestSpecialityName=document.request_form.speciality_name.value.trim();
var requestSchoolId=document.request_form.school_id.value.trim();
var requestFirstName=document.request_form.first_name.value.trim();
var requestLastName=document.request_form.last_name.value.trim();
var requestAddress=document.request_form.address.value.trim();
var requestCity=document.request_form.city.value.trim();
var requestState=document.request_form.state.value.trim();
var requestCountry=document.request_form.country.value.trim();
var requestZip=document.request_form.zip.value.trim();
var requestPhone=document.request_form.phone.value.trim();
var requestEmail=document.request_form.email.value.trim();
var requestWhen=document.request_form.when.value.trim();
var requestAge=document.request_form.age.value.trim();
var requestEducation=document.request_form.education.value.trim();
var requestGraduation=document.request_form.graduation.value.trim();
var requestSchoolEmail=document.request_form.school_email.value.trim();
var requestUrl="http://www.niahc.net/SchoolRequest1.jsp?first_name="+requestFirstName+"&last_name="+requestLastName+"&address="+requestAddress+"&city="+requestCity+"&state="+requestState+"&country="+requestCountry+"&zip="+requestZip+"&phone="+requestPhone+"&email="+requestEmail+"&when="+requestWhen+"&age="+requestAge+"&education="+requestEducation+"&graduation="+requestGraduation+"&school_name="+requestSchooName+"&speciality_name="+requestSpecialityName+"&school_id="+requestSchoolId+"&school_email="+requestSchoolEmail+"";
if(requestFirstName=="")
{
alert("Please enter your first name");
document.request_form.first_name.focus();
return false;
}

if(requestLastName=="")
{
alert("Please enter your last name");
document.request_form.last_name.focus();
return false;
}

if(requestAddress=="")
{
alert("Please enter the address details (address line)");
document.request_form.address.focus();
return false;
}

/*if(requestState=="")
{
alert("Please enter the address details (state)");
document.request_form.state.focus();
return false;
}*/

if(requestCountry=="Select")
{
alert("Please enter the address details (country)");
document.request_form.country.focus();
return false;
}


	if(requestCountry=="United States") 
	{
		if(document.request_form.state.value=="Select")
		{
			alert("Please select the address details (state)");
			document.request_form.state.focus();
			return false;
		}
	}
	else
	{
		if(document.request_form.non_us_state.value.trim()=="")
		{
			alert("Please enter the address details (state)");
			document.request_form.non_us_state.focus();
			return false;
		}
	}

if(requestCity=="")
{
alert("Please enter the address details (city)");
document.request_form.city.focus();
return false;
}

if(requestZip=="")
{
alert("Please enter the address details (zip code)");
document.request_form.zip.focus();
return false;
}

if(requestPhone=="")
{
alert("Please enter your phone number");
document.request_form.phone.focus();
return false;
}

if(requestEmail=="")
{
alert("Please enter your email id");
document.request_form.email.focus();
return false;
}

if (filter.test(str))
	{
	testresults=true
	}
	else
		{
	alert("Please enter a valid email id")
	document.request_form.email.focus();
	testresults=false;
	return (testresults)
	}

if(requestWhen=="Select")
{
alert("Please select when you might start your studies");
document.request_form.when.focus();
return false;
}

if(requestAge=="Select")
{
alert("Please select your age");
document.request_form.age.focus();
return false;
}

if(requestEducation=="Select")
{
alert("Please select your highest level of education");
document.request_form.education.focus();
return false;
}
if(requestGraduation=="Select")
{
alert("Please select your high school graduation date");
document.request_form.graduation.focus();
return false;
}
//alert("Url = "+requestUrl);
//alert("B4");
//sendSchoolRequest(requestUrl);
//alert("A4");
//return false;
}

/* Send the mail to Administrator from SchoolRequest.jsp */

var schoolCheckHttp;

function sendSchoolRequest(getUrl) 
	{
try
 {
 // Firefox, Opera 8.0+, Safari
 schoolCheckHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 
 try
  {
  schoolCheckHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  schoolCheckHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
 if(schoolCheckHttp==null)
{
alert("Your Browser doesn't support HTTP request");
}
  /* Print the message to use while checking the database: */

  document.getElementById('mail_send').innerHTML = "<img src='images_school/sending1.gif'>";

  schoolCheckHttp.open("POST",getUrl, false);
  schoolCheckHttp.onreadystatechange = SchoolRequestHttpResponse;
  //topicCheckHttp.setRequestHeader("Content-length", parameters.length);
  schoolCheckHttp.setRequestHeader("Connection", "close");
  schoolCheckHttp.send(null);

}

function SchoolRequestHttpResponse() 
  {
	//  alert("Status = "+schoolCheckHttp.status);
  if (schoolCheckHttp.readyState == 4) 
  {
  if (schoolCheckHttp.status == 200) 
  {
	//alert(schoolCheckHttp.responseText);
	document.request_form.reset();
    document.getElementById('mail_send').innerHTML = "";
    alert("Your request has been sent successfully...");
  } 
  else 
  {
  alert('Server connectivity problem. Please try again later.');
  document.getElementById('mail_send').innerHTML = "";
  }

  }
}

/* Submit the values to SchoolFullView.jsp using Hyperlink(More...) from SchoolSearchResults.jsp */

function moreSubmit(form_id)
{
document.forms[form_id].action="SchoolFullView.jsp";
document.forms[form_id].submit();
}

function reqInfo()
{
document.request_form.action="SchoolRequest.jsp";
document.request_form.submit();
}


/* Send the mail to Administrator from SchoolRequest.jsp */

var emailCheckHttp;

function checkEmail(mailID) 
	{
	alert(mailID);
try
 {
 // Firefox, Opera 8.0+, Safari
 emailCheckHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 
 try
  {
  emailCheckHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  emailCheckHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
 if(emailCheckHttp==null)
{
alert("Your Browser doesn't support HTTP request");
}
  /* Print the message to use while checking the database: */

  //document.getElementById('mail_send').innerHTML = "<img src='images_school/sending1.gif'>";

  emailCheckHttp.open("POST","SchoolMailCheck.jsp?email="+mailID+"",true);
  emailCheckHttp.onreadystatechange = EmailRequestHttpResponse;
  //topicCheckHttp.setRequestHeader("Content-length", parameters.length);
  emailCheckHttp.setRequestHeader("Connection", "close");
  emailCheckHttp.send(null);

}

function EmailRequestHttpResponse() 
  {
	//var checkParam="Failed";
	//  alert("Status = "+schoolCheckHttp.status);
 // if (emailCheckHttp.readyState == 4) 
 // {
 	//alert("If One= "+emailCheckHttp.responseText);
  if (emailCheckHttp.status == 200) 
  {
  if(emailCheckHttp.responseText=="Please check your Email")
  {
  alert("Please check your email id");
	//test("Failed");
	   // return checkParam;
	   //return checkParam;
	}
	else
	{
	//var checkParam="Fialed";
		//test("Passed");
	}
	//document.request_form.reset();
    //document.getElementById('mail_send').innerHTML = "";
    //alert("If checkParam."+checkParam);
   // return "Failed";
  //} 
  /*else 
  {
  alert("Else = "+emailCheckHttp.responseText);
  //document.getElementById('mail_send').innerHTML = "";
  checkParam="Passed";
      alert("Else checkParam."+checkParam);
  }*/
    //results = topicCheckHttp.responseText;
	/////////alert("Sent");
    /* Again, we're assuming your username input ID is "username" */
    //var name = document.getElementById("username").value;
    /* If the username is available, Print this message: */
   // if(results == "") results = "<font color=\"green\"><i>"+name+"</i> Is Available!</font>";
  // return false;
  
 /* document.getElementById("full_name").value="";
  document.getElementById("day_phone").value="";
  document.getElementById("email").value="";
  //document.getElementById("interested").value;
 // document.getElementById("landscape").value;
  document.getElementById("other_explain").value="";
  document.getElementById("add_info").value="";
*/

  // window.location="chk.html";

 }
}

function test(value)
{
alert("Passed value = "+value);
}



/***** Assign selected country name to send Authorize.net page *****/

function assignCountryName()
   {
   var w = document.add_school.country.selectedIndex;
   var selected_text = document.add_school.country.options[w].text;
   document.add_school.countryName.value = selected_text;
   stateChangeAddUser();
   }

/***** End Of Assign selected country name to send Authorize.net page *****/

function stateChange()
{
var countryVal;

countryVal=document.school_search.country.value;
if(countryVal=="229") 
{

document.getElementById('div0').style.display="block";
document.getElementById('div1').style.display="none";
}
else
{

document.getElementById('div0').style.display="none";
document.getElementById('div1').style.display="block";
}

}

function stateChangeRequestForm()
{
var countryRequestVal;

countryRequestVal=document.request_form.country.value;
if(countryRequestVal=="United States") 
{
document.getElementById('div0').style.display="block";
document.getElementById('div1').style.display="none";
}
else
{

document.getElementById('div0').style.display="none";
document.getElementById('div1').style.display="block";
}

}



function stateChangeAddUser()
{
var countryUserAddVal;

countryUserAddVal=document.add_school.country.value;
if(countryUserAddVal=="229") 
{
document.add_school.non_us_state.disabled=true;
document.add_school.state.disabled=false;
}
else
{
document.add_school.non_us_state.disabled=false;
document.add_school.state.disabled=true;
//document.add_school.non_us_state.value="";
}
var ww = document.add_school.country.selectedIndex;
var selected_text1 = document.add_school.country.options[ww].text;
document.add_school.countryName.value = selected_text1;
}

function stateChangeUpdateUser()
{
var countryUserUpdateVal;

countryUserUpdateVal=document.add_school.country.value;
if(countryUserUpdateVal=="229") 
{
document.add_school.non_us_state.disabled=true;
document.add_school.state.disabled=false;
document.add_school.non_us_state.value="";
}
else
{
document.add_school.non_us_state.disabled=false;
document.add_school.state.disabled=true;
document.add_school.non_us_state.value="";
}

}


/***** Functions of select multiple Speciality in SchoolUserAdd file *****/

function dosubmit() 
{
}

function addOption(object,text,value) 
{	
var defaultSelected = true;
var selected = true;
var optionName = new Option(text, value, defaultSelected, selected)
object.options[object.length] = optionName;
}

function deleteOption(object,index) 
{
object.options[index] = null;
getSelectedSpeciality();
}

function copySelected(fromObject,toObject) 
{
for (var i=0, l=fromObject.options.length;i<l;i++) {

if (fromObject.options[i].selected)
{

addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
}

for (var i=fromObject.options.length-1;i>-1;i--) {

if (fromObject.options[i].selected)
{

deleteOption(fromObject,i);
}
}
getSelectedSpeciality();
}

function getSelectedSpeciality()
{
var selectedSpeciality=document.form1.speciality2;
var selectedSpecialityVal="";
for(var m=0;m<selectedSpeciality.length;m++)
{
selectedSpecialityVal+=selectedSpeciality.options[m].value+",";
}
document.form1.speciality.value=selectedSpecialityVal.substring(selectedSpecialityVal,selectedSpecialityVal.length-1);
//alert("Value of selectedSpeciality :"+document.add_school.speciality.value);
}
/***** End of functions of select multiple Speciality in SchoolUserAdd file *****/


/***** Function for concatenate selected state value into one variable *****/
function getSelectedState()
{
var selectedState=document.form1.state;
var selectedStateVal="";
for(var n=0;n<selectedState.length;n++)
{
if(selectedState.options[n].selected)
{
selectedStateVal+=selectedState.options[n].text+",";
}
}
document.form1.selectedState.value=selectedStateVal.substring(selectedStateVal,selectedStateVal.length-1);

//alert("Value of selectedStateVal :"+document.add_school.selectedState.value);
}

/***** End of function for concatenate selected state into one variable *****/

/***** Function for Comma Seperated *****/


function commaSeperator()
{
var otherSpeciality=document.form1.other.value.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/\s/g,' ').replace(/[\s]{2,}/g,'').replace(/[\s]{1,}/g,'').replace(/\,$/,'');

   if(otherSpeciality.charAt(0)==",")
    {
        alert("Do not start with a comma (,)");
        return false;
    }
    if(otherSpeciality.charAt(parseInt(otherSpeciality.length)-1)==",")
    {
        alert("Do not end with a comma (,)");
        return false;
    }
document.form1.other.value=otherSpeciality;
}

/***** End of function for Comma Seperated *****/