// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// Clock 

function startclock()
{
var thetime=new Date();

var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var nday=thetime.getDay();
var nmonth=thetime.getMonth();
var ntoday=thetime.getDate();
var nyear=thetime.getYear();
var AorP=" ";

//if (nhours>=12)
//    AorP="P.M.";
//else
//    AorP="A.M.";

//if (nhours>=13)
   // nhours-=12;

if (nhours==0)
   nhours=24;

if (nsecn<10)
 nsecn="0"+nsecn;

if (nmins<10)
 nmins="0"+nmins;

if (nday==0)
  nday="Sun";
if (nday==1)
  nday="Mon";
if (nday==2)
  nday="Tues";
if (nday==3)
  nday="Wed";
if (nday==4)
  nday="Thurs";
if (nday==5)
  nday="Fri";
if (nday==6)
  nday="Sat";

nmonth+=1;

if (nyear<=99)
  nyear= "19"+nyear;

if ((nyear>99) && (nyear<2000))
 nyear+=1900;

document.getElementById('clockspot').innerHTML='<font face="arial" size="2">  '+nhours+":"+nmins+":"+nsecn+", "+nday+", "+ntoday+"/"+nmonth+"/"+nyear+ '</font>';

setTimeout('startclock()',1000);

} 


function openProfile1() {
  document.getElementById('parah').innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='22'><img src='images/chicdown.gif' width='13' height='13' border='0' /></td><td><a href='javascript:closeProfile1()' class='menuProfile'>Your Profile</a></td></tr><tr class='menuProfile'><td width='10%' height='22px'>&nbsp;</td><td><table width='100%' border='0' cellpadding='0' cellspacing='0' class='menuProfile'><tr><td width='10%'><strong>::</strong></td><td width='90%'><a href='hand_contact.html' class='dropProfile'>Contact Details</a></td></tr><tr> <td><strong>::</strong></td><td><a href='hand_skills.aspx' class='dropProfile'>Skills  List</a></td></tr><tr><td><strong>::</strong></td><td><a href='hand_training.aspx' class='dropProfile'>Training</a></td></tr><tr><td><strong>::</strong></td><td><a href='Hand_area.aspx' class='dropProfile'>Work Area</a></td></tr><tr> <td><strong>::</strong></td><td><a href='hand_facilities.aspx' class='dropProfile'>Facilities</a></td></tr><tr><td>&nbsp;</td></tr></table></td></tr></table>";
}
 
 function closeProfile1() {
  document.getElementById('parah').innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='10%' height='22'><img src='images/chicdent.gif' width='13' height='13' border='0' /></td><td><a href='javascript:openProfile1()' class='menuProfile'>Your Profile</a></td></tr></table>";
}



function checkLog(){
	var user
	user = document.getElementById('username').value;
	var pass
	pass = document.getElementById('password').value;
	
	if(user == 'hand' && pass == 'hand'){
	window.location="pHome.php";
	document.getElementById('redirect').innerHTML = 'redirecting....';
		
	}
	else if(user == 'org' && pass == 'org'){
	window.location="oHome.php";	
	document.getElementById('redirect').innerHTML = 'redirecting....';
		
	}
	
	
}
	/*
	
	function applyAssign(){
		var appString;
		appString = "<form id="form1" name="form1" method="post" action=""><table width="100%" border="0" cellspacing="2" cellpadding="2">
                                      <tr><td colspan="2"><strong>Application Message</strong></td></tr><tr>
                                        <td width="34%" valign="top"><strong>Subject</strong></td>
										<td width="66%"><input name="textfield" type="text" id="textfield" value="Application for Position Ref: 22" /></td>
										</tr><tr>
                                        <td valign="top"><strong>Message</strong> [<a href="#" class="finderLink">Choose cover note</a>]</td>
                                        <td><textarea name="textfield2" cols="30" rows="3" id="textfield2"></textarea></td>
                                      </tr><tr><td valign="top">&nbsp;</td><td><input type="submit" name="button" id="button" value="Apply Now" /></td>
                                      </tr></table></form>";
	document.getElementById('applySpan').innerHTML = appString;	
		
		
	}
	
	*/
	
	function submitMe() {
		if(document.getElementById('password').value == 'password' || document.getElementById('password').value == ''){
	alert('Please enter your username and password in the two fields provided.');	
	}
	else{
document.forms['logIn'].submit();	
		
	}
	}
	
	
	
	
	
	
	
		
	// Codes

//var ht001 = "Title 01";
//var h001 = "Text 01";


