


function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.show(e, msg);
}


function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.hide();
}


/* pre-load images due to IE6 bug */
var myimages=new Array()
function preloadimages()  {
	for (i=0;i<preloadimages.arguments.length;i++)
		{
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
		}
}

preloadimages("images/fav.gif", "images/addfav.gif",  "images/remfav.gif", "images/add_comments.png", "images/val.gif", "images/added_comments.png", "images/dload.gif", "images/read.gif", "images/unread.gif", "images/unval.gif", "images/doc.gif");



function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)

if (str.indexOf(at)==-1){
   return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
   return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false
}

 if (str.indexOf(at,(lat+1))!=-1){
    return false
 }

 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false
 }

 if (str.indexOf(dot,(lat+2))==-1){
    return false
 }

 if (str.indexOf(" ")!=-1){
    return false
 }

if (str.indexOf("yahoo") !=-1   &&  str.indexOf("-") !=-1) {
  return false
} 

 return true					
	}




function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}




function Validate_Form(f)
	{
	var msg;
	var empty_fields = "";
	var errors = "";
	var alpha_errors = "";

	msg  = "_____________________\n\n"
	msg += "Application Form Incomplete\n";
	msg += "_____________________\n\n"


	if (isblank(f.elements.uname.value))  
		{
		msg += "      Please provide a preferred user name\n";
		errors = "Y";
		}
	else
		{
		if ((f.elements.uname.value.length < 3) || (f.elements.uname.value.length > 16)) 
			{
			msg += "      Usernames must be between 3 and 16 characters.\n";
			errors = "Y";
			}
		else
			{
			var numaric = f.elements.uname.value;
			for(var j=0; j<numaric.length; j++)
				{
				var alphaa = numaric.charAt(j);
				var hh = alphaa.charCodeAt(0);
				if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
					{
					}
				else
					{
					alpha_errors = "Y";
					}
		 		}

		if  (alpha_errors == "Y")
					{
					msg += "      Usernames should contain only alphanumeric characters\n";
					errors = "Y";
					}

			}

		}

    if (isblank(f.elements.password.value))  {
      msg += "      Please provide a valid password\n";
      errors = "Y";
    }
else
	{
if ((f.elements.password.value.length < 5) || (f.elements.password.value.length > 15)) {
      msg += "      Passwords must be between 5 and 15 characters.\n";
      errors = "Y";
}

	}


    if (isblank(f.elements.email.value))  {
      msg += "      Please provide a valid email address\n";
      errors = "Y";
    }
else
	{
	if (echeck(f.elements.email.value)==false)
		{
    		msg += "      Invalid email address\n";
		errors = "Y";
		}
	}

    if (isblank(f.elements.gender.value)) {
      msg += "      Please provide your gender\n";
      errors = "Y";
    }

    if (isblank(f.elements.country.value))  {
      msg += "      Please provide your country details\n";
      errors = "Y";
    }

    if (!f.elements.o18.checked)  {
      msg += "      Please confirm that you're 18 or over\n";
      errors = "Y";
    }

    if (!errors) return true;

    alert(msg);

    return false;
}









function Validate_Email(f)
	{
	var msg;
	var empty_fields = "";
	var errors = "";
	var alpha_errors = "";


    if (isblank(f.elements.email.value))  {
      msg = "      Please provide a valid email address\n";
      errors = "Y";
    }
else
	{
	if (echeck(f.elements.email.value)==false)
		{
    		msg = "\n\n      Invalid email address\n\n";
		errors = "Y";
		}
	}



    if (!errors) return true;

    alert(msg);

    return false;
}











function dw_loadExternal(url, ifrmId, divId, bLoadMsg) 
	{
	ifrmId = ifrmId || 'buffer'; divId = divId || 'display'; 
	if ( window.frames[ifrmId] ) 
		{
		window.frames[ifrmId].location = url;
		var lyr = document.getElementById? document.getElementById(divId): null;
		if ( lyr && bLoadMsg ) 
			{ // Option to display message while retrieving data 
			lyr.innerHTML = '<p>Retrieving data. Please wait ...</p>';
			lyr.style.display = 'block'; 
			}
		return false;
		} 
	return true; // other browsers follow link
	}



function dw_displayExternal(fname, bname ,ifrmId, divId, fp) 
	{
	ifrmId = ifrmId || fname; divId = divId || bname; 
    
	var lyr = document.getElementById? document.getElementById(divId): null;
	if ( window.frames[ifrmId] && lyr ) 
		{
		lyr.innerHTML = window.frames[ifrmId].document.body.innerHTML;
		lyr.style.display = 'block'; 
		if ( typeof fp == 'function' ) 
			{
			fp();
			}
        		// Demonstrated in tooltip demo
		if ( typeof window.frames[ifrmId].doOnIframedLoad == 'function' ) 
			{
			window.frames[ifrmId].doOnIframedLoad();
			}
		}
	}




