var agt=navigator.userAgent.toLowerCase(); 
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
var is_mac = (agt.indexOf("mac")!=-1);
var browser_version = parseInt(navigator.appVersion);
var is_nav6 = false;
if (is_nav) {
	if (browser_version >= 5) {	is_nav6 = true };
}

function popUP(mypage, myname, w, h, pScroll) {
  var winl =  (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+pScroll+',toolbar=no,resizable=no,status=no';
  win = window.open(mypage, myname,winprops);
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); };
}

function popUpAll(mypage, myname, w, h, pScroll) {
  var winl =  (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+pScroll+',toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,';
  win = window.open(mypage, myname,winprops);
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); };
}


function doBlur(iTem) {
	if (is_nav) {
		// don't issue blur command for netscape
	} else {
		// issue blur command to turn off box around clicked elements in explorer
		iTem.blur()
	}
}



function writeCSS(path) {
	MacIE = path + "../common/css/mac_ie.css"; 
	MacNav = path + "../common/css/mac_nav.css";
	WinIE = path + "../common/css/ie.css";
	WinNav = path + "../common/css/pc_nav.css";
	if (is_mac) {
		if(is_nav) {
		 document.write("<link rel='stylesheet' href='" + MacNav + "' type='text/css'>");
		} else {
		 document.write("<link rel='stylesheet' href='" + MacIE + "' type='text/css'>");
		}
	} else {
		if(is_nav) {
			//alert(WinNav)
		 document.write("<link rel='stylesheet' href='" + WinNav + "' type='text/css'>");
		} else {
		 document.write("<link rel='stylesheet' href='" + WinIE + "' type='text/css'>");
		}

	}
}



function swapImage(pImg) {
 	var objString = pImg.src
 	var locPos = objString.lastIndexOf("_")
 	var imageTypePos = objString.lastIndexOf(".")
 	var imageString = objString.substring(imageTypePos,objString.length);
 	var locString = objString.substring(0,locPos)
 	var stateString = objString.substring(locPos,objString.length)
 	if (stateString == "_up" + imageString) {
  		stateString = "_over" + imageString
 	} else {
  	stateString = "_up" + imageString
	}
	setString = locString + stateString
 	pImg.src = setString
}

function preLoadImages() {
   if (document.images) {
	var j=0;
	var preImage = new Array();
	for (i=0; i<preLoadImages.arguments.length; i++) {
		preImage[i]=new Image();
		preImage[i].src=preLoadImages.arguments[i]
		//alert(i)
		//window.status = preImage[i].src
	}
   }
}

/////
function createArray(size)      {

 this.length = size;
 for ( var i = 1; i <= size; i++ ) {
 this[i] = null }
 return this
}

function CheckEmail() {
 
 if (document.forms[0].email.value.indexOf("@",0)==-1 || document.forms[0].email.value.indexOf(".",0)==-1 || document.forms[0].email.value.indexOf("@",0)==1) {
 return true;
 }else{
 return false;
 }
}

// Counting a character within a string starting from the end;

function CountCharEnd (stringToCountEnd,x) {

countResultEnd = stringToCountEnd.lastIndexOf(x,stringToCountEnd.length) +1;
return countResultEnd;

}
function submitForm () {
	return CheckForm()
	document.forms['updates'].submit()
}


function CheckForm() {
 
 var Alert = new createArray(11)
	
 Alert[0]="Please enter your first name";
 Alert[1]="Please enter your surname";      
 Alert[2]="Your e-mail address appears to be incorrect";

 

if (document.forms[0].name.value=="") {
  alert(Alert[0]); document.forms[0].name.focus(); return false; 
} else {
  if (document.forms[0].surname.value=="") {
  	 alert(Alert[1]); document.forms[0].surname.focus(); return false; 
  } else {
  	
     if (document.forms[0].email.value=="" || CheckEmail()) {
	   alert(Alert[2]); document.forms[0].email.focus(); return false; 
	 } else {  
 		//return true; 
	 }
 	}
}
}


function getPic(picNumber){
document.images.pic.src = "images" + "/" + "gallery" + "/" + galleryNumber + "/" + picNumber +".jpg"
}

function setPic(picNumber){
	document.write(picNumber);
}
