// form validation function

// var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;

function trim(str) {

  return str.replace(/^\s+|\s+$/g, '');

}

<!------------------->



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;

   }

//Check float number
function isFloat(strString)
   //  check for valid float number
{
   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;
} 
// START OF MESSAGE SCRIPT //



var MSGTIMER = 60;

var MSGSPEED = 5;

var MSGOFFSET = 3;

var MSGHIDE = 3;



// build out the divs, set attributes and call the fade function //

function inlineMsg(target,string,autohide) {

  var msg;

  var msgcontent;

  if(!document.getElementById('msg')) {

    msg = document.createElement('div');

    msg.id = 'msg';

    msgcontent = document.createElement('div');

    msgcontent.id = 'msgcontent';

    document.body.appendChild(msg);

    msg.appendChild(msgcontent);

    msg.style.filter = 'alpha(opacity=0)';

    msg.style.opacity = 0;

    msg.alpha = 0;

  } else {

    msg = document.getElementById('msg');

    msgcontent = document.getElementById('msgcontent');

  }

  msgcontent.innerHTML = string;

  msg.style.display = 'block';

  var msgheight = msg.offsetHeight;

  var targetdiv = document.getElementById(target);

  targetdiv.focus();

  var targetheight = targetdiv.offsetHeight;

  var targetwidth = targetdiv.offsetWidth;

  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);

  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;

  msg.style.top = topposition + 'px';

  msg.style.left = leftposition + 'px';

  clearInterval(msg.timer);

  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);

  if(!autohide) {

    autohide = MSGHIDE;  

  }

  window.setTimeout("hideMsg()", (autohide * 2000));

}



// hide the form alert //

function hideMsg(msg) {

  var msg = document.getElementById('msg');

  if(!msg.timer) {

    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);

  }

}



// face the message box //

function fadeMsg(flag) {

  if(flag == null) {

    flag = 1;

  }

  var msg = document.getElementById('msg');

  var value;

  if(flag == 1) {

    value = msg.alpha + MSGSPEED;

  } else {

    value = msg.alpha - MSGSPEED;

  }

  msg.alpha = value;

  msg.style.opacity = (value / 100);

  msg.style.filter = 'alpha(opacity=' + value + ')';

  if(value >= 99) {

    clearInterval(msg.timer);

    msg.timer = null;

  } else if(value <= 1) {

    msg.style.display = "none";

    clearInterval(msg.timer);

  }

}



// calculate the position of the element in relation to the left of the browser //

function leftPosition(target) {

  var left = 0;

  if(target.offsetParent) {

    while(1) {

      left += target.offsetLeft;

      if(!target.offsetParent) {

        break;

      }

      target = target.offsetParent;

    }

  } else if(target.x) {

    left += target.x;

  }

  return left;

}



// calculate the position of the element in relation to the top of the browser window //

function topPosition(target) {

  var top = 0;

  if(target.offsetParent) {

    while(1) {

      top += target.offsetTop;

      if(!target.offsetParent) {

        break;

      }

      target = target.offsetParent;

    }

  } else if(target.y) {

    top += target.y;

  }

  return top;

}



// preload the arrow //

if(document.images) {

  arrow = new Image(7,80); 

  arrow.src = "msg_arrow.gif"; 

}





//common.js by anoop





/******************************************

Code : Vinod Suthar	

Common JS function 

********************************************/

/*Function to check the CheckBox is Selcted or not..*/

function isChecked(isitchecked){

	

	if (isitchecked == true){

		document.frm_hidden.boxchecked.value++;

	}

	else {

		document.frm_hidden.boxchecked.value--;

	}

}//Function Ends









//Number Validation 

function numberOnly(field){

		

	var fieldVal = document.getElementById(field).value;

	var phoneRegex = /^[0-9]+(([\- ][0-9 ])?[0-9]*)*$/;

	if(!fieldVal.match(phoneRegex)) {

		document.getElementById(field).value="";

	  inlineMsg(field,'Only numbers Allowed.',2);

	  

	  return false;

  } return true;

	}





