/* LAST UPDATED: 1:29:50am 19 May 2010 */ var bmXserver = 'http://www.beamme.info';
var bmXloopback = '1';var _wnu = window.navigator.userAgent;
var bmXData = {};
var bmX = {
	
	appVersion:1,
	loaded:0,
	loadTimeout:10,
	loadTimer:0,
	_db:document.body,
	count:0,
	/*ad:[],*/
	indTimeout:0,
	method:"SMS",
	loc: 0,
	infoLast: "",
	saf:(_wnu.match(/Safari/i)),
	/*opera:(_wnu.match(/Opera/i)),*/
	ie:(_wnu.match(/MSIE/i)),
	/*chrome:(_wnu.match(/Chrome/i)),*/
	action:bmXserver+"/beam-send/",
	icon:bmXserver+"/images/beamicon/beamme_{rep}.gif",
	mobile: null,
	data:[],	
	stateTimer:0,
	requestID:-1,
	securityMsg:"Security Blocking Active - Please visit your BeamMe Website Security Settings and update your Serving Addresses", 
	hLen:history.length,
	hash:document.location.hash,
	time:new Date().getTime(),
	termsChecked: false,
	wait:3000,
	
	/*
	Retrieve the beambox from the page elements
	*/
	getEl:function(q)
	{		
		var i = bmX.tag("SPAN");	
		
		/*
					
		var m = new RegExp("^beamBox"+((q)?"":"$"), "i");		
		var k = (bmX.ie && typeof(q) == "undefined");
		for (x = (k) ? i.length-1 : 0; eval((k ? "x >= 0" : "x < i.length")); eval((k ? "x--" : "x++"))) {					
			var r = i[x].getAttribute("title");
			if (r && r.match(m)) {
				i[x].removeAttribute("title");
				return i[x];
			}
		}		 
		return false;
		*/
		
		/*
		IE adds events backwards so step backward through elements to get our beamboxes
		do not do this when processing multiple beam boxes in the same page using the
		page footer loading scenario
		*/
		var m = new RegExp("^beamBox"+((q)?"":"$"), "i");
		if (bmX.ie && typeof(q) == "undefined") {
			var l = i.length-1;
			for (var x = l; x >= 0; x --) {
				var r = i[x].getAttribute("title");
				if (r && r.match(m)) {
					i[x].removeAttribute("title");
					return i[x];
				}
			}
		}
		else {
			for (var x = 0; x < i.length; x ++) {
				var r = i[x].getAttribute("title");
				if (r && r.match(m)) {
					i[x].removeAttribute("title");
					return i[x];
				}
			}
		}	
		return false;	
	},
	
	trim: function(s)
	{
		return s.replace(/^\s+|\s+$/g, '');
	},
	
	/*
	Create HTML beambox
	*/
	apply: function(v,q,w)
	{
		bmX._db = document.body;
		var i = bmX.getEl(q);		
		if (i) {
			i.id = "bmXi_"+v;	
			/* this is a page listing beam */
			if (q != null) {
				i.innerHTML = i.innerHTML.replace(/-->\s*$/, "").replace(/^\s*<\!--/, "");	
				/* IE ignores newlines or no new lines so add them in transparently */			
				if (bmX.ie || ! i.innerHTML.match(/\r\n|\n/g)) {					
					bmX.data[v].rawData = bmX.replaceVars(i.innerHTML.replace(/(beam(box|ad)?_[a-z_]+):/gi, "\n$1:").replace(/<br ?\/?>/ig, "\n"));
				}
				else {
					bmX.data[v].rawData = bmX.replaceVars(i.innerHTML.replace(/<br ?\/?>/g, ""));
				}
				i.style.cursor = "pointer";
			}
			/* standard beam */
			else {							
				var s = bmX.prev(i, "SCRIPT");
				bmX.data[v].rawData = bmX.replaceVars(s.innerHTML);			
				bmX.remove(s);
			}	
			/* replace whitespace once */
			bmX.data[v].rawData = bmX.trim(bmX.data[v].rawData);
			/* now show button etc */
			if (! bmX.data[v].status) {
				i.className = "bmXwrap";
				/* open beambox */		
				if (w == null) {
					bmX.createButton(v, 0);
					bmX.template(v);
				}
				else {
					bmX.createButton(v, 1);
				}
			}
			/* security wont allow display */
			else if (bmX.dataParam(v, "security")) {
				bmX.fail(v, bmX.securityMsg);
			}
			
			/* run load if needed */
			if (! bmX.loaded) bmX.go();
		}
		else if (bmX.data[v].status == "incorrect domain") {
			bmX.fail(v, bmX.securityMsg);
		}
	},
	
	/* Create button for displaying on webpage */
	createButton: function(v, oc)
	{
		var i = bmX.id("i_" + v), 
		is = bmX.priorityParam(v,"_icon"), 
		t = bmX.priorityParam(v,"_label"); 
				
		i.innerHTML = "";				
		i.onclick = (oc) ? new Function("bmX.request("+v+",this);") : new Function("bmX.open("+v+",this);");
		i.defaultText = (t&&t.length) ? t : "Send to mobile";
				
		with(i.appendChild(bmX.create("img"))) {
			src = bmX.icon.replace(/\{rep\}/, (is ? is.replace(/[^0-9]/, "") : "12"));	
			onload = function() { if (bmX.id("iframe")) setTimeout('if (!bmX.ie) bmX.id("iframe").src = "about:blank"', 10); };
		}
		with (i.appendChild(bmX.create("a"))) {
			href="#";
			onclick = function() { return false };
			innerHTML = i.defaultText;
			style.outline = "none";
			className = "bmXtext";
			id = "bmXlx_"+v;
		}		
		
		for (var c = i.childNodes, h = 0, w = 0; w < c.length; w ++) {
			if (! isNaN(c[w].offsetHeight) && c[w].offsetHeight > h) {
				h = c[w].offsetHeight;
			}
			if (c[w].style) {
				c[w].style.verticalAlign = "middle";
			}
		}
				
		/*i.firstChild.style.marginRight = "4px";*/
		var im = bmX.tag("IMG",i)[0];
		im.style.marginRight = "4px";	
		im.style.display = "inline";	
		i.style.display = "";
		i.style.visibility = "visible";
												
		if(! bmX.id("iframe")) {
			var d2 = bmX.create("div");
			var css = "div.bmXpop{background:#fff;border:1px solid #8a8a8a;text-align:left;position:absolute;display:none;line-height:13px;width:234px;padding:2px 6px 3px 6px;margin:0;font:11px arial;z-index:1000}"+
			"a.bmXa{outline:none;text-decoration:underline;padding:0;margin:0;display:inline}"+
			"a.bmXa:hover{background:none}"+
			"div.bmXpop img{border:0;display:inline;margin:0}"+
			"div.bmXpop span{font:11px arial}"+
			"div.bmXpop div{margin:0;text-align:left;display:block;font:11px arial}"+
			"div.bmXpop p{margin:5px 0;color:#666;line-height:1em;display:block;text-align:left;font:11px arial}"+
			"div.bmXpop div.lenMsg{margin:0;padding:0 0 4px 0;display:none}"+
			"div.bmXpop div.sendMsg{display:block;margin:0;text-align:center;padding:7px 0 10px 0}"+
			"div.bmXpop div.noPad{padding:0;text-align:center}"+
			"div.bmXpop div.info{padding:0 0 4px 0;margin:0;font:11px arial;overflow:hidden}";
			var html = "<iframe id=\"bmXiframe\" name=\"bmXiframe\" src=\"" + location.protocol + "//" + location.host + "/about:blank\" width=\"100%\" height=\"0\" frameborder=\"0\"></iframe>";
			d2.innerHTML = html;
			d2.style.display = "none";
			bmX._db.insertBefore(d2, bmX._db.firstChild);
			bmX.css(css, "global");
		}
			
		var d = bmX.create("div");
		d.className = "bmXpop";
		d.id = "bmX_"+v;
		d.innerHTML = "<div style='padding:10px'>one moment while we contact the service <span id=\"bmXind_"+v+"\"></span></div>";				
		bmX._db.appendChild(d);
	},
	
	/*
	Update HTML displayed in Beambox
	*/
	template: function(v, rm)
	{		
		if (bmX.data[v].status) {
			switch (bmX.data[v].status) {
				case "paused" : case "stopped" : bmX.fail(v, "This service has been paused and is currently unavailable."); break;		
				case "invalid-beam" : bmX.fail(v, "This does not appear to be a valid beam. Webmasters: please check you have correctly copied your code block from the website"); break;
			}
			return false;
		}
		var ti = (10 + (v * 1));
		var i = bmX.id("i_" + v),
		ic = bmX.icon.replace(/\{rep\}/, (bmX.style(v,"logo").toLowerCase() == "on") ? "logo_new" : 14), 
		ns = (bmX.data[v].beamsecurity && bmX.data[v].beamsecurity == 1);
		if (! ns) {		
			if (bmX.loc == 0) {				
				/* default to aus */
				if (! bmX.data[v].country.length) {
					bmX.data[v].country = "AU";
				}
				bmX.loc = bmX.data[v].country;
			}
			var g = (bmXcntry[bmX.loc]) ? bmXcntry[bmX.loc] : 0, 
			lc = (g) ? bmX.loc + "+" + g.p : "", 
			/*pt = (bmX.saf) ? 19 : 22,*/
			cp = bmX.data[v].beam_cost;
			bmX.data[v].charged = (cp && cp != 0), 
			s2 = "display:none;width:100%;outline:none;left:0;", 
			//s3 = "display:block;position:relative;text-decoration:none;z-index:1004;padding:0 2px 2px 2px;width:55px;font:bold 13px arial;";
			s3 = "position:absolute;text-decoration:none;z-index:1004;font:bold 12px arial;top:4px;left:41px;";
						
			/* styling for email */
			var iW = (! bmX.data[v].charged) ? ((bmX.ie) ? 146 : 145) : 50, iP = 48, iX = 37;
			/*if (bmX.param(v, "_email")) {
				//var iW = (! bmX.data[v].charged) ? "57" : "33", iP = 99, iX = 45;
				var iW = (! bmX.data[v].charged) ? "139px" : "33%", iP = 77, iX = 45;
			}
			else {
				//var iW = (! bmX.data[v].charged) ? "74%" : "50%", iP = 59, iX = 0;
				var iW = (! bmX.data[v].charged) ? ((bmX.ie) ? 149 : 148) : "50", iP = 45, iX = 37;
			}*/
			
			/*
			removed from post action - &origin="+encodeURIComponent(document.location.href)+"
			*/
			var html = '<form style="padding:0;margin:0" action="' + bmX.action.replace(/^https?/,bmX.protocol) + '?id='+v+'&adsup='+bmX.data[v].ad+'" method="post" id="bmXf_'+v+'" onsubmit="return bmX.send('+v+')">'+bmX.hidden("version","",String(bmX.appVersion))+bmX.hidden("advert","ad_"+v,"")+bmX.hidden("adcat","adcat_"+v,bmX.param(v,"ad_category"))+bmX.hidden("adpl","adpl_"+v,bmX.param(v,"ad_placement"))+bmX.hidden("uid","uid_"+v,bmX.data[v].uid)+bmX.hidden("token","token_"+v,"")+bmX.hidden("mid",/*"mid_" + v*/"","")+bmX.hidden("caller_id",/*"mid_" + v*/"","") + '<div style="padding-bottom:5px">';
			
			if (! bmX.param(v,"_to")) {
				html += bmX.hidden("message","details_"+v,/*bmX.data[v].rawData*/"");
			}
			
			var lnks = bmX.param(v, "_links");
			if (! lnks || lnks.toLowerCase() == "on") {
				lnks = bmX.link(v,"message",'Message')+bmX.link(v,"privacy",'Privacy')+bmX.link(v,"help",'Help')+bmX.link(v,"info",'Info');				
			}
			if (lnks && lnks.length) {
				html += lnks;
			}
			else {
				html += '<a href="#" style="text-decoration:none">&nbsp;</a>';
			}

			if (bmX.data[v].charged) {
				html+=bmX.link(v,"pin",'No Pin?');
			}

			/*"+((cp&&cp!=0)?" onblur=\"bmX.lookup("+v+",0)\"" : "")+"*/		
			
			html+='<img src="'+bmXserver+'/images/beamicon/beamlock.png" width="10" height="12" style="position:absolute;right:5px;top:3px" /></div><div id="bmXml_'+v+'" style="display:none"></div><div id="bmXC_'+v+'" style="padding:0;margin:0">';
						
			for (var q = 0; q < 2; q ++) {
				
				var rW = iW, rP = iP, dsp = '';
				
				switch(q) {
					
					// mobile input
					case 0 :
						var inc = ["To", "mobile", (bmX.param(v,"_to")) ? bmX.param(v,"_to") : bmX.msg, "country", "validKey"]; 		
						if (bmX.param(v, "_email"))	{
							rW -= 34;
							rP += 34;
						}
						if (bmX.param(v,"_to")) {
							dsp = 'none';
						}
					break;
					
					// sender input
					case 1 :
						// no caller id						
						if (bmX.dataParam(v, "box_caller_override") != "yes" && ! bmX.param(v,"_to")) {
							continue;
						}
						var inc = ["From", "sender", bmX.param(v,"_to") ? (bmX.param(v,"_from_default") ? bmX.param(v,"_from_default") : bmX.msgSend2) : bmX.msgSend, "sendcountry", "validKey"]; 						
					break;
					
				}
							
				html += '<div class="cont" style="display:'+dsp+'"><span style="position:absolute">&nbsp;'+inc[0]+'</span><input type="text" id="bmX'+inc[1]+"_"+v+'" name="'+inc[1]+'" value="'+inc[2]+"\" autocomplete=\"off\" onclick=\"if(this.value=='"+inc[2]+"') this.value='';\" class=\"input\" style=\"width:"+rW+"px;padding:2px 2px 2px "+rP+'px" onkeydown="return bmX.validKey(event,'+v+')" tabindex="'+ti+""+q+'" />';
					
				if (!q && bmX.data[v].charged) {
					html += '<input type="password" name="pin" class="input" style="width:44px;margin-left:4px;_margin-left:3px;padding:1px 3px;font-size:13px" maxlength="4" onkeyup="if(this.value.length==4){bmX.lookup('+v+');}" />';
				}				
				
				/* type link */
				var rm = 0;
				if (!q && bmX.param(v, "_email")) {
					html += '<a class="bmXa" style="'+s3+';left:88px" id="bmXtlb_'+v+"\" href=\"#\" onclick=\"bmX.id('type_"+v+"').style.display='';bmX.id('type_"+v+"').focus();bmX.set("+v+');return false">SMS</a>';
					var rm = 4;
				}
				
				/* Country dropdown */
				var chtml = '<select class="input" id="bmX'+inc[3]+"_"+v+'" name="'+inc[3]+'" style="'+s2+";margin-bottom:3px;padding:0 2px\" onblur=\"this.style.display='none';bmX.set("+v+')" onchange="bmX.locUpdate(this,'+v+');">';
				var cLen = 0;
				for (var w in bmXcntry) {
					var e = bmXcntry[w];
					chtml += "<option value=\""+w+"\"";			
					if (w == bmX.data[v].country) {
						chtml += " selected=\"selected\"";
					}
					chtml += ">" + e.n + "</option>";
					cLen ++;
				}
				chtml += "</select>";
							
				/* country link */
				html += "<a class=\"bmXa\" style=\""+s3+";cursor:"+((cLen==1)?"default":"pointer")+"\" id=\"bmX"+inc[3]+"loc_"+v+"\" href=\"#\" onclick=\"" + ((cLen>1) ? "bmX.id('"+inc[3]+"_"+v+"').style.display='';bmX.id('"+inc[3]+"_"+v+"').focus();bmX.set("+v+")" : "") + ";return false\">"+lc+"</a></div>" + chtml;
				
			}			

			if (bmX.param(v,"_to")) {
				html += '<div class="cont" style="display:'+dsp+'"><span style="position:absolute">&nbsp;SMS</span><textarea id="bmXdetails_'+v+'" name="message" class="input" style="width:'+(rW+rP)+'px;padding:2px 2px 2px 0" tabindex="'+ti+'3" /></textarea></div>';
			}					
			
			html += '<select class="input" id="bmXtype_'+v+'" name="method" style="'+s2+"\" onblur=\"this.style.display='none';bmX.set("+v+')" onchange="bmX.typeUpdate(this,'+v+');"><option value="SMS">SMS</option><option value="Email">Email</option></select>';
											
			/*html += chtml;*/
							
			html += '<div id="bmXlc_'+v+'" style="display:'+(g.p==1?'':'none')+';margin:6px 0 0 0;padding:0"><p>The recipient of this SMS may incur charges depending on their wireless carrier.</p><p>Supported carriers: AllTel, Cellular One, Nextel, AT&amp;T, Verizon, T-Mobile, Sprint, Boost, US Cellular, Virgin Wireless</p><input type="checkbox" id="bmXtcb_'+v+'" style="margin:0 2px 0 0" /> I agree to these terms and conditions</div><div style="padding:4px 0;display:none" id="bmXt_'+v+'"><p>Terms and Conditions</p><p>The recipient of this message may incur charges depending on their wireless carrier and phone plan. <a class="bmXa" href="'+bmXserver+'/about/america.php" target="_new">Visit site for more.</a></p></div><div id="bmXtc_'+v+'" style="display:none;padding:3px 0">Please agree to the terms and conditions before continuing</div>';
			
			if (!bmX.data[v].charged) {						
				html += '<div id="bmXlnc_'+v+'" style="display:'+(g.p!=1?'':'none')+';margin:10px 0 4px 0;padding:0;clear:both">' + bmX.data[v].beambox_tagline + "</div>";					
			}						

			html += '</div><div id="bmXbot_'+v+"\" style=\"margin:0;padding:6px 0 1px 0\"><a style=\"margin-top:-2px;\" class=\"bmXa\" href=\"#\" onclick=\"return bmX.info("+v+",'info')\"><img id=\"bmXlogo_"+v+'" src="'+ic+'" style="margin-top:2px;border:0;display:inline" /></a><span style="position:absolute;right:5px"><a href="#" class="bmXa" id="bmXclnk_'+v+'" style="padding:0 5px;text-decoration:none" onclick="bmX.hide('+v+');return false" tabindex="'+ti+'4">CLOSE</a><a id="bmXsc_'+v+'" href="#send" class="bmXa" style="margin:0 0 0 5px;padding:0 5px;text-decoration:none" onclick="return bmX.send('+v+')" tabindex="'+ti+'3">SEND</a></span></div>';
						
			if (bmX.data[v].charged) {
				html += '<div id="bmXlnc_'+v+'" style="margin:6px 0 2px 0;padding:0;clear:both;font-size:10px">This SMS costs '+bmX.data[v].beam_cost+" " + bmX.data[v].beam_currency + " and will be billed to your account. <a class=\"bmXa\" onclick=\"return bmX.info("+v+",'pin',this)\" href=\"#\">Get a BeamMe.Info PIN.</a></div>";
			}
			
			html += "</form>";

			/* set beambox content */		
			bmX.id("_" + v).innerHTML = html;			
						
			bmX.getCSS(v);						
			i.onclick = new Function("bmX.open("+v+",this);");
		}
		return true;
	},
	
	/*
	Make sure numbers or letters are passed only
	*/
	validKey: function(e,i)
	{
		var k = (e.keyCode) ? e.keyCode : (e.which) ? e.which : e.charCode, t = (e.target) ? e.target : (e.srcElement) ? e.srcElement : false;
		if (k == 13) {
			bmX.send(i);
			return false;
		}
		else if (String(k).match(/^(8|9|16|17|16|91|36|37|39|40|46|116)$/)) {			
			return true;
		}
		if (t) {
			if (t.id.match(/sender/)) {
				if (t.value != bmX.msg) {
					var a = (t.value.match(/[a-z]/i));
					t.maxLength = a ? 11 : 15;
				}
				/*bmX.id("sendcountryloc_" + t.id.replace(/[^0-9]/g, "")).style.display = (a) ? "none" : "";*/
			}
			if ((k >= 48 && k <= 57) || (k >= 96 && k <= 105) || ((! t.id.match(/mobile/) || (e.ctrlKey || e.metaKey)) && (k >= 65 && k <= 90))) {				
				return true;
			}
			return false;		
		}
	},
	
	getCSS: function(v)
	{
		var st = function(m) { return bmX.style(v,m); };
		
		var mycss = [
			"#bmX_"+v+"{border:1px solid "+st("border") + ";background:"+st('bg')+";color:"+st("text")+";}",
			"#bmX_"+v+" a{color:"+st("link")+";}",
			"#bmX_"+v+" a.bmXaOn{color:"+st("link_over")+"}",
			"#bmX_"+v+" p{color:"+st("text")+"}",
			"#bmX_"+v+" .input {margin:0;color:"+st("field_text")+";background:"+st("field_bg")+";font:normal 13px arial;z-index:1003;border:1px solid "+st("field_border")+";outline:none;left:37px}",
			"#bmX_"+v+" div.cont .input {border:0;position:relative}",
			"#bmX_"+v+" div.cont{background:"+st("field_border") + ";position:relative;height:auto;margin-bottom:3px;padding:" + ((bmX.ie) ? 0 : 1) + "px}",
			"#bmX_"+v+" div.cont span {font:bold 11px arial;color:#fff;top:4px}",
			"#bmXclnk_"+v+".bmXa {color:"+st("close_text")+";border:1px solid "+st("close_border")+";background:"+st("close_bg")+"}",
			"#bmXclnk_"+v+".bmXa:hover {color:"+st("close_text_over")+";background:"+st("close_bg_over")+"}",
			"#bmXsc_"+v+".bmXa {color:"+st("send_text")+";border:1px solid "+st("send_border")+";background:"+st("send_bg")+"}",
			"#bmXsc_"+v+".bmXa:hover {color:"+st("send_text_over")+";background:"+st("send_bg_over")+"}",
			"#bmXtc_"+v+" {color:"+st("warning_text")+"}",
			"#bmX_"+v+"	div.lenMsg{margin:0;color:"+st("link")+"}"			
		];
		
		bmX.css(mycss.join(" "), "css_" + v);
	},
	
	lookup: function(i)
	{
		var m = bmX.id("mobile_"+i).value;
		if (m.length > 8 && m != bmX.msg) {
			var f = bmX.id("f_"+i);
			f.target = "bmXiframe";
			if (typeof(f.origAction)=='undefined') {
				f.origAction = f.action;
			}	
			bmX.stateMsg(i, 'One moment while we check your PIN...');	
			f.action = f.origAction.replace(/sendbeam\.php/, "validateMobile.php") + "&rand=" + Math.round(1000*Math.random());
			f.submit();
			bmX.waitForStateChange(i);
			f.action = f.origAction;
		}
	},
		
	waitForStateChange: function(i)
	{
		/*document.getElementById("historyLength").innerHTML = "History Length: " + history.length;*/
		clearTimeout(bmX.stateTimer);
		var x = /*bmX.id("iframe").contentWindow.*/location.hash;
		var m = x.match(/beam:(.*)/);
		if (m) {
			var d = bmX.hLen - history.length;
			/* ignore first run in IE - make sure history never advances from the base URL */
			if ((! bmX.ie || d) && d) {
				history.go(d);
			}
			/* reset hash for browser url display purpose */
			/*document.*/location.hash = (bmX.hash.length) ? bmX.hash : "#";		
			var dp = m[1].indexOf(":");
			var dp2 = m[1].indexOf(":", dp+1); 
			if (dp2 == -1) dp2 = m[1].length;
			bmX.stateChange(i, m[1].substring(0, dp), m[1].substring(dp + 1, dp2), m[1].substring(dp2 + 1));
		}
		else {
			bmX.stateTimer = setTimeout("bmX.waitForStateChange("+i+")", 25);
		}
	},
	
	stateChange: function(i, method, result, details)
	{
		document.getElementById("debug").innerHTML = method + ":" + result + " - " + details + "<br />" + document.getElementById("debug").innerHTML;
		switch (method) {

			/* handle user paid beam requests */
			case "validate" :
					
				switch (result) {						
					
					case "reg_req" :
						bmX.stateMsg(i,"Number not found. <a class=\"bmXa\" href=\"#\">Register</a> once to use beams");
					break;	
					
					case "valid" :
						bmX.stateMsg(i,"<span style=\"float:left;padding-top:3px\">Number found please enter your PIN</span><br style=\"clear:both\" />");
						bmX.id("f_"+i).pin.focus();
					break;		
					
					case "fail" :
						bmX.stateMsg(i,"Your PIN was not accepted, please <a href=\"#\" onclick=\"bmX.stateChange("+i+",'validate','valid');return false\">try again</a> or get your PIN sent to your phone");
					break;					
					
					case "ok" :
						bmX.stateMsg(i,"");
						bmX.id("token_"+i).value = details;
						if (bmX.requestID != -1) {
							bmX.send(bmX.requestID);
						}
					break;	
				}			
				
			break;			
		}			
	},
	
	stateMsg: function(i, m)
	{
		var q = bmX.id("smsg_" + i);
		if (! q) {
			q = bmX.create("div");
			q.id = "bmXsmsg_" + i;
			q.style.padding = "6px 0 0 0";
			var h = bmX.id("bot_"+i);
			h.parentNode.insertBefore(q, h);
		}
		q.innerHTML = m;
		q.style.display = (m.length) ? "block" : "none";
	},
	
	/*
	Country dropdown has changed - show special cases
	hide select
	*/
	locUpdate: function(obj,i)
	{
		var loc = obj.value, t = obj.id.replace(/^bmX([a-z]+)_([0-9]+)$/, "$1");
		var q = bmXcntry[loc], 
		z = bmX.id("lc_"+i), 
		y = bmX.id("lnc_"+i);
		bmX.id(t+"loc_"+i).innerHTML = loc + "+" + q.p;
		bmX.id('t_'+i).style.display = bmX.id('tc_'+i).style.display = 'none';
		if (t == "country") {
			if (q.p == 1) {
				z.style.display = "";
				y.style.display = "none";
			}
			else {
				z.style.display = "none";
				y.style.display = "";
			}
			
			if (bmX.infoLast.length) {
				bmX.info(i,bmX.infoLast);
			}
			bmX.loc = obj.value;
		}
		else {
			bmX.locSend = obj.value;
		}		
		obj.style.display = 'none';
		bmX.set(i);		
	},
	
	/*
	Country dropdown has changed - show special cases
	hide select
	*/
	typeUpdate: function(obj,i)
	{
		var pm = bmX.method;
		bmX.method = obj.value;
		bmX.id("tlb_"+i).innerHTML = bmX.method;
		
		var m = bmX.id("mobile_"+i);
		var dt = bmX.id("lnc_"+i);
		var u = (!m.value.length || m.value == bmX.msg);
		switch (bmX.method) {
			
			case "Email" : 
				m.style.paddingLeft = "44px";
				m.style.width = (! bmX.data[i].charged) ? "80%" : "56%";
				bmX.id("loc_"+i).style.visibility = "hidden";
				bmX.msg = " enter your email";
			break;
			
			case "SMS" :
				m.style.paddingLeft = "99px";
				m.style.width = (! bmX.data[i].charged) ? "57%" : "33%";
				bmX.id("loc_"+i).style.visibility = "visible";
				bmX.msg = " enter your mobile";
			break;
			
		}
		if (u) m.value = bmX.msg;
		var p2 = (pm == "SMS") ? "number" : "email";
		var p3 = (pm != "SMS") ? "number" : "email";
		dt.innerHTML = dt.innerHTML.replace(pm, bmX.method).replace(p2, p3);
		
		if (bmX.infoLast.length) {
			bmX.info(i,bmX.infoLast);
		}
		
		obj.style.display = "none";				
		bmX.open(i);
	},
	
	/*
	Add styles by string
	*/
	css: function(css, i)
	{
		var p = bmX.id("css_" + i);
		if (p) {
			bmX.remove(p);
		}
		
		var ss = bmX.tag("HEAD")[0].appendChild(bmX.create("style"));
		ss.type = "text/css";
		ss.id = "bmXcss_" + i;
		if (ss.styleSheet) {
			ss.styleSheet.cssText = css;
		}
		else {
			ss.appendChild(document.createTextNode(css));
		}
	},
	
	/*
	Replace JS variables found within beamcode
	*/
	replaceVars: function(i)
	{
		var tag = ["js"];
		for (var q = 0; q < tag.length; q ++) {
			eval("var re = /<"+tag[q]+">(.+)<\\/"+tag[q]+">/igm;");
			var m = re.exec(i);
			while (m) {
				eval("var x = " + m[1] + ";");
				if (x) {
					i = i.replace(m[0], x);
				}	
				m = re.exec(i);			
			}
		}	
		return i;
	},
	
	/*
	Create hidden input field
	*/
	hidden: function(n, i, v) 
	{
		if (! v) v = "";
		v = v.replace(/\"/g, "&quot;");
		var inp = "<input " + (n.length ? "name=\"" + n + "\"" : "") + " type=\"hidden\" " + (i.length?"id=\"bmX" + i + "\"":"") + " value=\""+v+"\" />";
		return inp;
	},
	
	/*
	Create link
	*/
	link: function(v,i,t)
	{
		var x = bmX.dataParam(v, "box_link_" + i);
		if (!x || x == "yes") {
			return "<a class=\"bmXa\" style=\"padding-right:10px\" href=\"#\" onclick=\"return bmX.info("+v+",'" + i + "',this)\">" + t + "</a>";
		}
		return "";
	},
		
	/*
	Open the beambox
	*/
	open:function(i)
	{	
		if (bmX.id("country_"+i)) {
			bmX.locUpdate(bmX.id("country_"+i),i);
			var x = bmX.id("_" + i), 
			d = bmX.data[i], 
			v = bmX.id('tcb_' + i), 
			j = bmX.id('ml_' + i), 
			m = bmX.id("mobile_" + i);
			x.style.visibility = "hidden";
			bmX.id('C_' + i).style.display = "block";
			bmX.id("sc_"+i).style.display = "inline";
			if(v && bmX.termsChecked) {
				v.checked = true;
			}		
			/*bmX.set(i);*/
			if(bmX.mobile != null) {			
				if(m.value == bmX.msg) {
					m.value = bmX.mobile;
				}
			}
			bmX.hideX(i);
							
			var msg = bmX.param(i,"_text"), ml = msg.length + (msg.replace(/[^\r\n]/g, '').replace(/\r\n/g, ".").length);		
			if (ml > bmXlength[d.length - 1]) {
				bmX.info(i,"message");
				var lmsg = (d.demo==1) ? "Free Beams are limited to 160 chars" : "Beams from this account have been set to a limit of " + bmXlength[d.length - 1] + " chars";
				j.style.display = 'block';
				j.className = "lenMsg";
				j.innerHTML = lmsg;
			}
			bmX.sendStat(i, d.uid, "click");
			bmX.set(i);		
			/*var mW = (d.charged) ? 125 : 200;
			if (m.offsetWidth < mW) {			
				if (bmX.saf) {
					m.style.marginLeft = "59px";
				}
				else {
					m.style.width = (d.charged) ? "116px" : "100%";
				}
			}*/
			x.style.visibility = "visible";
			m.focus();
			m.select();
			/*		
			var str = i + "<br>";
			for (var prop in d) {
				str += (prop + " = " + eval("d." + prop) + "<br>");
			}
			document.getElementById("debug").innerHTML = str;
			*/
		}
	},
	
	/*
	Send tags on click etc
	*/
	sendStat: function(id, i, x)
	{		
		var t = bmX.paramsReq(id, 1);
		x=(x==null)?"view":"click";
		var u = bmXserver+"/beam-save-stat/?" + t + "&uid=" + i + "&id=" + id + "&pi=" + bmX.time + "&type=" + x + "&adsup="+bmX.data[id].ad;
		bmX.cmd(u);
	},
	
	/*
	Add script to head
	*/
	cmd: function(src)
	{
		var s=bmX.create("SCRIPT");
		s.type="text/javascript";
		s.src=src+((src.search(/\?/)==-1) ? "?" : "&") + "rand=" + Math.round(1000*Math.random())/* + "&origin=" + encodeURIComponent(document.location.href)*/;
		bmX.tag("HEAD")[0].appendChild(s);
		/*
		s.onload = function() { this.parentNode.removeChild(this); };
		s.onreadystatechange = function() { if (this.readyState == 'complete') { this.parentNode.removeChild(this); } };
		*/
		return s;
	},
	
	/*
	Set position of beambox
	*/
	set: function(c)
	{
		var obj = bmX.id("i_" + c), 
		x = bmX.id("_" + c), 
		i = bmX.id("logo_" + c),
		oL = 2,
		oT = 2;
		if (i) {
			i.style.position="relative";
			oL = i.offsetLeft;
			oT = i.offsetTop;
		}
		x.style.left=(bmX.pos(obj,"Left")-oL + bmX._db.offsetLeft + 1) + "px";
		x.style.display="block";
		var t=(bmX.pos(obj,"Top")-oT + bmX._db.offsetTop + 3);		
		if(t<0) t=0;
		x.style.top=t + "px";	
		if (typeof(bmXonOpen) == "function") {
			bmXonOpen(c);
		}
	},
	
	info: function(i,type,o)
	{
		bmX.infoLast = type;
		var k = bmX.tag("A",bmX.id("f_" + i).firstChild);
		for (var q = 0; q < k.length; q ++) {
			k[q].className = (k[q] == o) ? "bmXa bmXaOn" : "bmXa";
		}	
		var msg="";
		var jx = (bmX.method == "SMS") ? "mobile number" : "email address";
		var d=bmX.id("ml_" + i);
		d.className="info";
		var d3=bmX.data[i];		
		d.style.display="block";
		bmX.termsVis = (type == "help");
		switch (type) {
			case "error" :				
				d.className = "sendMsg";
				d.innerHTML = d3.errorMessage;
				/* reset log ID to force new entry */
				d3.logID = '';
				bmX.requestID = -1;
			break;
			case "no advertiser" : 
			case "sending" :
			case "send" :
				switch (type) {
					case "send"	: /*bmX.id("sc_"+i).style.display='none'; msg = (bmX.data[i].ad==1) ? "Locating sponsor" : "Sending"; break;*/
					case "sending" : bmX.id("sc_"+i).style.display='none'; msg = "Sending"; break;
					case "no advertiser" : bmX.id("sc_"+i).style.display='inline'; msg = "Sorry we are unable to send a "+bmX.method+" to this location at this time"; bmX.requestID = -1; break;
				}
				d.className = "sendMsg";
				/*
				d.innerHTML = "<br /><span style=\"background:url("+bmXserver+"/images/indicator.gif) no-repeat 0 50%;padding:10px 0 10px 20px\">" + msg + "<span id=\"bmXind_"+i+"\"></span></span><br />&nbsp;";
				*/
				d.innerHTML = msg + "<span id=\"bmXind_"+i+"\"></span>";
				if (type != "no advertiser") {
					bmX.indicate(i);				
				}
				else {
					clearTimeout(bmX.indTimeout);
					var to = setTimeout('bmX.hide(' + i + ')', bmX.wait);
					if (type == "no advertiser") {
						bmX.data[i].sendTimer = to;
					}
				}
			break;
			case "sent" :
				d.className = "sendMsg";
				d.innerHTML = "Sent. Your "+bmX.method+" will arrive shortly.";
				/* reset log ID to force new entry */
				d3.logID = '';
				bmX.requestID = -1;
			break;
			case "pin" :
				d.innerHTML="<p><span style=\"color:"+bmX.style(i,"link")+"\">Get a BeamMe.Info PIN number</span><br />This is a user paid Beam. To get the info SMS your preferred 4 digit PIN to 568574854. You will get a reply with your registration details and will be able to request user paid Beams. <a href=\"#\" class=\"bmXa\">Terms & Conditions</a></p>";
			break;
			case "help":
				var lnk = (bmXcntry[bmX.loc].p != 1) ? "<a class=\"bmXa\" href=\""+bmXserver+"/support\">"+bmXserver+"/support</a>" : "<a class=\"bmXa\" href=\""+bmXserver+"/about/america.php\">"+bmXserver+"/about/america.php</a>";
				switch (bmX.method) {
					case "SMS" : 
						d.innerHTML = "<p>Enter your local mobile number, click the send button and your Beam will be sent shortly. </p><p>Please ensure the correct country code for your phone is displaying on the left of the box. If incorrect, please click on the code and select your correct country.</p>Please also allow time for our global carriers to deliver your message. If you have tried without success, visit BeamMe support at " + lnk + "</p>";
					break;
					case "Email" :
						d.innerHTML = "<p>Enter your email address, click the send button and your Beam will be sent shortly. </p><p>If you fail to receive your email please check your spam filters and your junk folder to ensure the email wasn't captured there.</p>";
					break;
				}
				
				
			break;
			case "privacy":
				var s = bmXprivacyStatement;
				if (d3.ad != 0) {
					s += "<p>You will also be sent a 130 character "+bmX.method+" advert following the information you have requested.</p><p>Each advertising message sent from BeamMe.Info enables the service to be free to the end user. <!-- AD: " + d3.ad + " --></p>";
				}
				d.innerHTML=s;
			break;
			case "info":
				d.innerHTML="<p>Add this service to your website in minutes. For more information visit <a class=\"bmXa\" href=\"#\" onclick=\"window.open('"+bmXserver+"');return false\">"+bmXserver + "</p>";
			break;
			default: 
				if (bmX.param(i, "_to")) {
					d.innerHTML="<p><span style=\"display:inline;width:auto;color:"+bmX.style(i,"link")+"\">You define the message sent, please enter your query into the SMS box below.</span></p>";					
				}
				else {
					var xs=bmX.param(i,"_text");
					msg=(xs)?xs:(d3.beam_text) ? d3.beam_text : "no message defined.";
					msg = msg.substring(0, eval("bmXlength["+(d3.length-1)+"]"));
					if (d3.ad && d3.ad != 0 && d3.adText) {
						msg += "\n\n<div style=\"border:1px solid #dedede;padding:3px;\"><strong>ADVERTISEMENT</strong><br />" + d3.adText + "</div>";
					}
					d.innerHTML="<p><span style=\"display:inline;width:auto;color:"+bmX.style(i,"link")+"\">The following will be sent via "+bmX.method+"</span><br />" + msg.replace(/\\r\\n|\\n|\r\n|\n/g, "<br />").replace(/<br ?\/?>$/i, "") + "</p>";
				}
		}
		bmX.set(i);
		return false;
	},
	
	indicate: function(i)
	{
		clearTimeout(bmX.indTimeout);
		var x = bmX.id("ind_"+i);
		if (x) {
			var l = x.innerHTML.replace(/[^.]/g, "").length;
			l = (l == 3) ? 0 : l+1;
			for (var str = "", c = 0; c < 3; c ++) {
				str += (c < l) ? "." : "&nbsp;";				
			}
			x.innerHTML = str;
			bmX.indTimeout = setTimeout("bmX.indicate("+i+")",300);
		}
	},
	
	infoX: function(i)
	{
		try {bmX.id("t_" + i).style.display=bmX.id("ml_" + i).style.display="none";}catch(e){};
		bmX.infoLast = "";	
		bmX.set(i);
		return false;
	},
	
	style: function(i,n)
	{
		var s = bmX.priorityParam(i,"box_"+n);
		/*return (s && s.length) ? s.replace(/;(.*)$/g, "").replace(/^\s+|\s+$/g, "") : eval("bmX.defaults."+n);*/
		return s.replace(/;(.*)$/g, "").replace(/^\s+|\s+$/g, "");
	},
	
	/**
	Get priority parameter
	v - index of beambox
	t - type of parameter
	d - direction
	*/
	priorityParam: function(v, t, d)
	{
		return (!d || d == "param") ? eval("bmX.param("+v+", '"+t+"') || bmX.dataParam("+v+",'"+t+"');") : eval("bmX.dataParam("+v+",'"+t+"') || bmX.param("+v+", '"+t+"');");
	},
	
	dataParam: function(i, type)
	{
		return eval("bmX.data["+i+"].beam" + type + " || false");		
	},
	
	param: function(i,type)
	{
		var p = bmX.readParam(bmX.data[i].rawData, type);
		if (type == "_text" && ! p.length) {
			p = "no message defined";
		}		
		return (p) ? p.replace(/,?\*?$/, "").replace(/\s*$/, "") : p;
	},
	
	/*
	Read parameter from innerHTML
	*/
	readParam: function(s, p)
	{		
		var f={};
		s=s.split(/\\r\\n|\\n|\r\n|\n/g);		
		
		/*alert(s + "\n" + "^\\s*beam(box|ad)?_([^:]+):(.*)");*/
		
		var reg=new RegExp("^\\s*beam(box|ad)?(_[^ :]+) ?:(.*)", "i");	
		for (var e=0, l = s.length;e<l;e++) {
			var m=s[e].match(reg);
			if(m) {
				var t = (typeof(m[1]) != "undefined") ? m[1] + m[2] : m[2], val=bmX.trim(String(t).toLowerCase());
				if (val != p) {
					continue;
				}
			}
			if (typeof(val) != "undefined") {
				eval("if(typeof(f." + val + ")=='undefined') { f." + val + "=[];}");
				var j = (m?m[3]:s[e]).replace(/'/g, "\\'");
				eval("f." + val + ".push('" + j + "')");				
			}
		}
		return eval("(f." + p + ")?f." + p + ".join('\\n').replace(/\\r\\n|\\n$/,''):false;");
	},
	
	/*
	required get parameters for successful request
	*/
	paramsReq: function(i,u)
	{
		var url = (typeof(u) != "undefined"), 
		rd = (url) ? [] : "", 
		d = bmX.data[i], 
		/*supply = ((url) ? '_from|_tags|_banner|ad_category|ad_placement' : '_text|_from|_banner|_tags|ad_category|ad_placement').split("|");*/
		supply = 'ad_placement|_banner'.split('|');
		for (var w = 0, l = supply.length; w < l; w ++) {
			var k = supply[w], v = bmX.param(i, k);
			if (v) {
				if (url) {
					rd.push("beam" + k + "=" + encodeURIComponent(v));
				}
				else {
					rd += "beam" + k + ":" + v + "\n";
				}
			}
		}		
		return (url) ? rd.join("&") : rd;
	},
	
	send: function(i,s)
	{
		var tm=bmX.id("tc_" + i), 
		dx = bmX.data[i];
		if(bmXcntry[bmX.loc].p==1&&!bmX.id("tcb_" + i).checked) {
			tm.style.display='';
			bmX.set(i);
			return false;
		}
		tm.style.display='none';
		
		/* charged beam but no token is available - reject */
		if (dx.charged && bmX.id("token_"+i).value.length < 32) {
			bmX.requestID = i;
			var pl = bmX.id("f_"+i).pin.value.length;
			if (pl < 4) {
				bmX.info(i,"pin");
			}
			else if (pl == 4) {
				bmX.lookup(i);
				return false;
			}
			bmX.stateMsg(i, "Please enter your pin to continue");
			return false;
		}		
		bmX.set(i);
		bmX.termsChecked=true;
		/* check sender if incoming message */
		var m = (bmX.param(i,"_to")) ? bmX.id("sender_" + i) : bmX.id("mobile_" + i),
		xw = (bmX.method == "SMS") ? "mobile number" : "email address", 
		xw2 = (bmX.method == "SMS") ? ", no spaces" : "";
		
		/* show error if something is wrong */
		var c = 0;	
		switch (bmX.method) {
			case "SMS" : 
				c = (m.value.match(/\d{8,}/));
			break;
			case "Email" :
				c = (m.value.match(/.+@[a-z0-9-]{2,}\.[a-z]{2,4}/));
			break;
		}
		
		// dont proceed if no message defined
		if (bmX.param(i,"_to") && ! bmX.id("details_" + i).value.length) {
			alert("Please enter a message to send");
			return false;
		}
			
		if (m.value != bmX.msg && c) {
					
			bmX.id("C_"+i).style.display = "none";
			bmX.info(i,"send");
			
			/* Wait for log ID before proceeding so we dont get unmatched requests */
			if (! dx.charged && (! dx.logID || isNaN(dx.logID))) {
				dx.sendTimer = setTimeout("bmX.send(" + i + "," + s + ")", 250);			
			}
			else {
				/* Clear send timer */
				/*if (dx.sendTimer) {*/
					clearTimeout(dx.sendTimer);
				/*}*/
				with (bmX) {
					mobile=m.value;
					/*
					hide(i);
					status(i,1);
					*/
					id("C_"+i).style.display = "none";
					info(i,"send");					
					/* sendGo(i);		 */
				}
				
				/* send only beam parameters back */								
				var url = bmX.action + "?uid=" + dx.uid + "&details=" + encodeURIComponent(bmX.paramsReq(i)) + "&id=" + i + "&lid=" + dx.logID;
				bmX.cmd(url);
			}
		}
		else{
			var uj = (bmX.param(i,"_to")) ? "from" : "to";
			alert("Please provide a valid "+xw+" to send " + uj + xw2);
		}
		return false;
	},
	
	sendGo: function(i, s)
	{
		var f=bmX.id("f_" + i);
		f.mid.value = s;
		if (typeof(f.origAction)!="undefined") {
			f.action = f.origAction;
		}
		if (!bmX.param(i,"_to")) {
			f.caller_id.value = bmX.param(i,"_from");
			f.message.value = bmX.param(i,"_text");		
		}	
		else {
			f.caller_id.value = "SET:" + bmX.id("sender_"+i).value;
		}
		f.target = "bmXiframe";	
		f.submit();		
		if (bmXloopback) {
			setTimeout('bmX.cmd("' + bmX.action + '?mid=' + s + '&id=' + i + '")',500);	
		}
		else {
			bmX.ready(s, i);
		}		
	},
	
	ready: function(s, i)
	{
		var x = bmX.id("iframe");		
		if(bmX.saf && _wnu.match(/Version\/2/)) {
			setTimeout('bmX.cmd("' + bmX.action + '?mid=' + s + '&id=' + i + '")',1500);			
		}
		else{
			x.onload=function() { 
				bmX.cmd(bmX.action + "?mid=" + s + "&id=" + i);				
				this.onload = null;
			};
			x.onreadystatechange=function() { 
				if(this.readyState=='complete') {
					bmX.cmd(bmX.action + "?mid=" + s + "&id=" + i);
				} 
			};
		}		
	},
	
	prev: function(x, tag)
	{
		do {
			if(x.tagName && x.tagName.toUpperCase() == tag) {
				return x;
			}
			x = x.previousSibling;
		} while(x);
		return false;
	},
	
	hide: function(i)
	{
		bmX.infoX(i);
		bmX.id("_" + i).style.display="none";
		var c = (bmX.id("advert_" + i));
		if (c) bmX.remove(c);
		if (typeof(bmX.data[i].sendTimer) != "undefined") {
			clearTimeout(bmX.data[i].sendTimer);
		}
	},
	
	hideX: function(i)
	{
		
		var ds=bmX.tag("div");
		for (var q=0; q <ds.length; q ++) {
			var m = ds[q].id.match(/^bmX_(.+)$/);
			if(m && m[1] != i) { 
				bmX.hide(m[1]);
			}
		}
	},
	
	pos: function(obj, type) 
	{
		if(type == "Left" && obj.pageX){
			return obj.pageX
		}
		else if(type == "Top" && obj.pageY){
			return obj.pageY
		}
		else{
			var e = 0;
			while(obj.offsetParent){
				eval("e += obj.offset" + type);
				obj = obj.offsetParent;
			}
		}		
		return e;
	},
	
	tag: function(e, o)
	{
		return (o || document).getElementsByTagName(e);		
	},
	
	id: function(id)
	{
		return document.getElementById("bmX"+id);
	},
	
	create: function(i)
	{
		return document.createElement(i);
	},
	
	remove: function(x)
	{
		x.parentNode.removeChild(x);
	},
	
	go: function()
	{
		if (bmX.loaded == 0) {
			bmX.loaded=1;
			for (var l = [], u = bmXserver+"/js/getbeam.php?version=2&uid=", s = bmX.tag("SPAN"), q = 0; q < s.length; q ++) {	
				if (s[q].title) {
					var m = s[q].title.match(/^beamBox:([0-9a-f]{32})$/i);
					if (m) {
						/* load beambox code on request rather than load */
						if (s[q].innerHTML.match(/beam_source\: ?local/)) {
							var id = bmX.count++;
							bmX.data[id] = {uid:m[1]};							
							bmX.apply(id, 1, 1);
						}
						else {
							if (l.length ? m[1].search(l.join("|")) == -1 : 1) {	
								bmX.cmd(u + m[1]);
							}				
							l.push(m[1]);
						}
					}
				}
			}
			if (l.length) {
				bmX.load(l.join("|"));
			}
		}
	},
	
	request: function(v)
	{		
		with(bmX) {
			if (! bmX.getData(data[v].uid)) {		
				set(v);
				indicate(v);
				setTimeout('bmX.cancel(' + v + ')', bmX.loadTimeout * 1000);
				cmd(bmXserver+"/js/getbeam.php?version=2&uid=" + data[v].uid);				
			}
			load(data[v].uid, v);
		}
	},
	
	fail: function(v, m)
	{
		with (bmX.id("_" + v)) {
			innerHTML = "<div style='padding:10px;text-align:center'>" + m + " <a href=\"#\" onclick=\"bmX.hide("+v+");return false\">Close</a></div>";
			bmX.set(v);
		}
	},
	
	cancel: function(v)
	{
		with(bmX) {
			if (! getData(data[v].uid)) {		
				clearTimeout(loadTimer);
				fail(v, "Sorry we could not connect to the SMS service.");
			}
		}
	},
	
	getData: function(i)
	{
		eval("var w = bmXData.x" + i + ";");
		return (typeof(w) != "undefined") ? w : false;		
	},
	
	load: function(u,pid)
	{			
		if (u.length) {							
			u = u.split('|');		
			if (u.length > 0) {
				var i = u[0];
				if (bmXData) {
					var w = bmX.getData(i);
					if (w) {		
						var id = (pid == null) ? bmX.count++ : pid, ok = 1;
						if (typeof(bmX.data[id]) == "undefined") {
							bmX.data[id] = {uid:i};		
						}
						for (var prop in w) {
							try {
								eval("bmX.data[id]." + prop + " = '" + w[prop].replace(/\'/g, "\\'") + "'");
							}
							catch (e) {	
								switch (prop) {
									case "beamsecurity" :
										//  needs to be 1 for fail
										if (w[prop]) {
											bmX.data[id].status = "incorrect domain"; ok = false; 										
										}
									break;
									default: alert("could not set property: " + prop);
								}
							};
						}					
						if (pid != null && ok) {
							bmX.template(pid);
							bmX.open(pid);
						}
						else {
							bmX.apply(id, 1);	
						}
						u.shift();
					}
				}
				
				bmX.loadTimer = setTimeout("bmX.load('"+u.join("|")+"', " + pid + ")", 50);
			}	
		}
		/*document.close();*/
	}
};

/*
Attach to load event
*/
if (typeof(bmXcallLoad) == "undefined") {
	if (window.addEventListener) {
		window.addEventListener('load', bmX.go, false); 
	} 
	else if (window.attachEvent) { 	
		window.attachEvent('onload', bmX.go, false);
	}	
}bmX.msg = "enter your mobile";bmX.msgSend = "name or mobile no.";bmX.msgSend2 = "enter your mobile";bmX.protocol = "https";