/** newsletter script from robin **/
function clearText(thefield){
	if (thefield.defaultValue==thefield.value) thefield.value = ""
} 
function CheckMultiple(name) 
				{
					theFrm = document.frmSS;
					for (var i=0; i < theFrm.length; i++) 
					{
						fldObj = theFrm.elements[i];
						var fieldnamecheck=fldObj.name.indexOf(name);
						if (fieldnamecheck != -1) {
							if (fldObj.checked) {
								return true;
							}
						}
					}
					return false;
				}


				function CheckSS()
				{
					theFrm = document.frmSS;

					hasDot = theFrm.Email.value.indexOf(".");
					hasAt = theFrm.Email.value.indexOf("@");
					
					if (hasDot == -1 || hasAt == -1)
					{
						alert("Please enter a valid email address.");
						theFrm.Email.focus();
						theFrm.Email.select();
						return false;
					}

					
					return true;
				}
/** end **/
function RightBar(){
	var r = document.getElementById('eventDetailsRgt');
	var s = document.getElementById('content');
	if(!r || !s) return;
	if(s.offsetHeight>r.offsetHeight) r.style.height = s.offsetHeight+'px';
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,yScroll) 
	return arrayPageSize;
}
function getScroll(){
  	var scrOfX = 0, scrOfY = 0;
 	if( typeof( window.pageYOffset ) == 'number' ) {
   	  scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
  	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
       scrOfY = document.body.scrollTop;
       scrOfX = document.body.scrollLeft;
  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
       scrOfY = document.documentElement.scrollTop;
       scrOfX = document.documentElement.scrollLeft;
    }
    return new Array(scrOfX,scrOfY);
      // document.title = scrOfY+" ~ "+getPageSize()[3];
}
function getOffsetTop(obj){
	obj = document.getElementById(obj);
	var n = 0;
	while(obj.offsetParent){
		n+=obj.offsetTop;
		//alert(n);
		obj = obj.offsetParent;
	}
	return n;
}
function getOffsetLeft(obj){
	obj = document.getElementById(obj);
	var n = 0;
	while(obj.offsetParent){
		n+=obj.offsetLeft;
		//alert(n);
		obj = obj.offsetParent;
	}
	return n;
}
function CCForm(){
	var el,s='',i,k,fm = document.forms['fmSearch'];
	if(!fm) return;
	for(i=0;i<fm.elements.length;i++){
		if(fm.elements[i].type=='select-one'){
			el = document.createElement('DIV');
			el.className = 'CCMenu';
			el.setAttribute("id","CCMenu_"+fm.elements[i].name);
			el.setAttribute("selname",fm.elements[i].name);
			for(k=0;k<fm.elements[i].options.length;k++){
				s += fm.elements[i].options[k].value;
				var sp = document.createElement('SPAN');
				sp.setAttribute("val",fm.elements[i].options[k].value);
				sp.setAttribute("order",k);
				sp.appendChild(document.createTextNode(fm.elements[i].options[k].text));
				sp.onclick = function(){
					//alert(this.getAttribute("val"));
					//alert(getPageSize()[1]+" ~ "+this.parentNode.id+" "+getOffsetTop(this.parentNode.id));
					this.parentNode.style.display = 'none';
					fm.elements[this.parentNode.getAttribute("selname")].selectedIndex = this.getAttribute("order");
					document.getElementById("seldummy_"+this.parentNode.getAttribute("selname")).innerHTML = (this.innerHTML.length>20?this.innerHTML.substr(0,17)+"..":this.innerHTML);
					for(var j=0;j<this.parentNode.getElementsByTagName('SPAN').length;j++){
						this.parentNode.getElementsByTagName('SPAN')[j].style.fontWeight='normal';
					}
					this.style.fontWeight='800';
				}
				sp.onmouseover = function(){
					this.style.backgroundColor = '#eee';
				}
				sp.onmouseout = function(){
					this.style.backgroundColor = '#fff';
				}
				el.appendChild(sp);
			}
			/** replace current form controls for custom ones **/
			var elTop = getOffsetTop(fm.elements[i].id)
			var elLeft = getOffsetLeft(fm.elements[i].id)
			//alert(getOffsetTop(fm.elements[i].id)+" ~ "+elLeft);
			var selDummy = document.createElement('DIV');
			selDummy.className = 'selDummy';
			selDummy.setAttribute("name",fm.elements[i].name);
			selDummy.setAttribute("id","seldummy_"+fm.elements[i].name);
			selDummy.style.top = elTop+'px';
			selDummy.style.left = elLeft+'px';
			selDummy.appendChild(document.createTextNode(fm.elements[i].options[0].text));
			selDummy.onclick = function(){
				var dummy = document.getElementById("CCMenu_"+this.getAttribute("name"));
				dummy.style.display = 'block';
				dummy.style.top = this.offsetTop+'px';
				dummy.style.left = this.offsetLeft-dummy.offsetWidth+this.offsetWidth+'px';
				var $bottom = getOffsetTop("CCMenu_"+this.getAttribute("name"))+dummy.offsetHeight;
				if(($bottom-getScroll()[1])>getPageSize()[3]){
				dummy.style.top = parseInt(dummy.style.top)-($bottom-getPageSize()[3])-5+'px';
				}
				if(getScroll()[1]>dummy.offsetTop){
				dummy.style.top = getScroll()[1]+5+'px';
				}
				dummy.onmouseout = hideDiv;
			}
			document.forms['fmSearch'].appendChild(selDummy);
			fm.elements[i].style.visibility = 'hidden';
			/** end replace custom controls **/
			document.forms['fmSearch'].appendChild(el);
		}
		
	}
}
function hideDiv(evt) { 
 var b,relT,mT=false; 
 if(document.all&&!window.opera){b=event.srcElement;
// alert(b.id); return;
  while(b!=null){if(b.tagName=="DIV"){mT=true;break;}b=b.parentElement;}
  if(!b.contains(event.toElement)){b.style.display="none";}
 }
 else if(document.getElementById){b=evt.currentTarget;relT=evt.relatedTarget;
  while(relT!=null){if(b==relT){mT=true;break;}
  relT=relT.parentNode;}if(!mT){b.style.display="none";}}
}
function setTellAFriend(){
	if(!document.forms['fmTellAFriend']) return;
	var fm = document.forms['fmTellAFriend'];
	fm.action = location.href+"?#tab-tellafriend";
	var el = document.createElement('INPUT');
	el.setAttribute("type","hidden");
	el.setAttribute("name","page");
	el.setAttribute("value",location.href);
	fm.appendChild(el);
}
jQuery.noConflict();
jQuery(document).ready(function(){
	RightBar();
	CCForm();
	setTellAFriend();
	try {
	CCTabGUI();
	} catch(e){
	
	}
	var p = jQuery('#wrapper').offset();
	var w = jQuery('#wrapper').css("width");
	jQuery('.newslettersignup h2').css("margin",0);
	jQuery('.newslettersignup').
		css("position","absolute").
		css("color","white").
		css("top",5).
		css("left",(p.left+parseInt(w))-460);
	/**jQuery('.newslettersignup').css("color","white");
	jQuery('.newslettersignup h2').css("margin",0);
	jQuery('.newslettersignup').css("position","absolute");
	jQuery('.newslettersignup').css("top",5);
	jQuery('.newslettersignup').css("left",(p.left+parseInt(w))-460);
	**/

});