// Main help function

function helpSwap(helpTit, helpTxt){
	
	document.getElementById('helpTitle').innerHTML = helpTit;
	document.getElementById('helpText').innerHTML = helpTxt;
	
}




// Help cookie code


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
	MM_showHideLayers('helpBox','','show')
}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function eraseCookie() {
	createCookie("helpChecker","",-1);
}




function helpCheck() {
var x = readCookie('helpChecker')
if (x) {
MM_showHideLayers('helpBox','','show')
}
}


function helpStart(name,value) {
	
var x = readCookie('helpChecker')
if (x) {
	
MM_showHideLayers('helpBox','','show');
helpSwap(name, value);

}
}

// end help cookie code


// submit on enter

function submitenter(myfield,e)
{
	
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }






   // News ajax
   
   var newsCount = 0;
   var sector = "all";
   var lastJob = "";
   var typer = "next";
   
   function newsNext(){
newsCount = newsCount + 1;
typer = "next";
getNews();

}

function newsPrevious(){
if (newsCount >= 1){
newsCount = newsCount - 1;
}
typer = "prev";
getNews();
}


   
   
   function makePOSTRequest2(url, parameters) {
      http_request2 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request2 = new XMLHttpRequest();
         if (http_request2.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request2.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request2 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request2 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request2) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request2.onreadystatechange = alertContents2;
      http_request2.open('POST', url, true);
      http_request2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request2.setRequestHeader("Content-length", parameters.length);
      http_request2.setRequestHeader("Connection", "close");
      http_request2.send(parameters);
   }

   function alertContents2() {
      if (http_request2.readyState == 4) {
         if (http_request2.status == 200) {
            //alert(http_request.responseText);
            result = http_request2.responseText;
			if (typer == "next"){
			
			  var mydiv = document.createElement("div");
           mydiv.innerHTML = result;
		   
			  if (document.all) // IE Stuff
            {
               var lostCode = mydiv.innerText;
               
            }   
            else // Mozilla does not work with innerText
            {
                var lostCode = mydiv.textContent;
            }  
			var lengoid = lostCode.length; 
			var whereStart = lengoid - 100;
			var subTest = lostCode.substring(whereStart);
			
			if(subTest == lastJob){
				lastJob = subTest;
			newsNext();	
			}
			else{
            document.getElementById('newsSpan').innerHTML = result; 
			//alert (lastJob + ":::" + subTest);	
			lastJob = subTest;
			
			}
			}
			else{
					  var mydiv = document.createElement("div");
           mydiv.innerHTML = result;
			  if (document.all) // IE Stuff
            {
               var lostCode = mydiv.innerText;
               
            }   
            else // Mozilla does not work with innerText
            {
                var lostCode = mydiv.textContent;
            }  
			var lengoid = lostCode.length; 
			var whereStart = lengoid - 100;
			var subTest = lostCode.substring(whereStart);
			
			if(subTest == lastJob){
				lastJob = subTest;
			newsPrevious();	
			}
			else{
            document.getElementById('newsSpan').innerHTML = result; 
			//alert (lastJob + ":::" + subTest);	
			lastJob = subTest;
			
			}
			
				
			}
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   
   function getNews(soc) {
      var poststr = "newsCount=" + newsCount;
	  var soctest = soc;
	  if (soctest == "all"){
		  poststr += "&sector=all";
	  }
	  else{
		  poststr += "&sector=" + sector;
	  }
      makePOSTRequest2('tools/frontNews.php', poststr);
   }
   
   
   function sectorReload(){
	  sector = document.getElementById('sectorz').value;
	  newsCount = 0;
	  document.getElementById('newsSpan').innerHTML = "Job data loading, please wait<img height='18' align='absbottom' src='images/load.gif'></img>"
	  getNews(sector);
	   
   }
   
   
   function addJobValid(){
	var valid = new Validation('addJobForm', {onSubmit:false, useTitles:true});
    var result = valid.validate();
	if (result == true){
		//alert(result);
	addJobMe(result);
	document.getElementById('waiter').innerHTML = "Data Transfering, please wait....";
	}
   }
   
   
 
    function addJobValid2(){
	var valid = new Validation('addJobForm', {onSubmit:false, useTitles:true});
    var result = valid.validate();
	if (result == true){
		//alert(result);
	addJobMe2(result);
	document.getElementById('waiter').innerHTML = "Data Transfering, please wait....";
	}
   }
   
   
    
    function addJobValid3(){
	var valid = new Validation('addJobForm', {onSubmit:false, useTitles:true});
    var result = valid.validate();
	if (result == true){
		//alert(result);
	addJobMe3(result);
	document.getElementById('waiter').innerHTML = "Data Transfering, please wait....";
	}
   }
   
   
  var http_request3 = false; 
   
   function makePOSTRequest3(url, parameters) {
      http_request3 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request3 = new XMLHttpRequest();
         if (http_request3.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request3.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request3 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request3 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request3) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request3.onreadystatechange = alertContents3;
      http_request3.open('POST', url, true);
      http_request3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request3.setRequestHeader("Content-length", parameters.length);
      http_request3.setRequestHeader("Connection", "close");
      http_request3.send(parameters);
   }

   function alertContents3() {
      if (http_request3.readyState == 4) {
         if (http_request3.status == 200) {
            //alert(http_request.responseText);
            result = http_request3.responseText;
            document.getElementById('jobSpan').innerHTML = result;  
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

   
   
   function addJobMe(result) {
var poststr = "org_name=" + document.getElementById('org_name').value;
		  poststr += "&contact_name=" + document.getElementById('contact_name').value;
		  poststr += "&contact_email=" + document.getElementById('contact_email').value;
	poststr += "&sector=" + document.getElementById('sector').value;
		  poststr += "&title=" + document.getElementById('title').value;
		  poststr += "&description=" + document.getElementById('description').value;	  
		  poststr += "&qualifications=" + document.getElementById('qualifications').value;	 
		  poststr += "&location=" + document.getElementById('location').value;	  
		  poststr += "&valid_from_date=" + document.getElementById('valid_from_date').value;
		  poststr += "&valid_to_date=" + document.getElementById('valid_to_date').value;		  
      makePOSTRequest3('tools/addJob.php', poststr);
   }
   
   
   
      function addJobMe2(result) {
var poststr = "org_name=" + document.getElementById('org_name').value;
		  poststr += "&contact_name=" + document.getElementById('contact_name').value;
		  poststr += "&contact_email=" + document.getElementById('contact_email').value;
	poststr += "&sector=" + document.getElementById('sector').value;
		  poststr += "&title=" + document.getElementById('title').value;
		  poststr += "&description=" + document.getElementById('description').value;	  
		  poststr += "&qualifications=" + document.getElementById('qualifications').value;	 
		  poststr += "&location=" + document.getElementById('location').value;	  
		  poststr += "&valid_from_date=" + document.getElementById('valid_from_date').value;
		  poststr += "&valid_to_date=" + document.getElementById('valid_to_date').value;		  
      makePOSTRequest3('../tools/addJob2.php', poststr);
   }
   
   
   
         function addJobMe3(result) {
var poststr = "org_name=" + document.getElementById('org_name').value;
		  poststr += "&contact_name=" + document.getElementById('contact_name').value;
		  poststr += "&contact_email=" + document.getElementById('contact_email').value;
	poststr += "&sector=" + document.getElementById('sector').value;
		  poststr += "&title=" + document.getElementById('title').value;
		  poststr += "&description=" + document.getElementById('description').value;	  
		  poststr += "&qualifications=" + document.getElementById('qualifications').value;	 
		  poststr += "&location=" + document.getElementById('location').value;	  
		  poststr += "&valid_from_date=" + document.getElementById('valid_from_date').value;
		  poststr += "&valid_to_date=" + document.getElementById('valid_to_date').value;		  
      makePOSTRequest3('../tools/addJob3.php', poststr);
   }
   
   
   
   
   function socChooser(d){
	socMe = d;
	  window.close();
  window.opener.document.getElementById('sector').value = socMe;
  
   }
   
   
     var http_request4 = false; 
   
   function makePOSTRequest4(url, parameters) {
      http_request4 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request4 = new XMLHttpRequest();
         if (http_request4.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request4.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request4 = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request4 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request4) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request4.onreadystatechange = alertContents4;
      http_request4.open('POST', url, true);
      http_request4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request4.setRequestHeader("Content-length", parameters.length);
      http_request4.setRequestHeader("Connection", "close");
      http_request4.send(parameters);
   }

   function alertContents4() {
      if (http_request4.readyState == 4) {
         if (http_request4.status == 200) {
            //alert(http_request.responseText);
            result = http_request4.responseText;
            document.getElementById('twitterz').innerHTML = result;  
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
      function getTwit() {
      var poststr = "";
	
      makePOSTRequest4('http://www.ravensknowledge.co.uk/twitest.php', poststr);
   }
   
   