function NumberValid(objName,inputMask,lowerrange,upperrange){
var checkOK = "0123456789-. ";
var checkStr 
var allValid = true;
var decPoints = 0;
var allNum = "";
var floatval
if(objName){
	checkStr= objName.value;
if(objName.value=="NaN"){objName.value="0"}

if(lowerrange==""){lowerrange=0}
if(upperrange==""){upperrange=999999}
if (inputMask == null){inputMask=99999999.99} // Set input mask high if not defined
for (i = 0;  i < checkStr.length;  i++){
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length){
		allValid = false;
		break;
	}
	if (ch == "."){
		allNum += ".";
		decPoints++;
	}else if (ch != ",")
		allNum += ch;
}
if (!allValid){
        objName.value="0"
	alert("Not a valid number.  Try again using only numeric characters.("+objName.name+")");
	return (false);
}

if (decPoints > 1){
        objName.value="0"
	alert("Not a valid number.  More than one decimal point.("+objName.name+")");
	return (false);
}

var chkVal = allNum;
var prsVal = parseFloat(allNum);
var requiredDecimals;
var currentDecimals;
var AddOnDecimals;

if (chkVal != "" && !(prsVal >= (inputMask*-1) && prsVal <= inputMask)){
	alert("Not a valid number.  Enter a number in the range -"+lowerrange+" upto "+upperrange+".");
	return (false);
}

for (i = 0;  i < inputMask.length;  i++){
	if (inputMask.substr(i,1)=="."){requiredDecimals = inputMask.length-(i+1)}
}
if (requiredDecimals == null){requiredDecimals="0"}

//######## round checkstr
checkStr = Math.round(checkStr*Math.pow(10,requiredDecimals))/Math.pow(10,requiredDecimals)+""

for (i = 0;  i < checkStr.length;  i++){
	if (checkStr.substr(i,1)=="."){currentDecimals = checkStr.length-(i+1)}
}
if (currentDecimals == null){currentDecimals="0"}

if (requiredDecimals>currentDecimals){	//we need to add on some zero's
	for (i = 0; i < requiredDecimals-currentDecimals; i++){
		if (AddOnDecimals==null){AddOnDecimals="0"}
		else{AddOnDecimals=AddOnDecimals+"0"}
	}
	if (currentDecimals==0){AddOnDecimals="."+AddOnDecimals}	//add on the decimal point if we don't have one already
	checkStr = checkStr+AddOnDecimals
}


floatval=parseFloat(checkStr)
if(floatval<lowerrange){
   alert("Error- Number should be between "+lowerrange+" and "+upperrange)
   return(false)

}
if(floatval>upperrange){

   alert("Error- Number should be between "+lowerrange+" and "+upperrange)
   return(false)

}

objName.value = checkStr

}
return (true);
}

function ajAddShortlist(lID,email)
{

var xmlHttp;

try
  {  // Firefox, Opera 8.0+, Safari  

    xmlHttp=new XMLHttpRequest();


    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }

    xmlHttp.open("GET","/adshort.php?lID="+lID+"&email="+email,true);
    xmlHttp.send(null);
  }
catch (e)
  {  // Internet Explorer  
    try
    {    
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }
    xmlHttp.open("GET","/adshort.php?lID="+lID+"&email="+email,true);
    xmlHttp.send(null);


    }
  catch (e)
    {    
      try
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }
    xmlHttp.open("GET","/adshort.php?lID="+lID+"&email="+email,true);
    xmlHttp.send(null);


      }

    catch (e)
      {      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
}

function ajRemoveShortlist(lID,email)
{

var xmlHttp;

try
  {  // Firefox, Opera 8.0+, Safari  

    xmlHttp=new XMLHttpRequest();


    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }

    xmlHttp.open("GET","/remshort.php?lID="+lID+"&email="+email,true);
    xmlHttp.send(null);
  }
catch (e)
  {  // Internet Explorer  
    try
    {    
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }
    xmlHttp.open("GET","/remshort.php?lID="+lID+"&email="+email,true);
    xmlHttp.send(null);


    }
  catch (e)
    {    
      try
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }
    xmlHttp.open("GET","/remshort.php?lID="+lID+"&email="+email,true);
    xmlHttp.send(null);


      }

    catch (e)
      {      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
}

