function setClass(obj, cl){
  if (!cl) cl = "";  
  obj.className = cl;
}

function setClassById(objid, cl){
  obj = document.getElementById(objid);
  setClass(obj, 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 CssClass(elementId, CssClass){
    document.getElementById(elementId).className = CssClass;
}

function HideElement(elementId){
    document.getElementById(elementId).style.display = 'none';
}

function ShowElement(elementId){
    document.getElementById(elementId).style.display = '';
}

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 trim(str){
  var re = /^ */;
  var res = str.replace(re, '');
  re = / *$/;
  return(res.replace(re, ''));
}

function isValidEmail(mailstr){
  var re = /^ *([a-z0-9_-]+\.)*[a-z0-9_-]+@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) *$/;
  return (re.test(mailstr.toLowerCase()));
}

function getTopPos(obj){
  var res = 0;
  while (obj){
    res += obj.offsetTop;    
    obj = obj.offsetParent;
  }
  return res;
}

function preloadImg(){
	if (document.images){
		var imgSrc = preloadImg.arguments;
		imgArray = new Array(imgSrc.length);
		for (var c = 0; c < imgSrc.length; c++){
			imgArray[c] = new Image();
			imgArray[c].src = "/images/" + imgSrc[c];
		}
  }
}

function setImgSrc(idVal, srcVal){
  if (document.images) document.images[idVal].src = "/images/"+ srcVal;
}

function showImg(name){
  var printWin = window.open('/images/shots/' + name,'','width=600, height=400, scrollbars=yes, resizable=yes');
}

function showPhoto(name){
  var printWin = window.open(name,'','width=840, height=630, scrollbars=yes, resizable=yes');
}

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 openStatistic(summaryContainerId,detaildContainerId){
	document.getElementById(summaryContainerId).style.display = 'none';
	var expires = new Date();
    expires.setTime(expires.getTime() + 24*60*60*1000)
    setCookie('property-statistic-visible', '1', expires);
    deleteCookie('call-statistic-visible', '', '');
	document.getElementById(detaildContainerId).style.display = '';
}
function closeStatistic(summaryContainerId,detaildContainerId){
	document.getElementById(detaildContainerId).style.display = 'none';
	deleteCookie('property-statistic-visible','','');
	document.getElementById(summaryContainerId).style.display = '';
}
function openCallStatistic(summaryContainerId, detaildContainerId) {
    document.getElementById(summaryContainerId).style.display = 'none';
    var expires = new Date();
    expires.setTime(expires.getTime() + 24 * 60 * 60 * 1000)
    setCookie('call-statistic-visible', '1', expires);
    deleteCookie('property-statistic-visible', '', '');
    document.getElementById(detaildContainerId).style.display = '';
}
function closeCallStatistic(summaryContainerId, detaildContainerId) {
    document.getElementById(detaildContainerId).style.display = 'none';
    deleteCookie('call-statistic-visible', '', '');
    document.getElementById(summaryContainerId).style.display = '';
}