letsgo = '';
submitting = '';

function checkEnter(e){ //e is event object passed from function invocation
var characterCode; //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if character code is equal to ascii 13 (if enter key)
return false //return false to the event handler
}
else{
return true //return true to the event handler
}

}

function MM_validateForm() { //v5.0

ok="<img src='images/yes.gif'>";
nok="<img src='images/no.gif'>";
nokemail="<img src='images/no.gif'><span class=\"email_error\"> Email already exist</span>";
errorcolor='#FF9797';
formname=MM_validateForm.arguments[0];
clearTimeout(submitting);

errors='';

if (formname){
    var i,p,q,nm,test,num,min,max,args=MM_validateForm.arguments;
	for (i=1; i<(args.length-2); i+=3) { test=args[i+2]; val=formname[args[i]]; bg=formname[args[i]].style; bg.backgroundColor = 'white';
      if (val) { nm=val.name; var divname = nm + '_error'; if ((val=val.value)!="") {
		  document.getElementById(divname).innerHTML=ok;
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); q=val.indexOf('.');
          if ((p<1 || p==(val.length-1)) || (q<1 || q==(val.length-1))) { errors+='- '+nm+' must contain an e-mail address.\n'; bg.backgroundColor = errorcolor; document.getElementById(divname).innerHTML=nok; }
		} else if (test=='RisLet') {
			if (!isNaN(val)) {
			errors+='- '+nm+' must contain a letter.n'; bg.backgroundColor = errorcolor; document.getElementById(divname).innerHTML=nok;		}
		} else if (test!='R') { 
		num = parseFloat(val);
			  if (isNaN(val)) { 
			  errors+='- '+nm+' must contain a number.n'; bg.backgroundColor = errorcolor; document.getElementById(divname).innerHTML=nok;		  }          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) { errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; bg.backgroundColor = errorcolor; document.getElementById(divname).innerHTML=nok; } } } } else if (test.charAt(0) == 'R') {
			errors += '- '+nm+' is required.\n';
			bg.backgroundColor = errorcolor; 
			document.getElementById(divname).innerHTML=nok;
	} }
	
					if (val == 'Choose Business') {
						errors += '- '+nm+' is required.\n';
						bg.backgroundColor = errorcolor; 
						document.getElementById(divname).innerHTML=nok;
					}
					
					
					if (nm == 'password2') {
							if(formname.password.value != formname.password2.value) {
								errors+='- Passwords does not match.\n'; 
								formname.password2.style.backgroundColor = errorcolor;
								document.getElementById('password2_error').innerHTML=nok;
							}
					}
					
					if (nm == 'email2') {
							if(formname.email.value != formname.email2.value) {
								errors+='- Emails does not match.\n';
								formname.email2.style.backgroundColor = errorcolor;
								document.getElementById('email2_error').innerHTML=nok;
							}
					}
					
				
					if (nm == 'security') {
							SHA1encrypt_send();
					}

}
	
	if (letsgo==1) {
		submitting = setTimeout("Submission()",100);
	}
	
	} }
	
function Submission() {
	if (errors) {
		letsgo = '';
		alert('Sorry. Please correct the marked boxes above and submit again');
	} else {
		formname.submit();
	}
}
	
function debug(msg) {
	var text = document.getElementById('debug');
	text.value = text.value + ' , ' + msg;
}

function unhide(tdname) {
	document.getElementById(tdname).style.display='inline';
}

function hide(tdname) {
	document.getElementById(tdname).style.display='none';
}

function AJAXrequest() {
  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('ERROR!\nYou are using an outdated or uncompatible browser!\n\nPlease upgrade to FireFox (http://www.getfirefox.com)');
	 return false;
  }
  return http_request; // return the connection
}
var AJAX = AJAXrequest();
var AJAX2 = AJAXrequest();
//----------------------------------------------------------------------------------------------------//

function SHA1encrypt_send() {

	// get the password to encrypt from the field
	var pswd = document.getElementById('security').value;

	// check if its empty, if not we proceed
	if(pswd!=""){

		// build the post string
		var poststr = 'security=' + pswd + '&action=checkSHA1';

		// specify our AJAX file and also its params
		var url = '../include/AJAX.php';

		// open a new connection to our AJAX file and set as POST
		AJAX.open('POST', url, true);

		//************************************************************************************//
		// [-- DEBUG SECTION --]															*//
		//**********************************************************************************//
		//alert(poststr);
		//*********************************************************************************//

		// set our state change function
		AJAX.onreadystatechange = SHA1encrypt_recieve;

		// set headers and send away!
		AJAX.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		AJAX.setRequestHeader('Content-length', poststr.length);
		AJAX.setRequestHeader('Connection', 'close');
		AJAX.send(poststr);

	}
}

