
pics = new Array();
var objCount = 0;

if (typeof(browserOK) == "undefined") {
  browserOK = false;
}

function preload(name, first, second) {
  if (browserOK) {
    pics[objCount] = new Array(25);
    pics[objCount][0] = new Image();
    pics[objCount][0].src = first;
    pics[objCount][1] = new Image();
    pics[objCount][1].src = second;
    pics[objCount][2] = name;
    objCount++;
  }
}

function on(name){
  if (browserOK) {
     for (i = 0; i < objCount; i++) {
      if (document.images[pics[i][2]] != null)
        if (name != pics[i][2]) {
        } else {
           document.images[pics[i][2]].src = pics[i][1].src;
        }
    }
  }
}


function off(name)
{
  if (browserOK)
  {
    for (i = 0; i < objCount; i++)
    {
      if (document.images[pics[i][2]] != null)
      {
        if (name == pics[i][2])
        {
          document.images[pics[i][2]].src = pics[i][0].src;
        }
      }
    }
  }
}

preload("about_us","images/about_us.gif" , "images/about_us_r.gif");
preload("contact_us","images/contact_us.gif" , "images/contact_us_r.gif");
preload("bookmark","images/bookmark.gif" , "images/bookmark_r.gif");
preload("terms_conditions","images/terms_conditions.gif" , "images/terms_conditions_r.gif");
preload("copyright","images/copyright.gif" , "images/copyright_r.gif");
preload("feedback","images/feedback.gif" , "images/feedback_r.gif");
preload("email_friend","images/email_friend.gif" , "images/email_friend_r.gif");
preload("start_ukcorporator","images/start_ukcorporator.gif" , "images/start_ukcorporator_r.gif");
preload("faq","images/faq.gif" , "images/faq_r.gif");
preload("resource","images/resource.gif" , "images/resource_r.gif");
preload("view_summary","images/view_summary.gif" , "images/view_summary_r.gif");
preload("back","images/back.gif" , "images/back_r.gif");
preload("continue","images/continue.gif" , "images/continue_r.gif");
preload("go_search","images/go_search.gif" , "images/go_search_r.gif");

function BookMark()
{
  if (is_win)
  {
    if (is_ie4up) {
      window.external.addFavorite("http://www.ukcorporator.co.uk", "UKcorporator - UK Company Formations");
    }
    else if (is_safari) {
      alert('Please press the Apple key + D to add UKcorporator to your bookmarks.' );
    }
    else
    {
      if (is_nav4up) {
        alert('Please press Crtl + D to add UKcorporator to your bookmarks.');
      }
      else {
        alert('Please press Crtl + D to add UKcorporator to your bookmarks.' );
      }
    }
  } 
  else if( is_mac ) {
    alert('Please press the Apple key + D to add UKcorporator to your bookmarks.' );
  }
}

var width = screen.availWidth;
var height = screen.availHeight;

var popWindow = null;
var popWindow2 = null;


function closeGuidance() {
  if (popWindow != null) {
  	if (window.popWindow.closed==false) {
    		window.popWindow.close();
  	}
  }
  if (popWindow2 != null) {
  	if (window.popWindow2.closed==false) {
    		window.popWindow2.close();
  	}
  }
}

function closeGuidance2() {
  if (window.popWindow2) {
    window.popWindow2.close();
  }
}

