var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
	||(navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
	||(navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;
var moz = !ie && navigator.product == "Gecko";

function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

function attachEvt(target,eventname,handler) {		
	 	if (typeof target == 'string') { target = document.getElementById(target); }
	
	 	if ( target.addEventListener ) {
    		target.addEventListener(eventname, handler, false);
    	} else if ( target.attachEvent ) { 
         target.attachEvent("on" + eventname, handler);
    	} else { 
   	 		target["on" + eventname] = handler;
    	} 
}

// Forms
function goBack(thisform)
{
thisform.step.value = thisform.step.value - 1;
var new_form_action = 'thisform.' + thisform.name + '_action'
eval(new_form_action).value="back";
thisform.submit();
}

function get_page_size()
{
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			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 if (document.documentElement.scrollHeight) /* IE 7 */ {
			xScroll = document.documentElement.scrollWidth;
			yScroll = document.documentElement.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth + document.body.offsetLeft;
			yScroll = document.body.offsetHeight + document.body.offsetTop;					
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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 = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
}

function getframeheight(frameId) {
	   try{
      frame = document.getElementById(frameId);	      
      objToResize = (frame.style) ? frame.style : frame;
      return(objToResize.height);
   }
   catch(err){
      window.status = err.message;
   }
}


function changedisp(el,obj,hidetext,showtext) {
	
	if (document.getElementById(obj)) {
		document.getElementById(obj).style.display = document.getElementById(obj).style.display=='block' ? 'none' : 'block';
		el.innerHTML = document.getElementById(obj).style.display=='block' ? hidetext : showtext;
	}
	
}

function toggle_parameters(zone) {
	var params_div =document.getElementById('parameters'+zone);
	var params_link_div =document.getElementById('toggleparameters'+zone);
	params_div.className = params_div.className=='parameterPanel hide' ? 'parameterPanel show' : 'parameterPanel hide';
	params_link_div.innerHTML= params_div.className=='parameterPanel hide' ? 'Show Zone Settings' : 'Hide Zone Settings';
}





function $esize(Elem) { return([$ew(Elem),$eh(Elem)]); }
function $eh(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	}  
}
function $ew(Elem) { 
	
	if (ns4) { 
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function $pos(obj) { return([$px(obj),$py(obj)]); }
function $px(obj) {
  var curleft = 0;
  if(obj.offsetParent)
      while(1) { curleft += obj.offsetLeft;  if(!obj.offsetParent)  break; obj = obj.offsetParent; }
  else if(obj.x) curleft += obj.x;
  return curleft;
}

function $py(obj) {
  var curtop = 0;
  if(obj.offsetParent) 
	  while(1) { curtop += obj.offsetTop; if(!obj.offsetParent) break;obj = obj.offsetParent; } 
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}


function toggle_module_parameters(zone) {
	
	
}

function RunContent(file,width,height)
{
	var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '"><param name="movie" value="' + file + '" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><embed src="' + file + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="' + width + '" height="' + height + '"></embed></object>';
	// many thanks to gareth livingstone for his transparency testing on firefox.
	document.write(str);
}

$dg = function(el) { if (document.getElementById(el)) { return(document.getElementById(el)); } return(''); }

function usrfunc(usr,page_id,mode,querystring)
{
	
	if((mode=="edit" || mode=="preview" || mode=="audit") && (window.name!="page_frame" && window.name!="history_frame" && window.name!="current_content_frame") && usr!=0)
	{
		window.parent.location.href=url_address + 'index.php?page=' + page_id + '&mode=normal';
	}
	
	if(window.name=="page_frame" && mode!="edit" && mode!='audit') {
		
		window.parent.location.href = url_address + "_refresh/frame_main.php?module=sites&module_page=site_edit_page&page_id=" + page_id;		
	}
	
}

function get_page_size()
{
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			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 if (document.documentElement.scrollHeight) /* IE 7 */ {
			xScroll = document.documentElement.scrollWidth;
			yScroll = document.documentElement.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth + document.body.offsetLeft;
			yScroll = document.body.offsetHeight + document.body.offsetTop;					
		} 
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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 = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
}

function show_extra_info(ref,obj) {
	
	var objExtraInfo = $dg('contact_extra_info')
	
	if (objExtraInfo!='') {
		objExtraInfo.style.display = objExtraInfo.style.display=='block' ? 'none' : 'block';		
		obj.innerHTML = objExtraInfo.style.display=='block' ? 'Hide more information' : 'Add more information';
	}		
}