﻿/************* JavaScript By Brankov ******************/
/*var ws = screen.availWidth;
var hs = screen.availHeight;
var wd = document.body.width;
var hd = document.body.height;
var ww = window.availWidth;
var hw = window.availHeight;*/


/*********************** popUp ***************************/

function show_popup(picName, topImg)
{
	var p=window.createPopup();
	var pbody=p.document.body;
	pbody.style.backgroundColor="white";
	pbody.style.border="solid #aaaaaa 1px";
	pbody.innerHTML ='<center><h2>'+picName+'</h2></center>';
	pbody.innerHTML+='<br>';
	pbody.innerHTML+='<center><img src="../images/contstructionlogo.gif" name="'+picName+'" width="300" border="0" id="'+picName+'"></center>';
	pbody.innerHTML+='<br>';
	//pbody.innerHTML+='<a href="javascript: close();">close</a>';
	pbody.innerHTML+='<br>' + topImg + 'px';
	p.show(400,300 + topImg,320,370,document.body);
}

function open_win_pic(picID)
{
param = '/gallery/pic_viewer.php?picID='+picID;
window.open(param,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=580, height=450")
}

function resizeWindow()
{
top.resizeTo(500,300);
}

function open_win(idArticle, idMenu, idLang)
{
param = 'article_viewer.php?idArticle='+idArticle+'&idMenu='+idMenu+'&idLang='+idLang;
window.open(param,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=620, height=600")
}

function open_win_alert(url)
{
window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=620, height=450")
}


function deleteRecord(theLink, table)
{
	confirmation = window.confirm('Neao?ie ee noa, ?a eneaoa aa eco?eaoa oice caien?');
    if (confirmation) {
        theLink.href += '&del_is_js_confirmed=1&table='+table;
    }
}

function changeSource(src)
	{
		src = src+document.getElementById('sourceLang').value+"#form";
		//window.alert(src);
		window.open(src,"_top");
		//document.getElementById('menu_form').submit();
	}

function closeWindowTimeOut(timeInterval)
	{
		timeInterval = timeInterval*1000;
		setTimeout('window.close()', timeInterval);
	}

function goBackWindowTimeOut(timeInterval)
	{
		timeInterval = timeInterval*1000;
		setTimeout('window.history.back()', timeInterval);
	}
	
function returnValue(value, target)
	{
		var inputField = window.opener.document.getElementById(target).getElementsByTagName('input')[0];
		if (inputField)
		 inputField.value = value;
		window.close();
		/*
		<input id="ez_depLoc" type="text" style="width: 220px;" size="31" onfocus="if(this.value=='Flying from')this.value='';this.select();" onblur="document.cookie='depLoc='+this.value;if(this.value=='')this.value='Flying from';" name="ez$depLoc"/>
<br/>
<small>
<a id="depLookup" class="lookup" target="_blank" onclick="return openWindow('http://www.lessno.com/modals/airportlookup.aspx?target=auto', 'lookup')" href="http://www.lessno.com/modals/airportlookup.aspx">Airport lookup</a>
</small>*/
   }
	
function refreshReport(form)
	 {
	  document.getElementById(form).submit();  
	 }
	 
function refreshReportOpener(form)
	 {
	  opener.document.getElementById(form).submit();  
	 }
	
function refreshSearch(url) //kiwi http://localhost:10085/orders_report.php
	{
		window.location.href = url;
	}
	
	
function getWindowSize()
{
	
}
	
	
function centerPopupWindow()
	{
	var ws = screen.availWidth;
	var hs = screen.availHeight;
	var wd = document.body.width;
	var hd = document.body.height;
	var ww = window.availWidth;
	var hw = window.availHeight;
	
		if (window.navigator.appName != "Microsoft Internet Explorer")
			{
				//wiw = document.getElementById('site').offsetWidth;
				//hiw = document.getElementById('site').offsetHeight;
				wiw = window.innerWidth;
				hiw = window.innerHeight;
			}
		else
			{
				wiw = document.getElementById('site').offsetWidth;
				hiw = document.getElementById('site').offsetHeight;
			}
	
	window.moveTo((ws-wiw)/2,(hs-hiw)/2);
	window.focus();
	//window.alert (ws+' '+hs+' '+wd+' '+hd+' '+ww+' '+hw+' '+wiw+' '+hiw+window.navigator.appName);
	}
	
function centerDiv(divName)
	{
		if (document.getElementById(divName))
			{
				ws = screen.availWidth;
				hs = screen.availHeight;
				wd = document.body.width;
				hd = document.body.height;
				ww = window.availWidth;
				hw = 400;//window.availHeight;
				
				wdiv = 240;//document.getElementById('alert').width;
				hdiv = 180;//document.getElementById('alert').height;
				
					if (window.navigator.appName != "Microsoft Internet Explorer")
						{
							//wiw = document.getElementById('site').offsetWidth;
							//hiw = document.getElementById('site').offsetHeight;
							wiw = window.innerWidth;
							hiw = window.innerHeight;
						}
					else
						{
							wiw = document.getElementById('site').offsetWidth;
							hiw = document.getElementById('site').offsetHeight;
						}
						
						dLeft = Math.round(((wiw-wdiv)/2));
						dTop = Math.round(((hw-hdiv)/2));
				
				document.getElementById(divName).style.left = dLeft+'px';
				document.getElementById(divName).style.top = dTop+'px';
				//window.alert(document.getElementById(divName).style.top+' - '+wdiv+' - '+document.getElementById(divName).style.left+' - '+hdiv+' '+divName+' - '+dLeft+' - '+dTop+' end');
				//window.alert (ws+' '+hs+' '+wd+' '+hd+' '+ww+' '+hw+' '+wiw+' '+hiw+window.navigator.appName);
			}
	}
	
	 
	
function closeDiv(divName)
{
	if (document.getElementById(divName))
		{
			document.getElementById(divName).style.visibility="hidden";
		}
}
	
//Потвърждение за изтриване на фаза от дървото
function deleteConfirm(form, msg)
{
	if (confirm(msg)) {
		refreshReport(form);
	}
}//deleteConfirm

//Рестрикции при въвеждане на стойности в поле (Само: Int, Decimal)
function IsMatch(id, alertMsg)
{
	mystring = document.getElementById(id).value; 
	if (mystring == "") return true;
    if (!mystring.match(/^\d+$|^\d+\.\d+$/ ) )
    {
        alert(alertMsg);
		document.getElementById(id).value = "";
		document.getElementById(id).focus();
		document.getElementById(id).select();
			
		return false;
    }
	return true;
}//IsMatch
//Проверява дали е въведена стойност в поле
function IsEntered(id, alertMsg)
{
	mystring = document.getElementById(id).value; 
	if (mystring == "") 
	{
		alert(alertMsg);
		return false;
	}//if
	
	return true;	
}//IsEntered

//Премества скролът на позициите подадени като параметри.
function scrollToCoordinates(x, y) 
{
	var x = (x == null) ? 0 : x;
	var y = (y == null) ? 0 : y;
	window.scrollTo(x, y);
}//scrollToCoordinates

//Запазва координатите на скрола за да може при събмит да се обнови страницата на същото място.
function saveScrollCoordinates(id) 
{
	document.getElementById(id).scrollx.value = (document.all)?document.body.scrollLeft:window.pageXOffset;
	document.getElementById(id).scrolly.value = (document.all)?document.body.scrollTop:window.pageYOffset;
}//saveScrollCoordinates

//Проверка в полето да е въведен файл с определено разширение
function checkFileExtension( parafilevalue, fileType )
{
	var file = parafilevalue.split('.');
	var validType = false;
	
	if( file.length < 2 )
	{
		return false;
	}
	
	var fileext = file[1].toLowerCase();
	if( fileext ==  fileType) 
	{
	   validType = true;
	}  
	
	return validType;
}//checkFileExtension

function validateFileExtns(id, alertMsg, fileType)
{
	fileName = document.getElementById(id).value; 
	if (fileName == "") return true;
	if( ! checkFileExtension(fileName, fileType))
	{
		alert(alertMsg);
		document.getElementById(id).value = "";
		document.getElementById(id).select();
		return false;
	}
	return true;	
}//validateFileExtns


//Селектира всички checkbox-ове или ги деселектира.
function attachClickEvent(id)
{
	var checkboxArr = document.getElementById(id).getElementsByTagName("input");
	
	for (i=0; i<checkboxArr.length; i++)
	{
	if (checkboxArr[i].type == "checkbox")
	{
	checkboxArr[i].onclick = function()
	{
	checkUncheckAll(this, id);
	};
	}
	}
}

function checkUncheckAll(obj, id)
{
	var checkboxArr = document.getElementById(id).getElementsByTagName("input");
	var numCheckboxes = 0;
	var numChecked = 0;
	
	for (i=1; i<checkboxArr.length; i++)
	{
		if (checkboxArr[i].type == "checkbox")
		numCheckboxes++;
	}
	
	if (obj.value == "all")
	{
		for (i=0; i<checkboxArr.length; i++)
		{
			if (checkboxArr[i].type == "checkbox" && obj.checked == true && checkboxArr[i].disabled == false)
				checkboxArr[i].checked = true;
			else
				checkboxArr[i].checked = false;
		}
	}
	else
	{
		if (obj.checked == false)
		{
			checkboxArr[0].checked = false;
		}
		else
		{
			for (i=1; i<checkboxArr.length; i++)
			{
				if (checkboxArr[i].type == "checkbox" && checkboxArr[i].checked == true && checkboxArr[i].disabled == false)
					numChecked++;
			}
	
			if (numChecked == numCheckboxes)
				checkboxArr[0].checked = true;
		}
	}
}