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 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 count;
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;

	for (count = 0; count < el.length; count++) {
		if (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.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.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.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.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;
}

/* popup functions: show/hide popup layer */

function popImage(link) {
	popOpen('imagePop'); // open popup
	smlSrc = link.firstChild.src; // get small image src
	imgType = smlSrc.substring((smlSrc.length-3), smlSrc.length); // get type (gif, jpg, etc)
	imgPath = smlSrc.substring(0, (smlSrc.length-4)); // get path
	newSrc = imgPath+"_lrg."+imgType; // create new url to lrg image
	imgObj = "<img src='"+newSrc+"' />";
	header = link.title;
	document.getElementById('image_area').innerHTML = imgObj; 
	document.getElementById('image_head').innerHTML = header; 
}

function popText(link, width, height)
{
    popOpen('textPop');
    
    txtObj = "<iframe src='"+link+"' width='"+width+"' height='"+height+"' frameborder='0' scrolling='auto' />";    
    document.getElementById('text_area').innerHTML = txtObj;
    
    document.getElementById('content').style.width = width + 'px';
    document.getElementById('content').style.height = (height + 31) + 'px';
}


function popOpen(id) {
	var topOffset = 60;
	setSize(topOffset);
	var overShade = document.getElementById(id);
	var topPad =  pos+topOffset;
	// height-padding = div height
	overShade.style.height = (ph - topPad) + 'px'; /* remove topPad from height */
	overShade.style.width = pw + 'px';
	overShade.style.paddingTop = topPad + 'px';
	overShade.style.display = 'block';
	if (document.all && !navigator.appVersion.match(/MSIE 7.0/)) {
		coverSelects(overShade);
	}
}
function popClose(id) {
	document.getElementById(id).style.display = "";
	if (document.all && !navigator.appVersion.match(/MSIE 7.0/)) {
		document.getElementById("popup-cover").outerHTML = "";
	}
		
}
function setSize(topOffset) { /* sets size of shade */
	if (window.pageYOffset != null) { /* moz and safari */
		pos = window.pageYOffset;
		ph = document.documentElement.scrollHeight;
		pw = document.documentElement.scrollWidth;
		if (document.body.scrollHeight > document.documentElement.scrollHeight) {
			ph = document.body.scrollHeight;
			pw = document.body.scrollWidth;
		}
	} else if (document.documentElement.scrollTop > document.body.scrollTop) { /* ie, catch if Standards compliance mode */
		pos = document.documentElement.scrollTop;
		ph = document.documentElement.scrollHeight;
		pw = document.documentElement.scrollWidth;
		if (document.documentElement.clientHeight > document.documentElement.scrollHeight) {
			ph = document.documentElement.clientHeight;
		}
	} else if (document.body != null) { /* if IE 5.5 */
		pos = document.body.scrollTop;
		ph = document.body.scrollHeight;
		pw = document.body.scrollWidth;
		if (document.documentElement.scrollHeight > document.body.scrollHeight) {
			ph = document.documentElement.scrollHeight;
		}
		ph = ph + pos + topOffset; /* fix box model */
	}
}	

/* covers select form elements with iframe in IE 6&< so they do not show through the popup */
function coverSelects(par) {
		var covHeight = document.body.scrollHeight+"px"; // add the negative margin to the height
		var coverFrame = "<IFRAME id='popup-cover' style='";
		coverFrame = coverFrame + "height:"+covHeight+";' ";
		coverFrame = coverFrame + "src='javascript:false;' frameBorder='0' scrolling='no'></IFRAME>";
		par.insertAdjacentHTML("afterEnd",coverFrame); // create new iframe that is the size of the popup window
}
