function setClass(obj, cl){
	if (obj.className!=cl) obj.className = cl;
}

function setClassById(objid, cl){
	if (!cl) cl = '';
	document.getElementById(objid).className = cl;
}

function changeDisplayById(objId){
	for (c = 0; c < changeDisplayById.arguments.length; c++){
		obj = document.getElementById(changeDisplayById.arguments[c]);
		if (obj.style.display == 'none') obj.style.display = 'block';
		else obj.style.display = 'none';
	}
}

function gotoURL(url){
	if (!url) url = "/";
	if (window.event){
		var src = window.event.srcElement;
		if((src.tagName != 'A') && ((src.tagName != 'IMG') || (src.parentElement.tagName != 'A'))){
			if (window.event.shiftKey) window.open(url);
			else document.location = url;
		}
	} else document.location = url;
}

function popupURL(url){
	window.open(url);
}

function getLeftPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return res;
}

function getTopPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return res;
}

function chbCheckAll(formObj, checkName, checkVal){
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]')
			if (!el[count].disabled) el[count].checked = checkVal;
}

function chbExamAll(formObj, checkName, resName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	formObj.elements[resName].checked = (checkCount == boxCount);
}

function chbIsAllEmpty(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	return(checkCount == 0);
}

function chbIsOnlyOne(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++){
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	return(checkCount == 1);
}

function disableAll(){
	for (c1 = 0; c1 < document.forms.length;  c1++){
		var formElements = document.forms[c1].elements;
		for (c2 = 0; c2 < formElements.length;  c2++) formElements[c2].disabled = true;
	}
}

function showPopup(url){
  var printWin = window.open(url, '', 'width=488, height=530, scrollbars=no, resizable=no');
}


var mainImg;
var newImg;
var emptyImage;
var oc;
var localTimer;
var newHeight;
var newWidth;
var resizerCount = 0;

function reloadImage(path, mainImageId)
{  
  resizerCount = 0;
  mainImg = document.getElementById(mainImageId);
  mainImg.style.filter="Alpha(opacity=100, finishopacity=0, style=0)";
  window.clearTimeout(localTimer);
  if (mainImg.src != path)
  {
    newImg = new Image();
    newImg.src = path;
        
    oc = 100;
	fadeOut();
  }
}

function fadeIn() {	    
  mainImg.style.filter="Alpha(opacity="+oc+", finishopacity=0, style=0)";
  if(oc!=100) localTimer =  window.setTimeout('(oc += 4);fadeIn()',10);      
}

function setSize()
{
  if(isNaN(newImg.width) || isNaN(newImg.height) || newImg.width == 0 || newImg.height == 0)
  {
    if(resizerCount > 100)
        return;
    resizerCount++;
    setTimeout('setSize()', 50);
    return;
  }
  newHeight = 365;
  if(navigator.appName.indexOf("Internet Explorer") == -1)
  {
    newWidth = newImg.width * 365 / newImg.height;
    mainImg.width = newWidth;
  }
  mainImg.height = newHeight;
  setTimeout('mainImg.src = newImg.src; fadeIn();', 50);  
}

function fadeOut() {
  mainImg.style.filter="Alpha(opacity="+oc+", finishopacity=0, style=0)";
  if(oc!=0)
    localTimer =  window.setTimeout('(oc -= 4);fadeOut()',10);
  else 
  {		 
//    setSize();                        	 

	 mainImg.width = newImg.width;
	 mainImg.height = newImg.height;	 

     mainImg.src = newImg.src;          
	 
	 	
     fadeIn();
  }
}

function preLoad() 
{
 	if(document.images)
 	{
 	    var argLen = arguments.length; 		
 	    for(var i = 0; i < argLen; i++) 
 	    { 			
 	        var arg = arguments[i]; 			
 	        self[arg] = new Image(); 			
 	        self[arg].src = arg; 		
 	    } 	
 	} 
}