function popUpAwards(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "popUpAwards", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  newWindow = window.open(url , "popUpAwards", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=560,height=300,screenx=100,screeny=120,top=120,left=100");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpTestimonials() {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "popUpTestimonials", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  //newWindow = window.open("testimonials.html" , "popUpTestimonials", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=560,height=300,screenx=100,screeny=120,top=120,left=100");
  newWindow = window.open("testimonials.php", "popUpTestimonials", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=560,height=300,screenx=100,screeny=120,top=120,left=100");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpPostcode() {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "popUpPostcode", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  newWindow = window.open("http://www.royalmail.com/portal/rm", "popUpPostcode", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=360,height=500,screenx=420,screeny=20,top=20,left=420");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpGuidance(url, $name) {
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    popWindow = window.open("", "popWindow", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    popWindow.close();
    while(! popWindow.closed) ;
  }
  // If we are already in a guidance item don't add /guidance/ to url
  var guidance_already = document.URL.search(/guidance\//);
  if( guidance_already == -1 ) url = "./guidance/"+ url;
  popWindow = window.open( url, "popWindow", "width=320,height=275,resizable=yes,scrollbars=yes,screenx=440,screeny=195,left=435,top=195");
  popWindow.focus()
}

function popUpGuidance2(url, $name) {
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    popWindow2 = window.open("", "popWindow2", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    popWindow2.close();
    while(! popWindow2.closed) ;
  }
  var guidance_already = document.URL.search(/guidance\//);
  if( guidance_already == -1 ) url = "./guidance/"+ url;
  popWindow2 = window.open( url, "popWindow2", "width=320,height=275,resizable=yes,scrollbars=yes,screenx=40,screeny=195,left=35,top=195");
  if (navigator.appName != "Microsoft Internet Explorer") {
    popWindow2.focus()
  }
}

function popUpGuidance3(url, $name) {
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    popWindow3 = window.open("", "popWindow3", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    popWindow3.close();
    while(! popWindow3.closed) ;
  }
  var guidance_already = document.URL.search(/guidance\//);
  if( guidance_already == -1 ) url = "./guidance/"+ url;
  popWindow3 = window.open( url, "popWindow3", "width=320,height=275,resizable=yes,scrollbars=yes,screenx=40,screeny=195,left=200,top=90");
  if (navigator.appName != "Microsoft Internet Explorer") {
    popWindow3.focus()
  }
}


function popUpNewGuidance(url, $name) {
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    popWindow = window.open("", "_blank", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
  }
  popWindow = window.open("/guidance/" + url, "_blank", "width=320,height=275,resizable=yes,scrollbars=yes,screenx=440,screeny=195,left=435,top=195");
  popWindow.focus()
}


function popUpExternalLeft(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "External", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  newWindow = window.open(url, "External", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=500,screenx=20,screeny=20,top=20,left=20");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpExternalRight(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "External", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  newWindow = window.open(url, "External", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=300,screenx=420,screeny=20,top=20,left=420");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpCompanyNameSearch(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "External", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  newWindow = window.open(url, "External", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=460,screenx=420,screeny=20,top=20,left=420");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpExternal(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "External", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300,top=100,left=100");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  popUpWidth = width - 420;
  newWindow = window.open(url, "External", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=" + popUpWidth  + ",height=500,screenx=420,screeny=20,top=20,left=100");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpNewExternal(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "_blank", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300,top=100,left=100");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  popUpWidth = width - 420;
  newWindow = window.open(url, "_blank", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=" + popUpWidth  + ",height=500,screenx=420,screeny=20,top=20,left=100");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpNewExternalLeft(url) {
  var newLeftWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newLeftWindow = window.open("", "LeftWindow", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300,top=0,left=10");
    newLeftWindow.close();
    while(! newLeftWindow.closed) ;
  }
  popUpWidth = width - 420;
  newLeftWindow = window.open(url, "LeftWindow", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=" + popUpWidth  + ",height=500,screenx=10,screeny=20,top=0,left=10");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newLeftWindow.focus()
  }
}

function popUpNewExternalRight(url) {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "_blank", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300,top=0,left=410");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  popUpWidth = width - 420;
  newWindow = window.open(url, "_blank", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=" + popUpWidth  + ",height=500,screenx=440,screeny=20,top=0,left=410");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUp48w() {
  if (window.window48w) {
    window.window48w.close();
  }
  var window48w = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    window48w = window.open("", "window48w", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=350");
    window48w.close();
    while(! window48w.closed) ;
  }
  window48w = window.open("48w.php", "window48w", "toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=350,screenx=0,screeny=0,top=0,left=0");
  if (navigator.appName != "Microsoft Internet Explorer") {
    window48w.focus()
  }
}

function popUp48x() {
  var newWindow = null;
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    newWindow = window.open("", "48x", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=300");
    newWindow.close();
    while(! newWindow.closed) ;
  }
  newWindow = window.open("48x.php", "48x", "toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=500,screenx=400,screeny=0,top=0,left=400");
  if (navigator.appName != "Microsoft Internet Explorer") {
    newWindow.focus()
  }
}

function popUpClean(url) {
  if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion > 2.0)) {
    popWindow = window.open("", "popWindow", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=560,height=350");
    popWindow.close();
    while(! popWindow.closed) ;
  }
  popWindow = window.open(url, "popWindow", "width=560,height=350,resizable=yes,scrollbars=yes,screenx=440,screeny=195,left=435,top=195");
  popWindow.focus()
}

//page_continue() - original function below
function page_continue() {
  var location = document.URL;
  //If we are on any of the following pages then we simply go history.back so that these pages are not part of a UKCorp trace
  //when a user presses the back button after inputting information
  if (location.lastIndexOf("faq.php") > 0 ||
   location.lastIndexOf("46a.php") > 0 ||
   location.lastIndexOf("help.php") > 0 ||
   location.lastIndexOf("resources.php") > 0 ||
   location.lastIndexOf("about_us.php") > 0 ||
   location.lastIndexOf("copyright.php") > 0 ||
   location.lastIndexOf("46b.php") > 0 ||
   location.lastIndexOf("links.php") > 0 ||
   location.lastIndexOf("feedback.php") > 0) {
	  //history.back();
	  // BW 14/11/03 - Added a check to see if the last page was a ukcorporator page
	  //		If not, redirect to home page on continue.
	  var search_result = document.referrer.search(/^http:\/\/[^\/]*ukcorporator/);
	  if ((search_result==-1) && (document.referrer!=""))
	  {
	  	window.location.replace('/home.php');
	  } else {
	    	history.go(-1);
	  }
  }
  else if (form_errors(document.page)) {
    document.page.submit();
  }
}
/*
function page_continue() {
  if (form_errors(document.page)) {
    document.page.submit();
  }
}
*/

function page_back()
{
    var search_result = document.referrer.search(/^http:\/\/[^\/]*ukcorporator/);
	var search_result_sandbox = document.referrer.search(/^http:\/\/.*~.*htdocs/);
	if (search_result==-1 && search_result_sandbox==-1)
	{
		window.location.replace('/home.php');
	} else {
		history.go(-1);
	}
}

function form_errors(form) {
  var successful = true;
  var elements = form.elements;

  for (var i = 0; successful && i < elements.length; i++) {
    if (elements[i].validate) {
      successful = elements[i].validate();
    }
  }
  return successful;
}

function company_search() {

  //var name = form.name.value;
  
  var url = "http://wck2.companieshouse.gov.uk/"
  
  // JC 20/10/2004 Old url  
  //var url = "http://ws1info.companieshouse.gov.uk/info/do_search.cgi?id=&cname=" +
  //name + "&cnumb=&table=1&x=39&y=15";
  
  // GW 19/11/2004
  // window.location = url;
  popUpCompanyNameSearch(url);

}


/*
String.prototype.trim = function() {

 // skip leading and trailing whitespace
 // and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}
*/
String.prototype.LTrim=new Function("return this.replace(/^\\s+/,'')") 
String.prototype.RTrim=new Function("return this.replace(/\\s+$/,'')") 
String.prototype.Trim= new Function("return this.replace(/^\\s+|\\s+$/g,'')")

// Handy functions - replace them //
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
  return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
  return this.replace(/\s+$/,"");
}
