function fitImage(targetDivId) {

  var img_id = $('#' + targetDivId).attr('src')
  
  $('#' + targetDivId).html('<div style="overflow:hidden; height:100%; width:100%"><img style=" position:relative" id="' + targetDivId + '_img" src="' + img_id + '" ></div>');

  $('#' + targetDivId + '_img').load(function(){
  
      var w = $('#' + targetDivId).width()
      var h = $('#' + targetDivId).height()  
      var iW = $(this).width()
      var iH = $(this).height()

      //alert(iW + ' ; ' + iH + ' ; ' + w + ' ; ' + h + ' ; ' + w/iW + ' ; ' + h/iH);
      
      
      if ((h/iH)>(w/iW)) {
         scale = h / iH;
         $('#' + targetDivId + '_img').css({
           left: Math.round(((iW * scale) - w) / -2) + 'px',
           top: '0px',
           width: Math.round((iW * scale)) + 'px',
           height: h + 'px'
        })  
      }  
      else {
        scale = w / iW;
        $('#' + targetDivId + '_img').css({
        left: '0px',
        top: Math.round(((iH * scale) - h) / -2) + 'px',
        width: w + 'px',
        height: Math.round((iH * scale)) + 'px'
        })
      }   
      //$('#' + targetDivId + '_img').attr({'src':img_id})  
    })


}
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
// Shadow class handlers-------------------------------------------------------------------
var gradientshadow={}
gradientshadow.depth=7 //Depth of shadow in pixels
gradientshadow.containers=[]

gradientshadow.create=function(){
//var a = document.all ? document.all : document.getElementsByTagName('*')
var a = getElementsByClassName(document,"*","shadow")
for (var i = 0;i < a.length;i++) {

		for (var x=0; x<gradientshadow.depth; x++){
			var newSd = document.createElement("DIV")
			newSd.className = "shadow_inner"
			newSd.id="shadow"+gradientshadow.containers.length+"_"+x //Each shadow DIV has an id of "shadowL_X" (L=index of target element, X=index of shadow (depth) 
			if (a[i].getAttribute("rel"))
				newSd.style.background = a[i].getAttribute("rel")
			else
				newSd.style.background = "#222222" //default shadow color if none specified
			
			var parent = a[i].parentNode;
            parent.appendChild(newSd) ;
		/*	document.body.appendChild(newSd) */
		}
	gradientshadow.containers[gradientshadow.containers.length]=a[i]
	
}
gradientshadow.position()

}

gradientshadow.position=function(){
if (gradientshadow.containers.length>0){
	for (var i=0; i<gradientshadow.containers.length; i++){
		for (var x=0; x<gradientshadow.depth; x++){
  		var shadowdiv=document.getElementById("shadow"+i+"_"+x)
			shadowdiv.style.width = gradientshadow.containers[i].offsetWidth + "px"
			shadowdiv.style.height = gradientshadow.containers[i].offsetHeight + "px"
			shadowdiv.style.left = gradientshadow.containers[i].offsetLeft + x + "px"
			shadowdiv.style.top = gradientshadow.containers[i].offsetTop + x + "px"
		}
	}
}
}
if (window.addEventListener)
window.addEventListener("load", gradientshadow.create, false)
else if (window.attachEvent)
window.attachEvent("onload", gradientshadow.create)

// displayStatus -------------------------------------------------------------------------
function displayStatus(msgStr) {
  window.status=msgStr;
  return true
}

//hideStatus Hide Status bar -------------------------------------------------------------
function hideStatus(){
  window.status=''
  return true
}
//trim string prototypr addition --------------------------------------------------------
String.prototype.trim = function() {
return this.replace(/(^\s+|(\s+$))/g,'');
}
//decode email address ------------------------------------------------------------------
function decodeEA(ea){
elink = 'mailto:' + reversestring(ea);
window.location=elink;
}

//reverse string ------------------------------------------------------------------------
function reversestring(s){
splitext = s.split("");
revertext = splitext.reverse();
reversed = revertext.join("");
return reversed;
}