function SHA1encrypt_recieve() {

	// is the response ready?
	if (AJAX.readyState == 4) {
		if (AJAX.status == 200) {

			// ok, our response is ready, lets store it in a var
			SHApswd = '';
			SHApswd = AJAX.responseText;

			security2_send();
			//************************************************************************************//
			// [-- DEBUG SECTION --]															*//
			//**********************************************************************************//
			
			//*********************************************************************************//
		}
	}
}

function security2_send() {

	// get the password to encrypt from the field
	var pswd = document.getElementById('security').value;

	// check if its empty, if not we proceed
	if(pswd!=""){

		// build the post string
		var poststr = 'security=' + pswd + '&action=security2';

		// specify our AJAX file and also its params
		var url = '../include/AJAX.php';

		// open a new connection to our AJAX file and set as POST
		AJAX.open('POST', url, true);

		//************************************************************************************//
		// [-- DEBUG SECTION --]															*//
		//**********************************************************************************//
		//alert(poststr);
		//*********************************************************************************//

		// set our state change function
		AJAX.onreadystatechange = security2_receive;
		

		// set headers and send away!
		AJAX.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		AJAX.setRequestHeader('Content-length', poststr.length);
		AJAX.setRequestHeader('Connection', 'close');
		AJAX.send(poststr);

	}
}

function security2_receive() {

	// is the response ready?
	if (AJAX.readyState == 4) {
		if (AJAX.status == 200) {

			// ok, our response is ready, lets store it in a var
			SHApswd2 = AJAX.responseText;
			//alert(SHApswd);
			//alert(SHApswd2);
			//alert(formname.security2.value);
							if(SHApswd != SHApswd2) {
								errors+='- Security code does not match.\n';
								formname.security.style.backgroundColor = errorcolor;
								document.getElementById('security_error').innerHTML=nok;
								letsgo = '';
							} else {
								formname.security.style.backgroundColor = '#FFFFFF';
								document.getElementById('security_error').innerHTML=ok;
							}
			
			//************************************************************************************//
			// [-- DEBUG SECTION --]															*//
			//**********************************************************************************//
			
			//*********************************************************************************//
		}
	}
}

function checkemail_send() {

	// get the password to encrypt from the field
	var pswdm = formname.email.value;

	// check if its empty, if not we proceed
	if(pswdm!=""){

		// build the post string
		var poststrm = 'email=' + pswdm + '&action=emailcheck';

		// specify our AJAX file and also its params
		var url = '../include/AJAX.php';

		// open a new connection to our AJAX file and set as POST
		AJAX2.open('POST', url, true);

		//************************************************************************************//
		// [-- DEBUG SECTION --]															*//
		//**********************************************************************************//
		//alert(poststrm);
		//*********************************************************************************//
		// set our state change function
		AJAX2.onreadystatechange = checkemail_receive;

		// set headers and send away!
		AJAX2.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		AJAX2.setRequestHeader('Content-length', poststrm.length);
		AJAX2.setRequestHeader('Connection', 'close');
		AJAX2.send(poststrm);

	}
}

function checkemail_receive() {

	// is the response ready?
	if (AJAX2.readyState == 4) {
		if (AJAX2.status == 200) {

			// ok, our response is ready, lets store it in a var
			checkemail = '';
			checkemail = AJAX2.responseText;

			if(checkemail == 'BAD') {
								errors+='- Email already in database.\n';
								letsgo = '';
								formname.email.style.backgroundColor = errorcolor;
								document.getElementById('email_error').innerHTML=nokemail;
							}
						
								
			//************************************************************************************//
			// [-- DEBUG SECTION --]															*//
			//**********************************************************************************//
			
			//*********************************************************************************//
		}
	}
}

function removeElement(i,tablename){
    document.getElementById(tablename).deleteRow(i)
}

function addEvent(obj, evType, fn){ 
if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
} else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
} else { 
   return false; 
} 
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}