
// JavaScript Document
function validateEmail(elementValue){      
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue); 
 }
 
function generate_pin(email_add) {
	
	if(email_add=="") {
		
		alert("Please enter your email address to obtain a pin.");

	}else if(!validateEmail(email_add)) {
		
		alert("Your email address must be in the format of name@domain.com");
		
	}else if(document.getElementById('terms').checked==false) {
		
		alert("Please read the terms and conditions and click the tickbox to agree.")
		
	}else{ 
		
		document.getElementById('busy_icon').src = "/images/busy.gif";

		var MsgDOM = document.getElementById("pin_span");
		var ranNum= Math.round((999999-100000) * Math.random() + 100000);
	
	
		_xmlHttp = getXMLHTTP(); 
		_xmlHttp.open("GET","/ajax/email_pin.php?email="+escape(email_add)+"&pin="+ranNum);
		
		_xmlHttp.onreadystatechange=function() {
		  
		  if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
		  
				var html = _xmlHttp.responseText;
	
				if(html=="ok") {
					
					MsgDOM.innerHTML = ranNum;
				
				}else{
					
					MsgDOM.innerHTML = html;
					
				}
				
				document.getElementById('busy_icon').src = "/images/tick.gif";
			  
		  }
		}
		;
		_xmlHttp.send(null)
	}
}

function caller_action(a, clid, pc) {
	
	document.getElementById('busy_text').innerHTML = "Please wait...";
	document.getElementById('busy_icon').src = "/images/busy.gif";


	_xmlHttp = getXMLHTTP(); 
	
	_xmlHttp.open("GET","/ajax/caller.php?action="+a+"&clid="+escape(clid)+"&pc="+pc);
	
	_xmlHttp.onreadystatechange=function() {
	  
	  if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
	  
			var html = _xmlHttp.responseText;

			document.getElementById('busy_icon').src = "/images/tick.gif";
			
			document.getElementById('busy_text').innerHTML = "Caller "+html+".";
			
			if(a=="kick") { document.location.href='/beta/my-account/room/callers/&passcode='+pc; }
		  
	  }
	}
	;
	_xmlHttp.send(null)
	
	
}

function getXMLHTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
  }
  return A
}