<!-------------------------------------------------------------------------------------------------------------------------
// Script function to validate data related to buyer registration module form 
function validateForm(form)
{ 

  var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?"; 
  
  var scholarshiptype1      = form.scholarshiptype1.checked;
  var scholarshiptype2      = form.scholarshiptype2.checked;
  var lname  				= trim(form.lname.value);
  var fname 				= trim(form.fname.value);
  

  var address 				= trim(form.address.value);
  var city  				= trim(form.city.value);
  var state 				= trim(form.state.value);
  var zip 				    = trim(form.zip.value);
  var areacode 				= trim(form.areacode.value);
  var phone 				= form.phone.value;
  var email                 = trim(form.email.value);
  var emailRegex            = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
  
  var currentstatus1       = form.infreshman.checked;
  var currentstatus2       = form.constudent.checked;
  var currentstatus3       = form.comct.checked;
  
  var majorcourseofstudy 		= trim(form.majorcourseofstudy.value);
  var expectedgraduationdate 	= trim(form.expectedgraduationdate.value);
  
  var schoolname 				= trim(form.schoolname.value);
  var schoollocation 			= trim(form.schoollocation.value);
  var highschool 				= trim(form.highschool.value);
  var graduationdate 			= trim(form.graduationdate.value);
  
  var college 				    = trim(form.college.value);
  var colggraduationdate 		= trim(form.colggraduationdate.value);
  
  var volact                    = trim(form.volact.value);
  var achievements              = trim(form.achievements.value);
  var cplan                     = trim(form.cplan.value);
  var awardutilization          = trim(form.awardutilization.value);
  var spconsideration           = trim(form.spconsideration.value);
  var signature                 = trim(form.signature.value);
  var applieddate               = trim(form.applieddate.value);
  
  
  
  
  
   if(scholarshiptype1 == false && scholarshiptype2 == false)
   {
	  inlineMsg('scholarshiptype1','Please Select type of scholarship.',2);
	   return false;  
   }
   
   if(lname =="")
   {
	   inlineMsg('lname','Please Enter Your Last Name.',2);
	   return false;
   }
   
   if(fname =="")
   {
	   inlineMsg('fname','Please Enter Your First Name.',2);
	   return false;
   }
  

 
  if(address == "") {
    inlineMsg('address','Please Enter Your Street Address.',2);
	return false;
   }
 
  if(city == "") {
    inlineMsg('city','Please Enter Your City Name.',2);
	return false;
  }
  if(state == "") {
    inlineMsg('state','Please Enter Your State Name.',2);
	return false;
  }
  if(zip == "") {
    inlineMsg('zip','Please Enter Your Zip-Code.',2);
	return false;
  }

  if(!IsNumeric(zip) )
    {
	inlineMsg('zip','Please Enter Only Digits In Zip-Code Field.',2);
	return false;	
	}
	
  if(areacode == "") {
    inlineMsg('areacode','Please Enter Your area code.',2);
	return false;
  }
  
 if(!IsNumeric(areacode) )
    {
	inlineMsg('areacode','Please Enter Only Digits In area code Field.',2);
	return false;	
	}

 if(phone == "") {
    inlineMsg('phone','Please Enter Your Phone No.',2);
	return false;
  }
  
 if(!IsNumeric(phone) )
    {
	inlineMsg('phone','Please Enter Only Digits In Phone Field.',2);
	return false;	
	}
  
 if(email == "") {
    inlineMsg('email','You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','You have entered an invalid email.',2);
    return false;
  }
  
  
  if((currentstatus1 == false) && (currentstatus2 == false) && (currentstatus3 == false)) {
    inlineMsg('infreshman','Select you current status.',2);
    return false;
    }
	
   
   if(majorcourseofstudy == "") {
    inlineMsg('majorcourseofstudy','Please Enter your major course of study.',2);
    return false;
  }
  
    if(expectedgraduationdate == "") {
    inlineMsg('expectedgraduationdate','Please Select your expected date of graduation .',2);
    return false;
  }
  
  if(schoolname == "") {
    inlineMsg('schoolname','Please Enter your  current/ most recent school name .',2);
    return false;
  }
  
    if(schoollocation == "") {
    inlineMsg('schoollocation','Please Enter your  current/ most recent school location .',2);
    return false;
  }
  
  if(form.schlistedabove1.checked == true) {
	  
	  if(highschool =="")
	  {
        inlineMsg('highschool','Please Enter your  high school name .',2);
        return false;
	  }
	  
	  if(graduationdate =="")
	  {
        inlineMsg('graduationdate','Please Select graduation date .',2);
        return false;
	  }
  }
  
  
   if(form.schlistedabove2.checked == true) {
	  
	  if(college =="")
	  {
        inlineMsg('college','Please Enter your  college name .',2);
        return false;
	  }
	  
	  if(colggraduationdate =="")
	  {
        inlineMsg('colggraduationdate','Please Select  Attended date .',2);
        return false;
	  }
  }
  
    if(volact == "") {
    inlineMsg('volact','Please fill your text here.',2);
    return false;
  }
    if(achievements == "") {
    inlineMsg('achievements','Please fill your text here .',2);
    return false;
  }
    if(cplan == "") {
    inlineMsg('cplan','Please fill your text here .',2);
    return false;
  }
    if(awardutilization == "") {
    inlineMsg('awardutilization','Please fill your text here .',2);
    return false;
  }
    if(spconsideration == "") {
    inlineMsg('spconsideration','Please fill your text here .',2);
    return false;
  }
    if(signature == "") {
    inlineMsg('signature','Please Enter your name .',2);
    return false;
  }
    if(applieddate == "") {
    inlineMsg('applieddate','Please select date .',2);
    return false;
  }
  
  if(form.accept.checked ==false)
	  {
        inlineMsg('accept','Please Accept certification .',2);
        return false;
	  }
	  
 return true;
}

