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 = '';
	}
}

// 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 setClass(obj, cl) {
	if (obj.className!=cl) obj.className = cl;
}

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 = imgSrc[c];
		}
	}
}

function setImgSrc(idVal, srcVal)
{
	if (document.images) document.images[idVal].src = srcVal;
}

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 cblCheckOthers(formObj, thisEl, namePrep)
{
	var i;
	var el = formObj.elements;

	for (i = 0; i < el.length; i++) {
		if (el[i].id!=thisEl.id && el[i].id.indexOf(namePrep)>=0) {
			if (!el[i].disabled) el[i].checked = thisEl.checked;
		}
	}
}

function cblCheckMain(formObj, mainId, namePrep)
{
	var i;
	var boxCount = 0;
	var checkCount = 0;
	var el = formObj.elements;

	for (i = 0; i < el.length; i++) {
		if (el[i].id.indexOf(mainId)<0 && el[i].id.indexOf(namePrep)>=0) {
			boxCount++;
			if (el[i].checked || el[i].disabled) checkCount++;
		}
	}

	for (i = 0; i < el.length; i++) {
		if (el[i].id.indexOf(mainId)>=0) {
			el[i].checked = (checkCount == boxCount);
			break;
		}
	}
}

function chbCheckAll(formObj, checkName, checkVal)
{
	var count;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++) {
		if (el[count].name && el[count].name.indexOf(checkName) != -1) {
			if (!el[count].disabled) el[count].checked = checkVal;
		}
	}
}

function chbExamAll(formObj, checkName, resName)
{
	var count;
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;

	for (count = 0; count < el.length; count++) {
		if (el[count].name && el[count].name.indexOf(checkName) != -1) {
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	}

	for (count = 0; count < el.length; count++) {
		if (el[count].name && el[count].name.indexOf(resName) != -1) {
			el[count].checked = (checkCount == boxCount);
			break;
		}
	}
}

function chbIsAtLeastOne(formObj, checkAllName, checkName)
{
	var count;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++) {
		if (el[count].name && (el[count].name.indexOf(checkAllName)!=-1 || el[count].name.indexOf(checkName)!=-1)) {
			if (el[count].checked) return true;
		}
	}
	return false;
}