function ajRemoveAllShortlist(email)
{


var xmlHttp;

try
  {  // Firefox, Opera 8.0+, Safari  

    xmlHttp=new XMLHttpRequest();


    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
      }

    }

    xmlHttp.open("GET","/remshort.php?lID=0&email="+email,true);
    xmlHttp.send(null);
  }
catch (e)
  {  // Internet Explorer  
    try
    {    
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }
    xmlHttp.open("GET","/remshort.php?lID=0&email="+email,true);
    xmlHttp.send(null);


    }
  catch (e)
    {    
      try
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
//## nothing for now
alert(xmlHttp.responseText)
      }

    }
    xmlHttp.open("GET","/remshort.php?lID=0&email="+email,true);
    xmlHttp.send(null);


      }

    catch (e)
      {      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
}


function ajPop(opt,cValue)
{

var xmlHttp;
cUrl="pop.php?opt="+escape(opt)+"&cvalue="+escape(cValue);

try
  {  // Firefox, Opera 8.0+, Safari  

    xmlHttp=new XMLHttpRequest();
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
        popfunc(opt,cValue,xmlHttp.responseText);
      }
    }
    xmlHttp.open("GET",cUrl,true);
    xmlHttp.send(null);
  }
catch (e)
  {  // Internet Explorer  
    try
    {    
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
        popfunc(opt,cValue,xmlHttp.responseText);
      }

    }
    xmlHttp.open("GET",cUrl,true);
    xmlHttp.send(null);
    }
  catch (e)
    {    
      try
      {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
  	 xmlHttp.onreadystatechange=function()
         {
           if(xmlHttp.readyState==4)
           {
        popfunc(opt,cValue,xmlHttp.responseText);
           }

         }
    xmlHttp.open("GET",cUrl,true);
         xmlHttp.send(null);
      }

    catch (e)
      {      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
}


function popfunc(opt,cValue,cText)
{
   switch(opt)
   {
      case "MAKE":

        o=document.forms[0].f_model
o.length=1;

        for(n=1;n<o.options.length;n++){
          o.options[n]=null;
        }
        for(n=1;n<o.options.length;n++){
          o.options[n]=null;
        }

if(cText==""){
}
else{
        aRet=cText.split("|");
        for(n=0;n<aRet.length;n++){
           if(aRet[n]!=""){
     	     var newOpt=new Option(aRet[n],aRet[n])
             document.forms[0].f_model.options[n+1]=newOpt;
           }

        }
}
        break;
   }

}

function check_reg_screen()
{
oform=document.forms[0];
lError=false;
if(oform.code.value==""){
   alert("Please enter security code");
   lError=true;

}

if(oform.f_username.value==""){
   alert("Please enter your name");
   lError=true;

}
//if(oform.f_address1.value==""){
//   alert("Please enter your address");
//   lError=true;
//}
if(oform.f_postcode.value==""){
   alert("Please enter your postcode");
   lError=true;
}
if(oform.f_email.value==""){
   alert("Please enter your email address");
   lError=true;
}
else {
  if(oform.f_email_conf.value==""){
     alert("Please confirm your email address");
     lError=true;
  }
else {
  if(oform.f_email_conf.value != oform.f_email.value){
     alert("Email addresses do not match");
     lError=true;
  }

}
return !lError


}




}

function swap_image_detail(image_name,replace_with){
if(document.images){
   oImage=eval("document.images['"+image_name+"']");
   if(oImage){
      oImage.src=replace_with.src;
   }
}

}

var active_element;
function initiateSelfClosing(){    
if (navigator.appName == "Microsoft Internet Explorer") {
        active_element = document.activeElement;
        document.onfocusout = closeWnd;
        bIsMSIE = true;
    }    
else { 
window.onblur = closeWnd; 
}
}
function closeWnd(){
       if (window.opener != null) {
        if (bIsMSIE && (active_element != document.activeElement)) {
            active_element = document.activeElement;
        }
        else {
            window.close();
        }    
}
}
