﻿// JScript File

    
//////////////////////////////AJAX CAlendar control///////////////////////////////////////  
/*
    Author: Greg Benoit (Benwah)
    Last Modified: 3/16/2007
    
    This is an example of using a single CalendarExtender DatePicker is MS Ajax for
    an unlimited number of date field text boxes. This is a simple example, but could
    easily be extended into a more robust solution of having a single CalendarExtedner
    within a repeater. 
*/   

function pageLoad()
{
    // the ensureCalendar must be called in the pageLoad to hookup the PopupBehavior
    //$find('popupCalBhvr')._ensureCalendar();//zakomentiral Matic, 14.5.2007, ker je javljal error na vsakem page-u
}

/*
    Given an element (el) and an event (ev) this method fires a javascript
    function attached to the element...such as onclick, onfocus, onchange etc...
*/    
function FireEvent(el, ev)
{
    if (document.createEventObject) 
    {
        el.fireEvent(ev);
    } 
    else if (document.createEvent) 
    {
        var localE = document.createEvent("HTMLEvents");
        localE.initEvent(ev.substring(2, ev.length), true, true);
        el.dispatchEvent(localE);        
    }    
}
    
/*
    Takes the Date value in the txtHidden field and sees if it is different from
    the one already in the parentElement. If they are different, then change the
    value of the parentElement to reflect the new date and fire the onchange event of the parent.
*/  
function UpdateClientDate(cal)
{
    var parentDateElement = $find('popupCalBhvr')._popupBehavior.get_parentElement();
     var hiddenTxtBox = $get('txtHidden'); // the ID could be ctl00_txtHidden if you're using master pages
     
    if(parentDateElement.value != hiddenTxtBox.value)
    {
        parentDateElement.value = hiddenTxtBox.value;        
        FireEvent(parentDateElement, 'onchange');
    }
}   

/*
    
*/
function ShowPopupCalendar(calPopupTarget)
{     
    
    $find('popupCalBhvr').hide();  // hide the calendar if it already showing
    
    // set the parentElement of the CalendarPopup behavior...this is what the calendar will popup under.        
    $find('popupCalBhvr')._popupBehavior.set_parentElement(calPopupTarget);       
   
    var hiddenTxtBox = $get('txtHidden'); // the ID could be ctl00_txtHidden if you're using master pages
        
    var theDate = new Date(calPopupTarget.value); // figure out what date is selected...default is today
    if(isNaN(theDate))
    {
        // Set the currently selected date to today's date b/c no date exists
        // in the parentElement right now.
        $find('popupCalBhvr').set_selectedDate(new Date());
        hiddenTxtBox.value = '';           
    }
    else
    {
        // Set the currently selected date to that date that already exists in the
        // parentElement.
        $find('popupCalBhvr').set_selectedDate(theDate);
        hiddenTxtBox.value = calPopupTarget.value;            
    }
    
    // fire the onfocus event of the hiddentTextBox to make the Calendar popup.                
    FireEvent(hiddenTxtBox, 'onfocus');
}


/*
    Both of these function are just functions I made up to show how to handle 
    the selection of a new date...The functions would typically have some sort of
    key passed into them so you know what record to update in the DB.    
*/   


/* HTML Notes:
        Notice the txtStartDate and txtEndDate values can either be set to a date or be blank 
*/




//////////////////////////////Error & Alert Popups///////////////////////////////////////
var intTimeErr = 3000;
var intTimeMsg = 1500;
/*
function showErr(msg) 
{
	document.getElementById("divErrMsg").innerHTML = msg;
	document.getElementById("divErr").style.visibility = 'visible';
	setTimeout('document.getElementById("divErr").style.visibility = "hidden";', intTimeErr);
}
function hideErr() 
{
    document.getElementById("divErr").style.visibility = 'hidden';
}
function showMsg(msg) 
{
	document.getElementById("divMsgMsg").innerHTML = msg;
	document.getElementById("divMsg").style.visibility = 'visible';
	setTimeout('document.getElementById("divMsg").style.visibility = "hidden";', intTimeMsg);
}
function hideMsg() 
{
    document.getElementById("divMsg").style.visibility = 'hidden';
}

*/
function showErr(msg) 
{
    document.getElementById("iErr").src = "JSFunctions/Err.aspx?err=" + msg;
    document.getElementById("iErr").style.visibility = 'visible';

}
function hideErr() 
{
    document.getElementById("iErr").style.visibility = 'hidden';
}
function showMsg(msg) 
{
    document.getElementById("iMsg").src = "JSFunctions/Msg.aspx?msg=" + msg;
    document.getElementById("iMsg").style.visibility = 'visible';
    
}
function hideMsg() 
{
    document.getElementById("iMsg").style.visibility = 'hidden';
}

function killQueryString() 
{
    var url = document.location.href;
    if (url.indexOf("?") != -1) {
        url = url.substring(0, url.indexOf("?"));
        document.location.href = url;
    }
}

function popupWin(win) 
{
     window.open (win,"MPWin","left=100, top=100, width=700, height=500,status=1,toolbar=0, menubar=0, scrollbars=1, location=0");
}

var helpon = 0;
function helpme() {
    if (helpon == 0) {
        iHelp1 = document.getElementById("iHelp");
        iHelp1.style.visibility = 'visible';
        //alert(document.getElementById["iHelp"].window.Document.getElementById("help").innerHTML);
        //iHelp.src = "JSFunctions/Msg.asp";
        //window.frames["iHelp"].document.getElementById("help").innerHTML = "b";
        helpon = 1;
    } else {
        document.getElementById("iHelp").style.visibility = 'hidden';
        helpon = 0;
    }
}



