////////////// CALCULATOR /////////////////////////////////////////////////////
function ResetFields(){
	var oFromDate = document.getElementById("FromDate");
	var oToDate = document.getElementById("ToDate");
	var oShare = document.getElementById("Share");

	oFromDate.value = "";
	oToDate.value = "";
	oShare.value="";
}

function Calculate(){
	var oDohodnost = document.getElementById('Dohodnost');
	oDohodnost.style.color = "#CCCCCC";
}

function SetDate(sInputName, nDay, nMonth, nYear, nLangID){
    switch(nLangID){
        case 1:
            arMonths = new Array("Януари", "Февруари", "Март", "Април", "Май", "Юни", "Юли", "Август", "Септември", "Октомври", "Ноември", "Декември");
            break;
        case 2:
            arMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
            break;
    }
	var oDate = window.parent.document.getElementById(sInputName);
	//
	var oNextElement = window.parent.document.getElementById(sInputName+"Value");
	if(oNextElement)
	    if(oNextElement.type == "hidden")
	        oNextElement.value = nYear + "-" + nMonth + "-" + nDay;
	oDate.value = nDay + " " + arMonths[nMonth-1] + " " + nYear;
	ToggleCalendar(sInputName, true);
}

function ToggleCalendar(sInputName, parent){

    if(parent)
	    var CalendarLayer = window.parent.document.getElementById(sInputName +"Calendar");
	else
	    var CalendarLayer = document.getElementById(sInputName +"Calendar");
	if(CalendarLayer.style.top == ""){
	    if(parent)
		    var Input = window.parent.document.getElementById(sInputName);
		else
		    var Input = document.getElementById(sInputName);
		var arCoords = GetCoordinates(Input);
		CalendarLayer.style.left = arCoords[0] + "px";
		CalendarLayer.style.top += (arCoords[1] + Input.offsetHeight) + "px";
	}
	CalendarLayer.style.display = (CalendarLayer.style.display == "") ? "none" : "";
	if(CalendarLayer.style.display == "")
        CalendarLayer.firstChild.focus();
//	if(CalendarLayer.style.display == ""){
//	    CalendarLayer.focus();
//	}
}

function OverCalendar(sCalendarIcon){
	var oCalendarIcon = document.getElementById(sCalendarIcon);
	oCalendarIcon.style.cursor  = "pointer";
	oCalendarIcon.src  = "../Images/IcoCalendar2.gif";


}
function OutCalendar(sCalendarIcon){
	var oCalendarIcon = document.getElementById(sCalendarIcon);
	oCalendarIcon.style.cursor  = "";
	oCalendarIcon.src  = "../Images/IcoCalendar.gif";

}

function GetCoordinates(oElement, bIgnorePositionedParents){
	if(typeof(bIgnorePositionedParents) == 'undefined') 
		bIgnorePositionedParents = false;
	if(oElement == null)
		return new Array(0, 0);
	var X, Y, oParent;
	X = oElement.offsetLeft;
	Y = oElement.offsetTop;
	oParent = oElement;
	while(oParent = oParent.offsetParent){
		if(!bIgnorePositionedParents)
			if(oParent.style.position == 'absolute' || oParent.style.position == 'relative') 
				break;
		X += oParent.offsetLeft;
		Y += oParent.offsetTop;
	}
	return new Array(X, Y);
 }

function HideCalendarOnBlur(sName){
    if(document.getElementById(sName))
        document.getElementById(sName).style.display = "none";
}