function addClass(eleObj,classVal,toggle){
		if(toggle==true){//if class is to be added
			if(!eleObj.className){//if the 'class' attribute does not exist
				eleObj.className = classVal;
			}else if(eleObj.className && eleObj.className.indexOf(classVal)== -1){//if the 'class' attribute does exist then add value to existing value
				eleObj.className+=' ' + classVal;
			}
		}else if(toggle==false){//if class is to be removed
			var newClassVal=eleObj.className.replace(classVal,'');//replace classVal with empty string and return the remaining class value
			eleObj.className=newClassVal;
		}
}

function ieEleHover(parentEle,childEle){
	if(!parentEle){
		return;
	}
	this.re_ie6 =/MSIE 6.0/;
	if(this.re_ie6.test(navigator.userAgent)){//test for IE6 browser
		var eleArr = parentEle.getElementsByTagName(childEle);
		for(var i in eleArr){
			
			eleArr[i].onmouseover = function(){
				addClass(this,'ieHover',true);
				
			}
			eleArr[i].onmouseout = function(){
				addClass(this,'ieHover',false);
			}
		}
	}
}

function getEleByClass(classVal,parentObj){
	if(parentObj){
		var eleArr = parentObj.getElementsByTagName('*');
	}else{
		var eleArr = document.getElementsByTagName('*');
	}
	
	//alert(matchedEles.length);
	var matchedEles = new Array();
	for(var i = 0; i < eleArr.length; i++){
		if(eleArr[i].className == classVal){
			matchedEles.push(eleArr[i]);	
		}
	}
	return matchedEles;
}

/* ########## Start Scroll bar code ########## */
function scrollBar(varsArr){
	this.obj;
	this.scaleBar;
	this.handle;
	this.handleH;
	this.scrollStep;
	this.ObjContent;
	this.ObjTotalH;//total height inc hidden area at onload
	this.contentWrap;
	this.barStartY = 0;
	this.eStartY = 0;
	this.eTarget;
	
		
	parentClass = this;
		
	for (var key in varsArr) { this[key] = varsArr[key]; }
	
	this.iniVars = function(){
		if(!this.obj){
			return;
		}
		//alert('scrollh = '+this.obj.scrollHeight+'clientheight = '+this.obj.clientHeight);
		if(this.obj.scrollHeight > this.obj.clientHeight){
			this.ObjContent = this.obj.innerHTML;
			this.obj.innerHTML = "";
			this.obj.style.overflow = "hidden";
			this.obj.style.position = "relative";
			//
			this.createEles();
			this.contentWrap.style.paddingRight = "15px";
			this.handleH =  Math.round(this.obj.clientHeight * (this.obj.clientHeight/this.contentWrap.clientHeight));// + 2 for border top and bottom
			//this.handleH = Math.round(this.obj.clientHeight * (this.obj.clientHeight/this.contentWrap.clientHeight)) + 2;// + 2 for border top and bottom
			this.scrollStep =  (this.contentWrap.clientHeight-this.obj.clientHeight)/(this.scaleBar.clientHeight - this.handleH);
			//this.scrollStep =  Math.round(this.contentWrap.clientHeight/(this.scaleBar.clientHeight - this.handleH));
			this.handle.style.height = this.handleH + "px";
			this.ObjTotalH = this.obj.scrollHeight;
			
			this.handle.onmousedown = createMethodRef(this, "onMouseDown");
			this.scaleBar.onclick = createMethodRef(this, "onClick");
	
			//document.getElementById('debugBox').innerHTML = "this.obj.clientHeight = " + this.obj.clientHeight + " this.handleH = " + this.handleH + " this.contentWrap.clientHeight) = " + this.contentWrap.clientHeight + " this.scrollStep = " + this.scrollStep + " this.scaleBar.clientHeight = " + this.scaleBar.clientHeight;
		}
	}
	//alert("this.obj.clientHeight = " + this.obj.clientHeight )
	this.createEles = function(){
		this.scaleBar = document.createElement("div");
		this.scaleBar.className = "scaleBar";
		this.handle = document.createElement("div");
		this.handle.className = "handle";
		this.contentWrap = document.createElement("div");
		this.contentWrap.className = 'wrap';
		this.contentWrap.innerHTML = this.ObjContent;
		this.scaleBar.style.height = this.obj.clientHeight + "px";
		this.scaleBar.appendChild(this.handle);
		this.obj.appendChild(this.contentWrap);
		this.obj.appendChild(this.scaleBar);
		
	}
		
	this.moveHandle = function(e){
		if(window.event){
			e = window.event;
		}
		
		if(e.srcElement){
			this.eTarget = e.srcElement;
		}else{
			this.eTarget = e.target;
		}
		
		if(this.handle.offsetTop < 0){
			this.handle.style.top = "0px";
			return false;
		}else if(this.handle.offsetTop > (this.scaleBar.clientHeight - this.handleH)){//handle at bottom of range bar
			this.handle.style.top = this.scaleBar.clientHeight - this.handleH + "px";
		}else{
			this.handle.style.top = this.barStartY - (this.eStartY - e.clientY) + 'px';
			this.eStartY = e.clientY;
			this.barStartY = this.handle.offsetTop;
			this.moveContent();
		}
		return false;
	}
	this.moveContent = function(e){
		if(this.handle.offsetTop <= 0){//handle at top of range bar
			this.contentWrap.style.marginTop = 0;
		}else if(this.handle.offsetTop > (this.scaleBar.clientHeight - this.handleH)){//handle at bottom of range bar
			this.contentWrap.style.marginTop = this.obj.clientHeight - this.ObjTotalH + "px";
		}else{//handle general movement
			this.contentWrap.style.marginTop = (this.handle.offsetTop <= (this.scaleBar.clientHeight - this.handleH))? -(this.handle.offsetTop * this.scrollStep) + "px" : -(this.handle.offsetTop * this.scrollStep) - this.handleH + (this.obj.clientHeight) + "px";
		}
		
	}
	
	
		this.iniVars();
}	
	
