// JavaScript Document
var vatRate=0.175;

function trim(str){var str = str.replace(/^\s\s*/,''),ws=/\s/,i=str.length;while(ws.test(str.charAt(--i)));return str.slice(0,i+1);}	
function isnull(str){if(trim(str)==null || trim(str)==""){return true;}else{return false;}}
function validEmail(str){apos=str.indexOf("@");dotpos=str.lastIndexOf(".");if (apos<1||dotpos-apos<2){return false;}else{return true;}} 	
function isNumeric(str){var sField=new String(trim(str));if(sField.length==0) { return false; }else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }for(var x=0; x < sField.length; x++) {if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }else { return false;}}return true;}
function isDate(dateStr){var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;var matchArray = dateStr.match(datePat); /*is the format ok?*/if (matchArray == null){alert("Please enter date as either dd/mm/yyyy or dd-mm-yyyy.");return false;}day = matchArray[1];month = matchArray[3];year = matchArray[5];if (month < 1 || month > 12){/*check month range*/alert("Month must be between 1 and 12.");return false;}if (day < 1 || day > 31){alert("Day must be between 1 and 31.");return false;}if ((month==4 || month==6 || month==9 || month==11) && day==31){alert("Month "+month+" doesn`t have 31 days!");return false;}if(month==2){/*check for february 29th*/var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));if (day > 29 || (day==29 && !isleap)){alert("February " + year + " doesn`t have " + day + " days!");return false;}}return true;}
function PageRating($val){$.post("/ajax/PageRating.asp",{"Rating":$val,"Page":document.location.href},function(xml){var $s=$(xml).find("status").text();var $d=$(xml).find("description").text();if ($s==0){$("#PageRating").slideUp("slow",function(){$("#PageRating").html("<p class=\"bold red\">"+$d+"</p>");$("#PageRating").slideDown("slow",function(){setTimeout(function(){$("#PageRating").slideUp("slow");},1000);});});}else{alert($d);}});}
function GetFileName(){var file_name=document.location.href;var end=(file_name.indexOf("?")==-1)?file_name.length:file_name.indexOf("?");return file_name.substring(file_name.lastIndexOf("/")+1, end);}

function parseProjectNo(str) {
	str=str.toUpperCase();
	str=str.replace(/ /g,".");
	str=str.replace(/[^a-zA-Z0-9|\s|-]/g,'.');
	return str;
	}

//JQuery Code
$(function() {
	$("body").append("<div id=\"ajax_loader\" class=\"ajax_hide\"><img src=\"/images/ajax_loading.gif\" style=\"padding-right:4px;\" />Processing...</div>");
	$("body").ajaxStart(function(){$("#ajax_loader").attr("class","ajax_show");});
	$("body").ajaxStop(function(){$("#ajax_loader").attr("class","ajax_hide");});
	$("body").ajaxError(function(e, request, settings){alert("Oops! An error has occurred.\nIf this problem persists, please contact BIRR Legal Services on 0845 026 2460.");});
	
	LoadPictureBox();

	$("#FormLoginBox").submit(function() {
		$.post("/forms/Login.asp",$("#FormLoginBox").serialize(),function(xml) {
			var s=$(xml).find("status").text();
			var d=$(xml).find("description").text();
			if (s==0) {
				var LoginURL=$("#LoginURL").attr("value");
				var CompanyPack=$("#LoginCompanyPack").attr("value");
				if (LoginURL!=null && LoginURL!="") {
					var url=LoginURL;
					if (CompanyPack!="" && CompanyPack!=null) {
						url+="?pack="+escape(CompanyPack);
						}
					window.location=url;
					}
				else {
					window.location="/default.asp";
					}
				}
			else {
				alert(d);
				}
			});
		return false;
		});
   });

function ShowHide(id){$("#"+id).toggle("slow");}
function GetOutputValues(xml){var x=new Array($(xml).find("status").text(),$(xml).find("description").text());return x;}
function showDialog(str,title){$("#dialog").html(str);$("#dialog").dialog("option","title",title);$("#dialog").dialog("open");}
function StartPictureBoxFade(){var Next;var Active=$("#picture_box a.active");if (Active.length==0) {Active=$("#picture_box a:last");}if (Active.next().length==0) {Next=$("#picture_box a:first");}else {Next=Active.next();}Active.addClass("last-active");Next.css({opacity: 0.0});Next.addClass("active");Next.animate({opacity:1.0},500,function() {Active.removeClass("active last-active");});}
	
function LoadPictureBox() {
	var arr=new Array();
	arr[0]="<a href=\"http://www.birr.co.uk/company-formations.asp\"><img src=\"http://www.birr.co.uk/images/banners/banner0.jpg\" /></a>";
	arr[1]="<a href=\"http://www.birr.co.uk/registered-office.asp\"><img src=\"http://www.birr.co.uk/images/banners/banner-reg-office.png\" /></a>";
	arr[2]="<a href=\"http://www.birr.co.uk/company-searches.asp\"><img src=\"http://www.birr.co.uk/images/banners/banner-searches.png\" /></a>";
	arr[3]="<a href=\"http://www.birr.co.uk/secretarial-services.asp\"><img src=\"http://www.birr.co.uk/images/banners/banner-secretarial.png\" /></a>";
	arr[4]="<a href=\"http://www.birr.co.uk/welsh-business-show.asp\"><img src=\"http://www.birr.co.uk/images/banners/banner-welsh-business-show.jpg\" /></a>";
	arr.sort(function(){return Math.round(Math.random())-0.5;});
	//arr[i]="<a href=\"#Hello World\"><img src=\"banner-0.png\" /></a>";//arr.reverse();
	var str="";
	for(x in arr){
		str+=arr[x];
		}
	$("#picture_box").html(str);
	$("#picture_box a:first").addClass("active");
	setInterval("StartPictureBoxFade()",5000);
	}