function chbIsAllEmpty(formObj, checkName)
{
	var count;
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;

	for (count = 0; count < el.length; count++) {
		if (el[count].name && el[count].name.indexOf(checkName) != -1) {
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	return (checkCount == 0);
}

function chbIsOnlyOne(formObj, checkName)
{
	var count;
	var checkCount = 0;
	var el = formObj.elements;

	for (count = 0; count < el.length; count++) {
		if (el[count].name && el[count].name.indexOf(checkName) != -1) {
			if (el[count].checked) checkCount++;
		}
	}
	return (checkCount == 1);
}

function disableAll()
{
	var c1, c2;

	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=640, height=480, scrollbars=no');
}

function chahgeVisibility(objName)
{
	var el = document.getElementById(objName).style;
	el.display = (el.display=="block" ? "none" : "block");
}

function setVisibilityOn(objName)
{
	var el = document.getElementById(objName).style;
	el.display = "block";
}

function changeVisibilityAll(objsName, vis)
{
	var i;
	var els = document.getElementsByTagName("div");
	for (i = 0; i < els.length; i++) {
		if (els[i].id.indexOf(objsName) != -1) els[i].style.display = vis;
	}
}

function closePopupDiv(divID, shadID, ifrID)
{
	document.getElementById(shadID).style.display='none';
	document.getElementById(divID).style.display='none';
	document.getElementById(ifrID).src='';
}

var curr_divID = null;
var curr_shadID = null;
var curr_ifrID = null;

function closeCurrentPopupDiv()
{
	if (curr_divID==null || curr_shadID==null || curr_ifrID==null) return;

	closePopupDiv(curr_divID, curr_shadID, curr_ifrID);

	curr_divID = null;
	curr_shadID = null;
	curr_ifrID = null;
}

function openPopupRebindParams(divID, ifrID, param1, param2)
{
	if (document.getElementById(divID).style.display != 'block') return;

	if (typeof(document.getElementById(ifrID).contentWindow.process)!='undefined') {
		document.getElementById(ifrID).contentWindow.process(window, param1, param2);
	}
	window.setTimeout("openPopupRebindParams('"+divID+"','"+ifrID+"','"+param1+"','"+param2+"')", 100);
}

function openPopupDivCallFunc(divID, ifrID, ttlID, title, count, param1, param2)
{
	if (document.getElementById(divID).style.display != 'block') return;

	var i, str = "Loading ";
	for (i = 0; i < count; i++) str += ".";
	document.getElementById(ttlID).innerHTML = str;

	if (typeof(document.getElementById(ifrID).contentWindow.process)=='undefined')
	{
		count++;
		if (count > 5) count = 1;
		window.setTimeout("openPopupDivCallFunc('"+divID+"','"+ifrID+"','"+ttlID+"','"+title+"','"+count+"','"+param1+"','"+param2+"')", 100);
		return;
	}

	document.getElementById(ttlID).className = 'fat';
	document.getElementById(ttlID).innerHTML = title;
	document.getElementById(ifrID).contentWindow.process(window, param1, param2);
	window.setTimeout("openPopupRebindParams('"+divID+"','"+ifrID+"','"+param1+"','"+param2+"')", 100);
}

function openPopupDiv(divID, width, height, title, src, param1, param2)
{
	var left, top, shad;
	var div = document.getElementById(divID);

	div.style.zIndex = 150;
	div.style.position = 'absolute';
	div.style.top = '10px';
	div.style.left = '10px';
	div.style.backgroundColor = '#FFFFFF';
	div.style.border = '1px solid #000';
	div.style.width = width+'px';
	div.style.height = height+'px';

	var shadID = divID+'_shaddow';
	var ifrID = divID+'_iframe';
	var ttlID = divID+'_title';

	if (typeof(document.getElementById(shadID))=='undefined' || document.getElementById(shadID)==null)
	{
		shad = document.createElement('DIV');
		shad.id = shadID;
		shad.style.zIndex = 140;
		shad.style.position = 'absolute';
		shad.style.display = 'none';
		shad.style.width = width+'px';
		shad.style.height = height+'px';
		shad.style.backgroundColor = '#888';
		shad.innerHtml = '&nbsp;';
		div.parentNode.insertBefore(shad, div);
	}
	else shad = document.getElementById(shadID);

	var html = '<table cellpadding="0" cellspacing="0" style="height:100%;width:100%;">';
	html += '<tr style="background-color:#D0D9E6;">';
	html += '<td class="acc" style="padding:4px 0px 4px 8px;border-bottom:1px solid #000;width:100%" id="'+ttlID+'">';
	html += '</td><td align="right" style="padding:4px 8px 4px 0px;border-bottom:1px solid #000;">';
	html += '<a href="#" class="fat" onclick="closePopupDiv(\''+divID+'\',\''+shadID+'\',\''+ifrID+'\');return false;">';
	html += 'Close';
	html += '</a></td></tr><tr>';
	html += '<td colspan="2" style="height:100%;padding:0px 0px 0px 0px;">';
	html += '<iframe id="'+ifrID+'" src="'+src+'" style="width:100%;height:100%;border:none;"></iframe>';
	html += '</td></tr></table>';

	div.innerHTML = html;
	div.style.display = 'block';

	if (document.all)
	{
		left = (document.body.clientWidth - div.offsetWidth) / 2;
		top = (document.body.clientHeight - div.offsetHeight) / 2;
	}
	else
	{
		left = (window.innerWidth - div.offsetWidth) / 2;
		top = (window.innerHeight - div.offsetHeight) / 2;
	}

	div.style.left = left+'px';
	div.style.top = top+'px';

	shad.style.display = 'block';
	shad.style.left = (left+4)+'px';
	shad.style.top = (top+4)+'px';

	curr_divID = divID;
	curr_shadID = shadID;
	curr_ifrID = ifrID;

	window.setTimeout("openPopupDivCallFunc('"+divID+"','"+ifrID+"','"+ttlID+"','"+title+"','1','"+param1+"','"+param2+"')", 100);
}

// this function work's fine, only if one form is in document
function getElementByPartID(elID)
{
	var i;
	var formObj = document.forms[0];
	var el = formObj.elements;

	for (i = 0; i < el.length; i++) {
		if (el[i].name.indexOf(elID) != -1) return el[i];
	}

	return null;
}
