var agt = navigator.userAgent.toLowerCase();
var isNN = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var isMajor = parseInt(navigator.appVersion);
var isMinor = parseFloat(navigator.appVersion);
var isNN4 = (isNN && (isMajor <= 4));
var isNN6up = (isNN && (isMajor >= 5));
var isIE = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

backid		= 0;
backlist	= new Array();
backlist[0]	= "";

function closefloatingdiv(){
  el = getlayer('floatingdiv');
  if(el){
    layeroff(el);
    el.innerHTML = "";
  }
}

function ToggleUserAccount(pkey, onoff, disp){
  el = getlayer('floatingdiv');
  if(el){
    
    if(el.style){
      el.style.position= 'absolute';
      el.style.top = '150px';
      //el.left= '100px';
      el.style.width = '200px';
      //el.style.height = '150px';
      el.innerHTML = '<form name=disform action=\'users.php\' method=post><table width=200 cellpadding=0 cellspacing=0><tr><td>'+disp+' User</td><td align=right><a href=\'javascript:closefloatingdiv();\'><img border=0 width=11 height=12 border=1 src=\'images/i_delete.gif\'></td></tr></table><br>your password<br><input name=pwd type=password><br><br><a href="javascript:if(document.disform.pwd.value!= \'\' ){document.disform.submit();}">'+disp+' Now</a><input type=hidden name=perskey value='+pkey+'><input name=actionfield type=hidden value=\''+onoff+'\'></form>';
      el.className = 'floatingvis';
      layeron(el);
    }else if(el.visibility){
      el.visibility="hide";
    }
  }
}

function getlayer(layername) {
	if (document.layers) {
		var theLayer=document.layers[layername];
	} else {
		if (document.getElementById) {
			var theLayer=document.getElementById(layername);
		} else {
			var theLayer=document.all[layername];
		}
	};

	return theLayer;
	
}

function layeron(slayer) {
	if (document.layers) {
		slayer.visibility="visible"
	} else {
		if (document.getElementById) {
			slayer.style.visibility="visible";
			slayer.style.display="inline";
		} else {
			slayer.style.visibility="visible";
			
		}
	}
}

function layeroff(slayer) {
	if (document.layers) {
		slayer.visibility="hide"
	} else {
		if (document.getElementById) {
			slayer.style.visibility="hidden";
			slayer.style.display="none"
		} else {
			slayer.style.visibility="hidden";
		}
	}
}
function savetheform(){
    var extra="m1="+m1+"&m2="+m2;
    if(document.userform.action.indexOf('?') == -1){
      extra = "?" + extra;
    }else{
      extra = "&" + extra;
    }
    document.userform.action=document.userform.action+extra;
    document.userform.submit();
    //var backid = getbackid();
    //var backsteps = getbacksteps();
    //if(backid > 0 && backsteps > 1){
    //  //document.cookie = "backid=" + (parseInt(backid)+1);
    //  document.cookie = "backsteps=" + (parseInt(backsteps)+1);
    //}else{
      //document.cookie = "backid=0";
      //document.cookie = "backsteps=0";
    //}
}
function menuclick(href){
  //document.cookie = "backid=0";
  //document.cookie = "backstep=0";
  resetbacklist();
  document.location.href=href;
}

function resizetext(){
  document.location.href='splash.php?m1=0&m2=0&resize=true';
}

function pageclick(href,addtoback){
  if(addtoback){
    //var backid = getbackid();
    //var backsteps = getbacksteps();
    //document.cookie = "backid=" + (parseInt(backid)+1);
    //document.cookie = "backsteps=" + (parseInt(backsteps)+1);
    addtobacklist(document.location.href);
  }else{
    //document.cookie = "backid=0";
    //document.cookie = "backsteps=0";
  }
  var extra="m1="+m1+"&m2="+m2;
  if(href.indexOf('?') == -1){
    extra = "?" + extra;
  }else{
    extra = "&" + extra;
  }
  document.location.href=href+extra;
}

var imagewindow;
var infowindow;

var sPopupBlockedMsg = 'You have popups blocked.\n\nIf you look at the top of this page you should see a coloured bar saying \'Pop-up blocked\'. \n\nYou should click on this coloured bar and choose \'Always allow pop-ups from this site\'.\n\nOR\n\n\'Temporarily allow pop-ups\'\n\nThis will cause no harm to your computer.\n\nWe do not open pop-ups from external sites on Design Graduates';

