

 Validate = function()	{

	 var objForm = document.forms[0];
	 
	 /// validation for username
	objForm.username.required = 1;
	objForm.username.regexp = VALIDATE_CHAR;
	objForm.username.realname="The 'username' field should not contain special character(s) and should not be left blank.";
	
	//objForm.Company.required = 1;
	//objForm.Company.regexp = VALIDATE_CHAR;
	objForm.Company.realname="The 'Compamy' field should not contain special character(s) and should not be left blank.";
	
	objForm.ContactPhone.required = 1;
	objForm.ContactPhone.regexp = VALIDATION_TELEPHONE;
	objForm.ContactPhone.realname="The 'Phone Number' field should not contain special character(s) and should not be left blank.";
	
	objForm.Email.required = 1;
	objForm.Email.regexp = VALIDATION_EMAIL;
	objForm.Email.realname="The 'Email Address' field should not contain special character(s) and should not be left blank.";
			   
	return validateCompleteForm2(objForm,'');
}


function validateCompleteForm2(objForm,strErrorClass){
	return _showMsg(objForm,strErrorClass,0);
}

function _showMsg(form,strErrorClass,nErrorThrowType){
	var strErrorMessage="";
	var objFirstError=null;
	if(nErrorThrowType==0){
		strErrorMessage=(form.err)?form.err:_getLanguageText("err_form");
	}
	
	var fields=_GenerateFormFields(form);
	var iCount = 0;
	var i; 

	for(i=0;i<fields.length;++i){
	
		var field=fields[i];

		if(!field.IsValid(fields)){
		
			field.SetClass(strErrorClass);
			if(nErrorThrowType==1){
				_throwError(field);
				return false;
			}else{
				if(objFirstError==null){
					objFirstError=field;
				}
				document.getElementById(field.element.id).parentNode.className = "error";
				document.getElementById(field.element.id).parentNode.getElementsByTagName("span")[0].style.display = "inline";
				document.getElementById(field.element.id).parentNode.getElementsByTagName("span")[0].className = "error";
				//strErrorMessage=_handleError(field,strErrorMessage,++iCount);
				bError=true;
			}
		}else{
			if((field.element.id != "undefined") && (field.element.id.toString() != "") && (document.getElementById(field.element.id).parentNode != "undefined"))	{
				document.getElementById(field.element.id).parentNode.className = "";
				if(document.getElementById(field.element.id).parentNode.getElementsByTagName("span").length > 0)	{
					document.getElementById(field.element.id).parentNode.getElementsByTagName("span")[0].style.display = "none";
					document.getElementById(field.element.id).parentNode.getElementsByTagName("span")[0].className = "";		
				}
			}
			field.ResetClass();
		}
	}
	if(objFirstError!=null){
		//alert(strErrorMessage);
		objFirstError.element.focus();
		return false;
	}
	return true;
}

// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
  	if(inputs[i].type == 'text')	{
		inputs[i].onfocus = function () {
		  if(this.parentNode.className == "")	{
			  this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			  this.parentNode.className = "kindagood";
		  }
		}
		inputs[i].onblur = function () {
		  this.parentNode.getElementsByTagName("span")[0].style.display = "none";
		  this.parentNode.className = "";
		}
	}
  }
}


function addDOMLoadEvent(func) {
   if (!window.__load_events) {
      var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i=0;i < window.__load_events.length;i++) {
              window.__load_events[i]();
          }
          window.__load_events = null;
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
      
      // for Internet Explorer
      /*@cc_on @*/
      /*@if (@_win32)
          document.write("<scr"+"ipt id=__ie_onload defer src=//0><\/scr"+"ipt>");
          var script = document.getElementById("__ie_onload");
          script.onreadystatechange = function() {
              if (this.readyState == "complete") {
                  init(); // call the onload handler
              }
          };
      /*@end @*/
      
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      
      // create event function stack
      window.__load_events = [];
   }
   
   // add function to event stack
   window.__load_events.push(func);
}