scrollBar.prototype.onMouseDown = function(e){
	if(window.event){
		e = window.event;
	}
	
	if(e.srcElement){
		eTarget = e.srcElement;
	}else{
		eTarget = e.target;
	}
	
	this.barStartY = this.handle.offsetTop;
	this.eStartY = e.clientY;
	
	document.body.focus();
	document.body.onmousemove = createMethodRef(this, "moveHandle");
	
		
		document.onselectstart = function () { return false; };

//	}else{
			//alert('not worky');
		document.onmousedown = function () { return false; };
//	}
	
	//document.body.unselectable = "on";
	
	document.onmouseup = createMethodRef(this, "onMouseUp");
	return false;
}
scrollBar.prototype.adjustHandle = function(){

	if(this.handle.offsetTop < 0){
		this.handle.style.top = "0px";
		return false;
	}else if(this.handle.offsetTop > (this.scaleBar.clientHeight - this.handleH)){//handle at bottom of range bar
		this.handle.style.top = this.scaleBar.clientHeight - this.handleH + "px";
	}

}

scrollBar.prototype.onClick = function(e){
	if(window.event){
		e = window.event;
	}
	if(e.srcElement){
		eTarget = e.srcElement;
	}else{
		eTarget = e.target;
	}
	
	if(eTarget == this.scaleBar){
		
		var mousePosY = findElePos(this.scaleBar);
		this.handle.style.top = e.clientY - mousePosY + "px";
		this.adjustHandle();
		this.moveContent();
	}	
	
}

scrollBar.prototype.onMouseUp = function(e){
	
		//document.onselectstart = function () { return true; };
		document.body.onmousemove = null;
		//document.unselectable = "off";
		document.onmousedown = function () { return true; };
		this.adjustHandle();
		return true;
}
/* ########## End Scroll bar code ########## */


function createMethodRef(object, methodName) {
    return function () {
        object[methodName].apply(object,arguments);
    };
}


function findElePos(obj){
		var currTop = 0;
		var currLeft = 0;
		/**/do{
			currLeft += obj.offsetLeft;
			currTop += obj.offsetTop;
		}while(obj = obj.offsetParent);
		return currTop;
	
}
function checkTerms(obj) {
  if (obj.terms.checked) obj.submit();
  else alert ('You must accept the Terms & Conditions before proceed.'); return false;
}
window.onload = function(){
	ieEleHover(document.getElementById('mainNav'),'li');

	var scroller1 = new scrollBar({obj:document.getElementById('scrollRCol')});
	var scroller2 = new scrollBar({obj:document.getElementById('scrollDet')});
	var scroller3 = new scrollBar({obj:document.getElementById('scrollForm')});
	var scroller4 = new scrollBar({obj:document.getElementById('scrollMain')});
}