//set cookie ----------------------------------------------------------------------------
function setCookie(c_name,value,expiredays){
  var exdate=new Date();exdate.setDate(exdate.getDate() + expiredays);
  document.cookie=c_name+ "=" +escape(value) + ((expiredays==undefined) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";
}

//get cookie ----------------------------------------------------------------------------
function getCookie(c_name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1){ 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}
//calcHeight ---------------------------------------------------------------------------
function calcHeight(elem){
    try{
	    if( elem.contentWindow && elem.contentWindow.document){
		    a=elem.contentWindow.document.body;
		    the_height=a.scrollHeight;
		    elem.style.height=(the_height) + 'px';
		}
	}
	catch(e){}
}
//------------------------------------------------------------------------------------------------------------ajax 
var xmlhttp

function getXMLHttpObject(){
  if (window.XMLHttpRequest){
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject){
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}      

function ajaxgetVar(v){
  xmlhttp = getXMLHttpObject();
  if (xmlhttp==null){
    alert('No support for Ajax')
    return;
  }
  
  var url='/assets/ajaxgetVar.asp?v=' + v;

  xmlhttp.open('GET',url,false);
  xmlhttp.send(null);
  return( String(xmlhttp.responseText));
}

function ajax(url,target){
  xmlhttp = getXMLHttpObject();
  if (xmlhttp==null){
    alert('No support for Ajax')
    return;
  }
  
  xmlhttp.open('GET',url,false);
  xmlhttp.send(null);
  document.getElementById(target).innerHTML=String(xmlhttp.responseText);
}

//------------------------------------------------------------------------------------------------------------validation
var reAN   = /^[\w ]*$/i                                   //alphanumeric characters 
var reANX  = /^[\w &$'_\-\?]*$/i                           //alphanumeric characters + ampersand + dollar + single quote + underscore + minus sign + question mark
var reINT  = /^\d*$/                                       //integers only
var reDATE = /^(()|(\d{1,2}(\/|-)\d{1,2}(\/|-)\d{2,4}))$/  //date format
var reMENU = /^\d*.?\d{0,2}$/i                             //menu format
  
function validateAN(e){  
 	if (e.value == 'null' || e.value.length==0 || !reAN.test(e.value)){ 
		return false;
  	}
  	return true;   
}	 
function validateANX(e){  
 	if (e.value == 'null' || e.value.length==0 || !reANX.test(e.value)){ 
		return false;
  	}   
  	return true;
}	 	 
function validateINT(e){
    if (e.value == 'null' || e.value.length==0 || !reINT.test(e.value)){   
		return false;
  	}  
  	return true;  
}
function validateDATE(e){
    if (e.value == 'null' || e.value.length==0 || !reDATE.test(e.value)){   
		return false;
  	}
  	return true;    
}
function validateMENU(e){
    if (e.value == 'null' || e.value.length==0 || !reMENU.test(e.value)){   
		return false;
  	}
  	return true;    
}
function validateField(fieldID,validationType,errorMessage){
	var RC = true;
	var e = document.getElementById(fieldID); 
	switch (validationType){
		case 'AN':  
			RC = validateAN(e)
			break;
		case 'ANX':
			RC = validateANX(e)
			break;		
		case 'INT':
			RC = validateINT(e)
			break;	
		case 'DATE':
			RC = validateDATE(e)
			break;	
		case 'MENU':
			RC = validateMENU(e)
			break;										
	}
	if (!RC){
		alert(errorMessage);
    	e.focus(); 
    	return false; 
	} 
	return true;   	   
}
function purplesquarecontent(PageID,PanelID,ContentID){
    var onClickPhrase = ' onclick="fbIframe(\'/poitin/contenteditor.asp?pageid=' + PageID + '\&panelid=' + PanelID + '\&contentid=' + ContentID + '\')"'
    var stylePhrase   = ' style="position:absolute;width:10px;height:10px;right:0px;top:0px;background-color:navy;z-index:1000;cursor:pointer"'
	$('<div id=\"' + PanelID + '_\" class=\"purplesquare\" title=\"edit article\" ' + stylePhrase + onClickPhrase + '><div>').appendTo($('#' + PanelID).parent())
	var pos = $('#' + PanelID).position();
	$('#' + PanelID + '_').css({'top':pos.top + 'px', 'left': ($('#' + PanelID).width() - 10 + pos.left) + 'px'})
}
