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){}
}  
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);
}
