// omni rms javascript

window.onload = function() {
	setTimeout('newsticker(0)',500);
}

var max = 2;
var op_in;
var op_out;
var li_id;
var elem_li;


function newsticker(id){
	var ul;
	//form fix - redid in php
	/*
	var forms=document.getElementsByTagName('FORM');
	for(var i=0;i<forms.length;i++){
		if(forms[i].action=="/form"){
			forms[i].action="/form/";
		}
	}*/
	
	if(ul = document.getElementById('newstickerul')){
		var elems = ul.getElementsByTagName('li');
		
		li_id = id;	
		elem_li = elems[li_id];	
		elem_li.style.display = "inline";
		elem = elem_li.getElementsByTagName('a')[0];
		
		op_in = new ColorTween(elem.style,'color',Tween.regularEaseOut,'eeeeee','333333',1);
		op_out = new ColorTween(elem.style,'color',Tween.regularEaseOut,'333333','eeeeee',1);
	//	op_in = new OpacityTween(elem,Tween.regularEaseOut,0,100,1);
	//	op_out = new OpacityTween(elem,Tween.regularEaseOut,100,0,1);
		op_in.start();
		op_in.onMotionFinished = function(){
			setTimeout('fadeout()',5000);
			//console.log(elem.style.color);
		}
	}
}

function fadeout(){
	if(li_id < max){
		li_id++;
	} else {
		li_id = 0;
	}
	op_out.start();
	op_out.onMotionFinished = function(){
		elem_li.style.display = "none";
		setTimeout('newsticker(li_id)',500);
		//console.log(elem.style.color);
	}
}



/**************************************************
menu stuff
**************************************************/

var menuSwitcherOn = false;
document.onmousemove=menuSwitcher;
var activesub = '';

function getElementsByClassName(object,name){
	var allNodes=object.getElementsByTagName('*');
	if(!allNodes){
		var allNodes=object.all;	
	}
	var returnObj=new Array;
	var count=0;
	for(var i=0;i<allNodes.length;i++){
		if(allNodes[i].className.replace(name,"")!=allNodes[i].className){
			returnObj[count]=allNodes[i];
			count++;
		}
	}
	return returnObj;
}

function showSubMenu(subid,li){
	if(activesub != subid){		

		hideSubMenu();
		
		//change tab colour
		li.className = "active";
		if(li != document.getElementById('activetab')){
			document.getElementById('activetab').className = "active_hover";
		}
		var tabdiv = getElementsByClassName(li,'tabend');
		if(tabdiv.length > 0){
			tabdiv[0].className = "tabend tabend_active";
		}
		menuSwitcherOn = true;
		//alert(subid);
		var sub = document.getElementById('submenu_'+subid);
		sub.style.display = "inline";
		var subs = getElementsByClassName(document,'activesubnav');
		if(subs.length > 0){
			subs[0].style.display = "none";
		}
		activesub = subid;
	}
}

function hideSubMenu(){
	var allsubs = getElementsByClassName(document,'subnav');
	if(allsubs.length > 0){
		for(i = 0;i<allsubs.length;i++){
			allsubs[i].style.display = "none";
		}
	}
	var alltabs = getElementsByClassName(document,'tabend');
	if(alltabs.length > 0){
		for(i=0;i<alltabs.length;i++){
			if(alltabs[i].parentNode.parentNode.id != "activetab") {
				alltabs[i].className = "tabend";
			}
		}
	}
	var navul = document.getElementById('nav');
	var lis = navul.getElementsByTagName('LI');
	for(i=0;i<lis.length;i++){
		if(lis[i].id != 'activetab'){
			lis[i].className = "";
		}
	}
	var subs = getElementsByClassName(document,'activesubnav');
	if(subs.length > 0){
		subs[0].style.display = "inline";
	}
	document.getElementById('activetab').className = "active";
	activesub='';
}

function menuSwitcher(e){
	var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX;
		posy = e.clientY;
		if (isIE)
		{
			posx = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
			posy = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		}
	}
	//document.getElementById('testinput').value=posy;
	
	if((posy < 61 || posy > 107) && menuSwitcherOn == true) {
		//hide the submenu
		menuSwitcherOn = false;
		hideSubMenu();
	}
}


var msg;

function omniCSQFormCheck(){

	msg = "";
	var box;
	
	if(box = document.getElementById('csq_manager_name')){
		if(box.value == ''){
			msg += "<br />Manager Name not set";
			box.style.background = '#fefeba';
		}
	}
	if(box = document.getElementById('csq_department')){
		if(box.value == ''){
			msg += "<br />Department not set";
			box.style.background = '#fefeba';
		}
	}
	if(box = document.getElementById('csq_role')){
		if(box.value == ''){
			msg += "<br />Role not set";
			box.style.background = '#fefeba';
		}
	}
	if(box = document.getElementById('csq_refno')){
		if(box.value == ''){
			msg += "<br />Ref. No. not set";
			box.style.background = '#fefeba';
		} else {
			var refno = document.getElementById('csq_refno').value;
		}
	}
	if(box = document.getElementById('csq_email')){
		if(box.value == ''){
			msg += "<br />Email not set";
			box.style.background = '#fefeba';
		}
	}
	
	var myConn = new XHConn();
	var query="refToCheck="+refno;
	myConn.connect("/satisfaction_files/checkExistingRefs.php", "POST", query, checkRefs);

}

function checkRefs(data){
	var ref_returnval=data.responseText;

	if(ref_returnval == "exists"){
		msg += "<br /><br />The reference number provided is already in use";
	}
	if(msg.length > 0){
		document.getElementById('csq_errormsg').innerHTML = "<p>Please correct the following errors:"+msg+"</p>";
	} else {
		var theform = document.getElementById('satisfaction');
		theform.submit();
	}
}




//============================================================================================
/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
if(document.getElementById('statusbar')){
	var oldStatusBackground=document.getElementById('statusbar').style.backgroundImage;
}
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
    	//before load, set statusbar to loading icon
    	if(document.getElementById('statusbar')){
    		document.getElementById('statusbar').style.backgroundImage="url(/duocms-resources/icons/loading2.gif)";
    	}
    		
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete){
        	//after loaded set statusbar back to old background
        	if(document.getElementById('statusbar') && oldStatusBackground){
	    		document.getElementById('statusbar').style.backgroundImage=oldStatusBackground;
    		}else if(document.getElementById('statusbar')){
    			document.getElementById('statusbar').style.backgroundImage='';
    		}
        	
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}
