function disableEnterKey(e)
{
     var key;


     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox


     if(key == 13)  {
	  //alert("enter key " + key);
          return false;
     }
     else  {
	  //alert("other key " + key);
          return true;
     }

}

function checkCaseNo()
{
	var CaseNo1 = document.getElementById("crCaseNo1").value;
	var CaseNo2 = document.getElementById("crCaseNo2").value;
	var CaseNo3 = document.getElementById("crCaseNo3").value;
	
	if (CaseNo1 != "" && CaseNo2 != "" && CaseNo3 != "")
	{
		document.getElementById("crCourt").disabled = true;
		document.getElementById("crDate").disabled = true;
		document.getElementById("crCourt").className = "disabled";
		document.getElementById("crDate").className = "disabled";
		document.getElementById("crCourt").selectedIndex = 0;
		document.getElementById("crDate").value = "";
	}
	
	return true;
}

function validate_court(searchPageID)
{
	
	var CaseNo1 = document.getElementById("crCaseNo1").value;
	var CaseNo2 = document.getElementById("crCaseNo2").value;
	var CaseNo3 = document.getElementById("crCaseNo3").value;
	var CaseNo = CaseNo1 + "/" + CaseNo2 + "/" + CaseNo3;
	var Court = document.getElementById("crCourt")[document.getElementById("crCourt").selectedIndex].value;
	var Date = document.getElementById("crDate").value;
	
	window.location="default.aspx?page=" + searchPageID + "&case=" + CaseNo  + "&court=" + Court + "&courtDate=" + Date;
	
	return true;
}

function division_info(station_option)
{

	//var selStation = eval(station_option);
    var szWindow=new String()
    var szPage=new String()
    var iPos;
	
    szWindow = window.location + "";
    szPage = "default.aspx?page=" + station_option
    szPage = szPage.replace (/\s+/g, '');
    
    iPos = szWindow.indexOf('default.aspx')
	szWindow = szWindow.substring(0, iPos) + szPage;
    
    //alert(szWindow);
	window.location = szWindow;
	
    return false;

}


function validate_crime()
{
    var textbox1 = document.getElementById("txtRefNo1");
    var textbox2 = document.getElementById("txtRefNo2");
    var textbox3 = document.getElementById("txtRefNo3");
    var textbox4 = document.getElementById("txtRefNo4");
    var szRefNo = "";
    var szErrorMsg = "Please enter a valid Crime Reference Number."
    var iReqLen = 9;


    //var szWindow = window.location;
    var iEnd = 0;
    var szWindow=new String();
			


    //szWindow = window.location + "";
    szWindow="default.aspx?page=312"
    
    //iEnd = szWindow.search("&");
    //if (iEnd > 0) {
    //  szWindow = szWindow.substring(0,iEnd);
    //}
    szRefNo = textbox1.value + textbox2.value + textbox3.value + textbox4.value;

    
    if (szRefNo.length < 1) {
	  return false;
    }
    else if (szRefNo.length < iReqLen) {
	  alert(szErrorMsg);
	  return false;
	}
			
    //document.getElementById("lblRefNo").text = szErrorMsg;
    window.location=szWindow + "&tab=0&ref=" + szRefNo;
    //alert(szWindow + "&tab=0&ref=" + szRefNo);
    return false;

}

function validate_postcode()
{
  var oPostcode = document.getElementById('txtPostcode');
  var oCheckcode = document.getElementById('chkPostcode');
  //var szWindow = window.location;
  var iEnd = 0;
  var szWindow=new String()
  var szPcode=new String()
			
  szWindow = window.location + "";
  iEnd = szWindow.search("&postcode");

  if (iEnd > 0) {
    szWindow = szWindow.substring(0,iEnd);
  }
  
  pcode = oPostcode.value + "";
  if (pcode.length < 1) {
    return false
  }
  /*else if (pcode.length < 7) {
    alert ("Postcode is of incorrect length. Please include a space character when appropriate.");
    return false
  }*/
			
  if (pcode = check_postcode (oPostcode.value)) {
    // if substring == "page=0"
    
    //window.location=szWindow + "&postcode=" + oPostcode.value;
    
    
    /* 
	   dp data adjustment 
       remove spaces in postal codes of greater then eight characters
       to accommendate the dp data
    */
    if (pcode.length > 7) {
		pcode = removeSpaces(pcode);
	}
    document.getElementById('txtPostcode').value = pcode;
    
    window.location="default.aspx?page=314" + "&postcode=" + oPostcode.value;
    
    //document.getElementById('chkPostcode').checked = true;
    //document.getElementById('txtPostcode').value = check_postcode (oPostcode.value)
    //alert ("Postcode has a valid format");
  } 
  else {
    //document.getElementById('chkPostcode').checked = false;
    //window.location=szWindow;
    alert ("Postcode has invalid format");
  }

  return false;		

}


function check_postcode(toCheck) 
{
		
  // permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";  // character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";  // character 2
  var alpha3 = "[abcdefghjkstuw]";           // character 3
  var alpha4 = "[abehmnprvwxy]";             // character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";     // character 5
		  
		
  // array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();
		
  // expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
		  
  // expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
		
  // expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
		  
  // exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
		  
  // standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
		  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
		
  // load up the string to check
  var postCode = toCheck;
		
  // assume we're not going to find a valid postcode
  var valid = false;
		  
  // check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) 
    {
			
      // the post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
			  
      // copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
			  
      // if it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
			  
      // load new postcode back into the form element
      valid = true;
			  
      // remember that we have found that the code is valid and break from loop
      break;
    }
  }
		  
  // return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;

  //return false;
}


//String.prototype.strip = function( exp ){ return this.replace(exp?exp:/\s/g,""); };
function removeSpaces(string) 
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function strmin(exp){ return this.replace(exp?exp:/\s/g,""); };

function autotab(current,to)
{
    if (current.getAttribute && 
      current.value.length==current.getAttribute("maxlength")) {
        to.focus() 
    }
}

function MM_preloadImages() 
{

  if (document.images) {

    var imgFiles = MM_preloadImages.arguments;

    if (document.preloadArray==null) document.preloadArray = new Array();

    var i = document.preloadArray.length;

    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){

      preloadArray[i] = new Image;

      preloadArray[i++].src = imgFiles[j];

  } }

}

function ValidatePostcode(sender, args) {
    args.IsValid = (args.Value.match(/(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2})/i) != null);
    return args.IsValid;
}