function hideInfoCrearForm(m_message,m_email) {
	if ( document.getElementById('info') ) {
		document.forms['quick_form'].elements.q_message.value 	= m_message;
		document.forms['quick_form'].elements.q_email.value 	= m_email;
		document.getElementById('info').style.display 			= "none";
	}
}

function makeGray (obj, state, text){
	if (state && (obj.value == '')){
		obj.value = text;
	} else if (!state && (obj.value == text)){
		obj.value = '';
	}
}


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, target, callback){
  
	if (!url) url = "/";

	if(typeof callback == "function")
		callback(url);

	if(target && target!='_self'){
		popupURL(url, target);
	}
	else{
		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, target){
	window.open(url, target);
}

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 CheckAll(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 ExamAll(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 CheckAll(checkName, checkVal)
{
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{	  
		if (el[count].name == checkName)
		{
			if (!el[count].disabled)
			{
				el[count].checked = checkVal;
			}
			checkCount++;
		}
	}
}

function ExamAll(checkName, resName)
{
	var checkCount = 0;
	var boxCount = 0;
	var el = document.forms[0].elements;
	
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name == checkName)
		{
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	}
	
	if (document.forms[0].elements[resName])
		document.forms[0].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;
	}
}

// name - cookie name
// value - cookie value
// [expires] - Date object (by default cookie expires at the end of browser session)
// [path]
// [domain]
// [secure]
function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")

	if ( (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
}

// name - cookie name
function getCookie(name)
{
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

// name - cookie name
// [path]
// [domain]
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name+"="+
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}


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;
		}
	}
}

function ch_img(obj, img ) {
	if (self[img]) {
		obj.src = self[img].src;
	}
}

function mm_act(obj,img,cl,num,selected){
	
	if ( cl == 'item act' )
		showMenu(obj, num);
	else
		hideMenu(obj, num);
	
	if ( selected ) return;
	
	while (obj) {
		obj = obj.childNodes[0];
		if ( obj && obj.tagName == 'IMG') {
			ch_img(obj,img);
			break;
		}
	}
	
	while (obj && cl!='') {
		obj = obj.parentNode;
		if ( obj && obj.tagName == 'DIV') {
			obj.className = cl;
			break;
		}
	}
}

function popup_view (url, w, h, wname) {
	scr_left = 0;
	scr_top = 0;
	wname = wname;
	new_window = window.open (url, wname , "title=image,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width="+w+",height="+h+",top="+scr_top+",left="+scr_left);
	new_window.focus();
	return new_window;
}

function LTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;
    s = s.substring(j, i);
  }

  return s;
}

function RTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

    var i = s.length - 1;      
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
    s = s.substring(0, i+1);
  }

  return s;
}

function Trim(str)
{
  return RTrim(LTrim(str));
}

function headerKeydown(Url, Header)
{
    var reg = /[\x21-\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5e\x60\x7b\x7d\xa3]/ig;
    var regAnd = /&/ig;
    var regS = /[\s\x2f]/ig;

    var val = Trim(Header.value.toLowerCase()).replace(reg,"").replace(regAnd,"and").replace(regS,"-").replace(/\x2D{2,}/ig,'-');
    Url.value = (val.length > 0) ? val + ".aspx" : "";
}

function checkSelection(checkName) {
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{	  
		if (el[count].name == checkName)
		{
			if (!el[count].disabled)
			{
				if (el[count].checked) {
			    checkCount++;				  
				}
			}
		}
	}
	if (checkCount == 0) {
	  alert('You must check any item!');
	  return false;
	}
	return true;
}

function deleteConfirmation(checkName) {
  if (!checkSelection(checkName)) {
    return false;
  }
  if (!confirm('You are trying to delete item(s). \n\nAre you sure you wish to continue?')) {
    return false;
  }
  else {
    return true;
  }
}

var checkedCount = 0;

function updateCheckedCount(checkBox) {
  if (checkBox.checked) {
    checkedCount += 1;
  }
  else {
    checkedCount -= 1;  
  }
}

function deleteFromTreeConfirmation() {
  if (checkedCount <= 0) {
    alert('You must check any item!');  
    return false;
  }
  if (!confirm('You are trying to delete item(s). \n\nAre you sure you wish to continue?')) {
    return false;
  }
  else {
    return true;
  }
}

function checkedChanged(id, list)
{
    if (typeof list[id] != "undefined" && list[id].checked)
    {
        for (var i=0; i<list.length; ++i)
        {
            if (i != id)
            {
                list[i].checked = false;
            }
        }
    }
}
