// JavaScript Document

var flagTimer = 3000;
setTimeout("flagChange();", flagTimer);

function flagChange() {
	if (document.getElementById("callusholder")) {
		if (document.getElementById("callusholder").innerHTML.indexOf('0844')>0) {
			document.getElementById("callusholder").innerHTML = '<img src="/webimages/flag-es.png" width="74" height="48" align="top" />Call us on +34 95252 7272';
			setTimeout("flagChange();", flagTimer);
			return;
		}
	}
	if (document.getElementById("callusholder")) {
		if (document.getElementById("callusholder").innerHTML.indexOf('+34')>0) {
			document.getElementById("callusholder").innerHTML='<img src="/webimages/flag-en.png" width="74" height="48" align="top" //>Call us on 0844 734 5300';
			setTimeout("flagChange();", flagTimer);
			return;
		}
	}
		
}

function get_register_now() {
	document.getElementById("register_panel").innerHTML='Just enter your E:Mail and click send&nbsp;<input name="reg_email" type="text" id="reg_email" maxlength="100" style="width:300px;" />';
	document.getElementById("register_button").innerHTML='<a class="button" href="Javascript:;" onFocus="if(this.blur)this.blur();" onclick="register_now();"><img src="/webimages/envelope.gif" width="14" height="9" border="0" />&nbsp;&nbsp;Send</a>';
}

function changepanel(panel, pname) {
	var url="/"+panel+".php";
	var mypostrequest=new ajaxRequest();
	var panel = encodeURIComponent(panel);
	var parameters="panel="+panel;
	if (typeof pname != 'undefined') {
		var pname = encodeURIComponent(pname);
		parameters+="&pname="+pname;
	}
	mypostrequest.onreadystatechange=function(){
	 if (mypostrequest.readyState==4){
		if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById("search_panel")) {
				document.getElementById("search_panel").innerHTML = mypostrequest.responseText;
			}
		}
		else{
		 alert("An error has occured trying to retrive the new panel")
				document.getElementById("search_panel").innerHTML = mypostrequest.responseText;
		}
	 }
	}
	mypostrequest.open("POST", url, true)
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	mypostrequest.send(parameters)
}


function navBarStatus(tabber) {
	clearNavStatus("navbar")
	document.getElementById(tabber).className="selected";
}

function clearNavStatus(div) {
	if(!div) {
		return;
	}
	div = typeof div === "string" ? document.getElementById(div) : div;
	var elms = div.getElementsByTagName("*");
	for(var i = 0, maxI = elms.length; i < maxI; ++i) {
		var elm = elms[i];
		if (elm.className=="selected") {
			elm.className = "";
		}
	}
}

function alltrim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

toCamelCase.exp = / ([a-z])/;
function toCamelCase(s) {
	s = ' '+s.toLowerCase();
	for(var exp = toCamelCase.exp; 
		exp.test(s); 
		s = s.replace(exp, ' '+RegExp.$1.toUpperCase()) );
	return alltrim(s);
//	return ltrim(s);
}

function isEmailValid(email) 
{ 
    return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w{2,}$/.test(email); 
} 

//aweber stuff
var formData = function() {
  var query_string = (location.search) ? ((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
  var query_string = query_string.replace(/\s/g, "_");
  var query_string = query_string.replace("%20", " ");
  var elements = [];
  if(query_string) {

     var pairs = query_string.split("&");
     for(i in pairs) {
        if (typeof pairs[i] == 'string') {
            var tmp = pairs[i].split("=");
            elements[unescape(tmp[0])] = unescape(tmp[1]);
        }
     }
  }

  return {
      display: function(key) {
          if(elements[key]) {
            document.write(elements[key]);
          } else {
            document.write("");
          }
      }  
  }

}();
//-----------=============-------------
//ajax request
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){ 
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest) 
  return new XMLHttpRequest()
 else
  return false
}

