var winIE = (navigator.userAgent.indexOf("Opera")==-1 && (document.getElementById && document.documentElement.behaviorUrns))  ? true : false;

function pop_win(href,w,h) {
   window.open(href,"pop_win","width="+w+", height="+h+", screenx=100, screeny=50 toolbar=no, status=no, menubar=no, scrollbars=yes");
}

function freeze(elementId) {
   document.getElementById(elementId).disabled = "true";
}

function helper(field_name){
   var formObj = document.getElementById(field_name+'_helper');
   if(formObj.style.visibility == 'visible'){
      formObj.style.visibility = 'hidden';
      formObj.style.display = 'none';
   }
   else{
      formObj.style.visibility = 'visible';
      formObj.style.display = 'block';
   }
}

function countChars(element,max_length,counter_name,field_label) {
   var checker_button = '';
   if( element.value.length > max_length ) {
      element.focus();
   }
   if(element.value.length > max_length)
   document.getElementById(counter_name).style.color = 'red';
   else
      document.getElementById(counter_name).style.color = '#333333';
   document.getElementById(counter_name).innerHTML = element.value.length+checker_button;
}

/* window 'load' attachment */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function bodySize() {
  var width = getBrowserWidth();
  if (width == 0) return;
  sObj = document.getElementById("min-width").style;
  sObj.width = (width<950) ? "950px" : "100%";
}

function getBrowserWidth() {
  if (window.innerWidth) {
    return window.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth != 0) {
    return document.documentElement.clientWidth;
  }
  else if (document.body) {
    return document.body.clientWidth;
  }
  return 0;
};

if(winIE) {
  addLoadEvent(bodySize);
  onresize = bodySize;
}
