// ******************************************************
// File Level Definitions
// ******************************************************

var win = null, scroll, x = 0


// ******************************************************
// Scroll Up & Down
// ******************************************************

function moveDn(){
	if (holder.height() - content.height() < content.top() && scroll==true){
		content.moveTo(0,--x);
		setTimeout(moveDn,10);
	}
}

function moveUp(){
	if (content.top() < 0 && scroll==true){
		content.moveTo(0,++x);
		setTimeout(moveUp,10);
	}
}

// ******************************************************
// Hover Changer 
// ******************************************************

var lastColour=null;
function mOvr(src,colour,el) {
	if(!src.contains(event.fromElement))
		eval("lastColour=src.style."+el);
		eval("src.style."+el+"=colour");
}
function mOut(src,el) {
	if(!src.contains(event.toElement))	
		eval("src.style."+el+"=lastColour");
}


// ******************************************************
// Popup Window 
// ******************************************************

function NewWindow(mypage,myname,w,h,scroll,pos){
  if(pos=="random"){
    LeftPosition=(screen.availWidth)?Math.floor(Math.random()*(screen.availWidth-w)):50;TopPosition=(screen.availHeight)?Math.floor(Math.random()*((screen.availHeight-h)-75)):50;
  }
  if(pos=="center"){
    LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;
  }
  if(pos=="default"){
    LeftPosition=50;TopPosition=50
  }
  else if((pos!="center" && pos!="random" && pos!="default") || pos==null){
    LeftPosition=0;TopPosition=20
  }
  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
  win=window.open(mypage,myname,settings);
  if(win.focus){
    win.focus();
  }
}

// ******************************************************
// Cookie Stuff
// ******************************************************

function getCookieVal (offset) {  
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
  endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  
  while (i < clen) {    
  var j = i + alen;    
  if (document.cookie.substring(i, j) == arg)      
  return getCookieVal (j);    
  i = document.cookie.indexOf(" ", i) + 1;    
  if (i == 0) break;   
}  
return null;
}

function addOnClick(){
  //var coll = document.all.tags("A"); // Setup Collection 'coll' for all 'A' tags
  var coll = document.links

  if (coll != null){
    for (i=0; i<coll.length; i++){	// Loop round every object in collection 'coll'
	  var childObj = coll[i].firstChild // Setup object for possible child
	  
	  if(childObj != null){	  // check if Child exists
		var altText = childObj.alt

		if(altText == "Download" || altText == "download"){ // check if child object is the download file
		  coll[i].onclick = function anonymous(){return downloadFile(this.href)} // if child is download then add onclick event to parent to support data capture
		 // break  // break loop when found
		}
	  }
	}
  }
}

function downloadFile(src){
  
  var myCookie = GetCookie('www_wcigroup_com:fileDownload');

    if(myCookie == null){

  var myTitle = document.title.substring(27,document.title.length);
    win=window.open('/wci/system/registration.aspx?filename='+src+'&title='+myTitle,'downloadForm','width=700,height=500,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
    if(win.focus){
      win.focus();
    }
    return false
  }
}