function cvpop(key){
	if (imagewindow) {
		if(!imagewindow.closed){
			imagewindow.close();
		}
	}
	var w = 700;
	var h = 500;
	var x = (screen.availWidth - w)/2;
	var y = (screen.availHeight - h)/2;
	var sParams = "menubar=yes,toolbar=no,directories=no,WIDTH=" + w + ",height=" + h + ",left="+x+",top="+y+",resizable=yes";
	imagewindow=window.open('cv.php?key='+key,'Resume',sParams);
	if (imagewindow==null || typeof(imagewindow)=="undefined") {
		alert(sPopupBlockedMsg);
	}else{
		imagewindow.focus();
	}
}

function imagepop_old(src,title,width,height){
	imagesrc = src;
	imagetitle = title;
	if (imagewindow) {
		if(! imagewindow.closed){
			imagewindow.close();
		}
	}
	l=(screen.availWidth-width)/2;
	t= (screen.availHeight-height)/2
	imagewindow=window.open('imagepopup.htm',title,'resizable=no,toolbar=no,scrollbars=no,directories=no,menubar=no,width='+width+',height='+height+',top='+t+',left='+l);
	if (imagewindow==null || typeof(imagewindow)=="undefined") {
		alert(sPopupBlockedMsg);
	}else{
		imagewindow.focus();
	}
}

function imagepop(src,width,height){
	imagesrc = src;
	imagetitle = "";
	if (imagewindow) {
		if(! imagewindow.closed){
			imagewindow.close();
		}
	}
	l=(screen.availWidth-width)/2;
	t= (screen.availHeight-height)/2
	imagewindow=window.open('imagepopup.htm',"",'resizable=no,toolbar=no,scrollbars=no,directories=no,menubar=no,width='+width+',height='+height+',top='+t+',left='+l);
  	if (imagewindow==null || typeof(imagewindow)=="undefined") {
		alert(sPopupBlockedMsg);
	}else{
		imagewindow.focus();
	}
}

function imageinfopop(imgkey){
	if(infowindow) {
		if(! infowindow.closed){
			infowindow.close();
		}
	}
	w=400;
	h=300
	l=(screen.availWidth-w)/2;
	t= (screen.availHeight-h)/2
	infowindow=window.open('imageinfo.php?ikey='+imgkey,"",'resizable=no,toolbar=no,scrollbars=no,directories=no,menubar=no,width='+w+',height='+h+',top='+t+',left='+l);
	if (infowindow==null || typeof(infowindow)=="undefined") {
		alert(sPopupBlockedMsg);
	}else{
		infowindow.focus();
	}
}

function emailpreviewpop(tkey){
  if(infowindow) {
    if(! infowindow.closed){
      infowindow.close();
    }
  }
  w=screen.availWidth-50;
  h=600
  l=(screen.availWidth-w)/2;
  t= (screen.availHeight-h)/2
  infowindow=window.open('emailpreview.php?tkey='+tkey,"",'resizable=yes,toolbar=no,directories=no,menubar=no,width='+w+',height='+h+',top='+t+',left='+l);
}

function resetbacklist(){
  document.cookie = "backid=0";
  document.cookie = "backstep=0";
}

function addtobacklist(loc){
  var backid = getbackid();
  var backsteps = getbacksteps();
  document.cookie = "backid=" + (parseInt(backid)+1);
  document.cookie = "backsteps=" + (parseInt(backsteps)+1);
  backid++;
  backlist[backid] = loc;
}

function goback(){
  var backid = getbackid();
  var backsteps = getbacksteps();
  if(backid>0){
    document.cookie = "backid=" + (backid - 1);
    if(backsteps > 1){
      document.cookie = "backsteps=" + (backsteps - 1);
    }
    //history.go(-backsteps);
    history.go(-1);
  }
}

function getbackid(){
  var backid = getcookiedata(document,"backid");
  if(isNaN(backid)){
    backid= 0;
  }else{
    backid=parseInt(backid);
  }
  return backid;
}

function getbacksteps(){
  var backsteps = getcookiedata(document,"backsteps");
  if(isNaN(backsteps)){
    backsteps= 0;
  }else{
    backsteps=parseInt(backsteps);
  }
  return backsteps;
}

function getcookiedata(doc,labelname){
	var labellen = labelname.length;
	var cookiedata = doc.cookie;
	var clen = cookiedata.length;
	var i = 0;
	var cend;
	while (i<clen){
		var j = i + labellen;
		if(cookiedata.substring(i,j) == labelname){
			cend = cookiedata.indexOf(";",j);
			if(cend == -1){
				cend = cookiedata.length
			}
			return unescape(cookiedata.substring(j+1,cend));
		}
		i++;
	}
	return ""
}