var win = null;
function Story(mypage,myname,w,h,scroll)
{
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
  win = window.open(mypage,myname,settings);
}





function changeFontSize()
{
     document.getElementById('label').style.fontSize = "10pt";
}




function go()
	{
	var destination;
	box = document.forms[0].navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = 'index.php?func=authpage&author='+destination;
	}


function go2()
	{
	var destination;
	box = document.forms[0].navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = 'index.php?func=authpage2&author='+destination;
	}



function go3()
	{
	var destination;
	box = document.forms[0].navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) self.frames['buffer8'].location.href = 'libcollab.php?func=list&filter='+destination;
	}




function goval()
	{
	var destination;
	box = document.forms[0].navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = 'index.php?func=admin&view=valmain&val='+destination;
	}





function autoResize(id){
    var newheight;
    var newwidth;

    if(document.getElementById){
        newheight=document.getElementById(id).contentWindow.document .body.scrollHeight+10;
        newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
    }

    document.getElementById(id).height= (newheight) + "px";
    document.getElementById(id).width= (newwidth) + "px";
}







function calcHeight()
{
  //find the height of the internal page
  var the_height=
    document.getElementById('iframe3').contentWindow.
      document.body.scrollHeight;

  //change the height of the iframe
  document.getElementById('iframe3').height=
      the_height;


var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer')
		{
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)  rv = parseFloat(RegExp.$1);
		if (rv == 8) 
			{
  //setup polling in case frame is changed
  setTimeout("calcHeight()",1234);//wait 1.234 seconds before resizing frame



    			}
		}

}







function ShowDocType(divno)
	{
	for(var a = 1; a < 13; a++)
		{
		element_name = "div"+a;
		element = document.getElementById(element_name);
		if (element)
			{
			if (a == 10 && divno == 6)  {element.style.display = 'none';}
			else
			if (divno == a || divno == 6)  {element.style.display = 'block';}
			else
			if (a == 4 && divno == 3)  {element.style.display = 'block';}
			else
			if (a >= 5 && a <= 9 && divno == 5)  {element.style.display = 'block';}
			else
			if (a >= 11 && a <=12  && divno == 5)  {element.style.display = 'block';}
			else
			{element.style.display = 'none';}
			}
		}
	}



function bar_width(val)
	{
	d = document.getElementById('progbar');
	d.style.width=val+"px";
	}



function showHide(box,id)  
	{ 
	var elm = document.getElementById(id);
	elm.style.display = box.checked? "inline":"none";

	id = id+"2";
	var elm = document.getElementById(id);
	elm.style.display = box.checked? "inline":"none";
 	}



function ban_confirm(view,id) {
	var answer = confirm("Delete entry?")
	if (answer){
		alert("Entry Deleted")
		window.location = "index.php?func=admin&view="+view+"&del="+id;
	}
	else{
		alert("No action taken")
	}
}


function gocont()
	{
	var cont;
	box = document.forms[0].navic;
	cont = box.options[box.selectedIndex].value;
	if (cont) buffer7.location.href = 'libcontest.php?cont='+cont; 
	}


function changeFavImg(i,id) 
	{
	if (i == 1) 
		{
		document.getElementById(id).src="images/remfav.gif";
		document.getElementById(id).title="remove favourite";  

		}
	else if (i == 2) 
		{
		document.getElementById(id).src="images/addfav.gif";
		document.getElementById(id).title="add favourite";  
		}
	}





function toggle() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("displayText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = "show sub-genres";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "hide sub-genres";
	}
} 



function cstoggle(thisname) {
 var trs=zxcByClassName(thisname);
 for (var z0=0;z0<trs.length;z0++){
  trs[z0].style.display=trs[z0].style.display=='none'?'':'none';
 }
}

function zxcByClassName(nme,el,tag){
 if (typeof(el)=='string') el=document.getElementById(el);
 el=el||document;
 for (var tag=tag||'*',reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName(tag),ary=[],z0=0; z0<els.length;z0++){
  if(reg.test(els[z0].className)) ary.push(els[z0]);
 }
 return ary;
}


function showClock()
	{
	var clock=new Date();
	var hours=clock.getHours();
	var minutes=clock.getMinutes();
	var seconds=clock.getSeconds();
	if (hours<10)  {hours="0" + hours;}
	if (minutes<10)  {minutes="0" + minutes;}
	if (seconds<10)  {seconds="0" + seconds;}
	document.getElementById('clock').innerHTML="&nbsp;&nbsp;"+hours+":"+minutes+":"+seconds;
	t=setTimeout('showClock()',500);
	}


function showDate()
	{
	var mydate=new Date();
	var year=mydate.getYear();
	if (year < 1000)
	year+=1900;
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	if (daym<10)
	daym="0"+daym;
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	document.write(" "+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" ");
	}
