  var sNLOption = '';

function FlashTag(src, uid, param, wmode, width, height)
{
    this.src       = src;
    this.uid       = uid;
    this.param     = param;
    this.width     = width;
    this.height    = height;
    this.version   = '7,0,14,0';
    this.id        = null;
    this.bgcolor   = 'ffffff';
    this.wmode     = wmode;
    this.flashVars = null;
}

FlashTag.prototype.setVersion = function(v)
{
    this.version = v;
}

FlashTag.prototype.setId = function(id)
{
    this.id = id;
}


FlashTag.prototype.setFlashvars = function(fv)
{
    this.flashVars = fv;
}

FlashTag.prototype.toString = function()
{
    var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
    var flashTag = new String();
    if (ie)
    {
        flashTag += '<object id="' + this.uid + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
        if (this.id != null)
        {
            flashTag += 'id="'+this.id+'" ';
        }
        flashTag += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'">';
        flashTag += '<param name="movie" value="'+this.src+'"/>';
        flashTag += '<param name="quality" value="high"/>';
        flashTag += '<param name="wmode" value="'+this.wmode+'"/>';
        flashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
        //flashTag += '<param name="allowScriptAccess" value="sameDomain"/>';
        if (this.flashVars != null)
        {
            flashTag += '<param name="flashvars" value="'+this.flashVars+'&'+this.param+'"/>';
        }
        flashTag += '</object>';
    }
    else
    {
        flashTag += '<embed id="' + this.uid + '" src="'+this.src+'" ';
        flashTag += 'quality="high" '; 
        flashTag += 'bgcolor="#'+this.bgcolor+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'" ';
        flashTag += 'wmode="'+this.wmode+'" ';
        //	flashTag += 'allowScriptAccess="sameDomain" ';
        flashTag += 'type="application/x-shockwave-flash" ';
        if (this.flashVars != null)
        {
            flashTag += 'flashvars="'+this.flashVars+'&'+this.param+'" ';
        }
        if (this.id != null)
        {
            flashTag += 'name="'+this.id+'" ';
        }
        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        flashTag += '</embed>';
    }
    op_n=1;

    return flashTag;
    alert(flashTag);
}

FlashTag.prototype.fetch = function()
{
    return this.toString();
}

function o(id)
{
    return document.getElementById(id);
}

function validateEmail(email){
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(email.match(emailRegEx)){
        return true;
    }else{
        return false;
    }
}

function trim(str) {
    if(str=="")
        return "";
    else
        return str.replace(/^\s+|\s+$/g, '') ;
}
	
	
//============= Radosna tworczosc===========
function getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
    return arrayPageSize;
};

//====koniec radosnej tworczosci=======





function przyciemnienie() {

    var wymiary = getPageSize();
    document.getElementById('h_przyciemnienie').style.height =  wymiary[1] + "px";
    document.getElementById('h_przyciemnienie').style.display = "block";
}

function closeWindowMessage(div) {
    okienko_wybrane = "none";
    o("h_przyciemnienie").style.display = "none";
    o(div).style.display = "none";
}

function resetZgloszenie() {
    var style1 = "1px solid #a5acb2";
    var style2 = "1px solid #e20000";


    o('adres_nazwa_firmy').style.border = style1;

    o('adres_imie_nazwisko').style.border = style1;

    o('adres_ulica').style.border = style1;

    o('adres_kod1').style.border = style1;

    o('adres_kod2').style.border = style1;

    o('adres_miejscowosc').style.border = style1;

    o('dane_nr_faktury').style.border = style1;

    o('dane_data_dzien').style.border = style1;

    o('dane_data_miesiac').style.border = style1;

    o('dane_data_rok').style.border = style1;

    o('dane_nazwa_firmy').style.border = style1;

    o('dane_osoba').style.border = style1;

    o('dane_nr').style.border = style1;

    o('dane_email').style.border = style1;

    o('opis_uszkodzenia').style.border = style1;

}

var okienko_wybrane = "none";
function showWindowMessage(div) {
	
    okienko_wybrane = div;
	
    pozycja(div);
    o(div).style.display = "block";
    przyciemnienie();
}

function pozycja(id) {
    var div = o(id);

    var wymiary = getPageSize();


    div.style.marginLeft = parseInt((wymiary[2] / 2) - ($('#'+id).width()/2)) + "px";
    div.style.marginTop =  parseInt(wymiary[3] / 2) - ($('#'+id).height()/2) + "px";
  
}	


function przelacz_okienka(div1, div2) {
    pozycja(div2);
	
    o(div1).style.display = "none";
    o(div2).style.display = "block";
    okienko_wybrane = div2;
}

function logowanie_user() {
	
    xajax_logowanie_user(o('log_login').value, o('log_pass').value);
	
}

function wyslijZgloszenie() {
    var rodzaj;
	
    if (o('rodzaj1').checked) {
        rodzaj = 1;
    } else if (o('rodzaj2').checked) {
        rodzaj = 2;
    }
	
    var bErr = false;
	
    var style1 = "1px solid #a5acb2";
    var style2 = "1px solid #e20000";
	
    var adres_nazwa_firmy = o('adres_nazwa_firmy').value;
    var adres_imie_nazwisko = o('adres_imie_nazwisko').value;
    var adres_ulica = o('adres_ulica').value;
    var adres_kod1 = o('adres_kod1').value;
    var adres_kod2 = o('adres_kod2').value;
    var adres_miejscowosc = o('adres_miejscowosc').value;
    var dane_nr_faktury = o('dane_nr_faktury').value;
    var dane_data_dzien = o('dane_data_dzien').value;
    var dane_data_miesiac = o('dane_data_miesiac').value;
    var dane_data_rok = o('dane_data_rok').value;
    var dane_nazwa_firmy = o('dane_nazwa_firmy').value;
    var dane_osoba = o('dane_osoba').value;
    var dane_nr = o('dane_nr').value;
    var dane_email = o('dane_email').value;
    var opis_uszkodzenia = o('opis_uszkodzenia').value;
	
	
    if (rodzaj != 1 && rodzaj !=2) {
        bErr = true;
    }
    if (adres_imie_nazwisko == '') {
        o('adres_imie_nazwisko').style.border = style2;
        bErr = true;
    } else {
        o('adres_imie_nazwisko').style.border = style1;
    }
    if (adres_ulica == '') {
        o('adres_ulica').style.border = style2;
        bErr = true;
    } else {
        o('adres_ulica').style.border = style1;
    }
    if (adres_kod1 == '' || !adres_kod1.match(/^[0-9]{2}$/)) {
        o('adres_kod1').style.border = style2;
        bErr = true;
    } else {
        o('adres_kod1').style.border = style1;
    }
    if (adres_kod2 == '' || !adres_kod2.match(/^[0-9]{3}$/)) {
        o('adres_kod2').style.border = style2;
        bErr = true;
    } else {
        o('adres_kod2').style.border = style1;
    }
    if (adres_miejscowosc == '') {
        o('adres_miejscowosc').style.border = style2;
        bErr = true;
    } else {
        o('adres_miejscowosc').style.border = style1;
    }
	
    if (dane_nr == '') {
        o('dane_nr').style.border = style2;
        bErr = true;
    } else {
        o('dane_nr').style.border = style1;
    }
    if (dane_email == '' || !validateEmail(dane_email)) {
        o('dane_email').style.border = style2;
        bErr = true;
    } else {
        o('dane_email').style.border = style1;
    }
	
    if (!bErr) {
        o('zlecenie_serwisowe').action = "wyslij_zgloszenie.php";
        o('zlecenie_serwisowe').submit();
    }
	
}


function showPodobneProdukty(iPage, iKat, iProd) {
    xajax_showPodobneProdukty(iPage, iKat, iProd);
}

function wyslij_mail() {
    var tresc = o('kontakt_tresc').value;
    var mail = o('kontakt_mail').value;
    var blad =0;
	
    o('kontakt_tresc').className = "inp2";
    o('kontakt_mail').className = "inp2";

		
    if(validateEmail(mail) == false) {
        o('kontakt_mail').className = "inp2_red";
        blad = 1;
    }
	
    if(tresc.length < 2) {
        o('kontakt_tresc').className = "inp2_red";
        blad = 1;
    }
	
	
    if(blad == 0) xajax_sendMail2(mail, tresc);
	
	
}


function checkIfEnter(e)
{
    var iCode;
    if (e.keyCode) iCode = e.keyCode;
    else if (e.which) iCode = e.which;
    var keyChar = String.fromCharCode(iCode);
    if(keyChar == "\r")
    {
        logowanie_user();
    }
}


function init()
{    
    try {

        if (GBrowserIsCompatible()) {
            var map = new GMap2(o("googleMapCanvas"));
            map.setCenter(new GLatLng(49.424256,22.32477), 10);
            map.setMapType(G_NORMAL_MAP);
            map.addControl(new GSmallMapControl());
            var point = new GLatLng(49.424256,22.32477);
            map.addOverlay(new GMarker(point));
            map.openInfoWindowHtml(point,"<b> Pensjonat i Restauracja <br> \"W Starym Piecu...\" <br> Hoczew k/Leska <br> tel. 13 468 98 80"); // tekst do dymku
        }
    }catch(e) { };

    KsiegaGosciKometarzValidate();
    FormularzKontaktowyWiadomoscValidate();
    NewsLetterOperationValidate();
    FormularzRezerwacjiWiadomoscValidate();
    FormularzZamowieniaContentValidate();
    rezerwacjeDataPicker();

    Shadowbox.init();

}

(window.attachEvent)?attachEvent('onload', init) : addEventListener('load', init, false);



document.onkeydown = checkKeycode

function checkKeycode(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    if(keycode == 27 && okienko_wybrane != "none") {
        if(okienko_wybrane == "profil" || okienko_wybrane == "awatar") setTimeout("location.reload()",1);
        else zamknij_okienko(okienko_wybrane);
    }
}

function zgloszenieSerwisowe() {
    przyciemnienie();
    o('zgloszenie_serwisowe').style.display = "block";
}


function wyslijKontakt() {
    var imie = o('kontakt_imie').value;
    var naz = o('kontakt_nazwisko').value;
    var firma = o('kontakt_firma').value;
    var email = o('kontakt_email').value;
    var wiadomosc = o('kontakt_wiadomosc').value;
	

    o('kontakt_imie').className = "input";
    o('kontakt_email').className = "input";
    o('kontakt_wiadomosc').className = "textarea";

		
    var blad = 0;
	
    if(validateEmail(email) == false) {
        o('kontakt_email').className = "input_red";
        blad = 1;
    }
    if(imie.length < 3) {
        o('kontakt_imie').className = "input_red";
        blad = 1;
    }
    if(wiadomosc.length <3) {
        o('kontakt_wiadomosc').className = "textarea_red";
        blad = 1;
    }
	
    if(blad == 0) xajax_wyslijKontakt(imie, naz, firma, email, wiadomosc);
	
	
}

function szukaj() {

    if(trim(o('fraza').value).length < 3) o('fraza').style.color = "#e20000";
    else o('szukaj_form').submit();
	
}
//hoczew

function changeBgImage (image , id) {    
    o(id).style.backgroundImage = url(image);
}
function RedLeft(id){
    o(id).style.backgroundPosition = '0px -332px';
}
function WhiteLeft(id){
    o(id).style.backgroundPosition = '-225px -332px';
}

function showWydarzeniaGaleriaZdjecia(iPage, iIdPods, iType) {
    xajax_hShowWydarzeniaGaleriaZdjecia(iPage, iIdPods, iType);
}

function showWydarzeniaGaleriaFilmy(iPage, iIdPods) {
    xajax_hShowWydarzeniaGaleriaFilmy(iPage, iIdPods);
}

function showImprezyGaleriaZdjecia(iPage, iIdPods, iType) {
    xajax_hShowImprezyGaleriaZdjecia(iPage, iIdPods, iType);
}

function showImprezyGaleriaFilmy(iPage, iIdPods) {
    xajax_hShowImprezyGaleriaFilmy(iPage, iIdPods);
}

function showPodstronaGaleriaZdjecia(iPage, iIdPods, iType) {
    xajax_hShowPodstronaGaleriaZdjecia(iPage, iIdPods, iType);
}

function showPodstronaGaleriaFilmy(iPage, iIdPods) {
    xajax_hShowPodstronaGaleriaFilmy(iPage, iIdPods);
}

function bilety_KupBilet(){
    if(o('kbEdit').style.display == "" || o('kbEdit').style.display == "none")
    {
        o('kbEdit').style.display = "block";
    } else {
        o('kbEdit').style.display = "none";
    }
}

function ksiegaGosci_dodajWpis(){
    if(o('kgEdit').style.display == "" || o('kgEdit').style.display == "none")
    {
        o('kgEdit').style.display = "block";     
    } else {
        o('kgEdit').style.display = "none";
    }
}

function KsiegaGosciValidate() {
    jQuery("#kg_form").submit();
}

function KsiegaGosciKometarzValidate() {
    jQuery("#kg_form").validate({
        submitHandler: function() {
            var KGMess = new Array();
            KGMess.push(o('kgEditText_name').value);
            KGMess.push(o('kgEditText_email').value);
            KGMess.push(o('kgEditTextArea_message').value);
            xajax_hSendKGComment(KGMess);
        },
        rules: {
            kgEditText_name: "required",
            kgEditTextArea_message: "required",
            kgEditText_email: {
                required: true,
                email: true
            },
            captcha_img: {
                required: true,
                remote: "captcha/process.php"
            }
        },
        messages: {
            kgEditText_name: "   Pole jest wymagane!",
            kgEditTextArea_message: "   Pole jest wymagane!",
            kgEditText_email: "   Proszę podać poprawny adres email!",
            captcha_img: "   Proszę podać poprawny kod z obrazka! Kod można zmienić klikając na obrazek"
        },
        onkeyup: false
    });
}

function FormularzKontaktowyValidate() {
    jQuery("#fk_form").submit();
}

function FormularzKontaktowyWiadomoscValidate() {
    jQuery("#fk_form").validate({
        submitHandler: function() {
            var FKMessage = new Array();
            FKMessage.push(o('fkEditText_surname').value);
            FKMessage.push(o('fkEditText_name').value);
            FKMessage.push(o('fkEditText_email').value);
            FKMessage.push(o('fkEditTextArea_message').value);
            xajax_hSendFKComment(FKMessage);
        },
        rules: {
            fkEditText_surname: "required",
            fkEditTextArea_message: "required",
            fkEditText_email: {
                required: true,
                email: true
            },
            captcha_img: {
                required: true,
                remote: "captcha/process.php"
            }
        },
        messages: {
            fkEditText_surname: "   Pole jest wymagane!",
            fkEditTextArea_message: "   Pole jest wymagane!",
            fkEditText_email: "   Proszę podać poprawny adres email!",
            captcha_img: "   Proszę podać poprawny kod z obrazka! Kod można zmienić klikając na obrazek"
        },
        onkeyup: false
    });
}

function NewsLetterValidate(_sNLOption) {
    sNLOption = _sNLOption;
    jQuery("#nl_form").submit();
}

function NewsLetterOperationValidate() {
    jQuery("#nl_form").validate({
        submitHandler: function() {
            xajax_hSendNLOperation(sNLOption, o('nlEditText_email').value);
        },
        rules: {
            nlEditText_email: {
                required: true,
                email: true
            }
        },
        messages: {
            nlEditText_email: "  Proszę podać poprawny adres email!"
        },
        onkeyup: false
    });
}

function FormularzRezerwacjiValidate(){
    jQuery("#fr_form").submit();
}

function FormularzRezerwacjiWiadomoscValidate() {
    jQuery("#fr_form").validate({
        submitHandler: function() {
            var FRMessage = new Array();
            FRMessage.push(o('frEditText_NazwiskoImie').value);
            FRMessage.push(o('frEditText_KodUlica').value);
            FRMessage.push(o('frEditText_Telefon').value);
            FRMessage.push(o('frEditText_email').value);
            FRMessage.push(DataPickerGetDate("#frRezerwacjaDateStart","yy-mm-dd"));
            FRMessage.push(DataPickerGetDate("#frRezerwacjaDateEnd","yy-mm-dd"));
            FRMessage.push(o('frEditText_IlDorosle').value);
            FRMessage.push(o('frEditText_IlDzieci').value);
            FRMessage.push(o('frEditTextArea_Uwagi').value);

            xajax_hSendFRMessage(FRMessage);
        },
        rules: {
            frEditText_NazwiskoImie: "required",
            frEditText_KodUlica: "required",
            frEditText_Telefon: "required",
            frRezerwacjaDateStart: "required",
            frRezerwacjaDateEnd: "required",
            frEditText_IlDorosle: "required",
            frEditText_email: {
                required: true,
                email: true
            },
            captcha_img: {
                required: true,
                remote: "captcha/process.php"
            }
        },
        messages: {
            frEditText_NazwiskoImie: "   Pole jest wymagane!",
            frEditText_KodUlica: "   Pole jest wymagane!",
            frEditText_Telefon: "   Pole jest wymagane!",
            frRezerwacjaDateStart: "   Pole jest wymagane!",
            frRezerwacjaDateEnd: "   Pole jest wymagane!",
            frEditText_IlDorosle: "   Pole jest wymagane!",
            frEditText_email: "   Proszę podać poprawny adres email!",
            captcha_img: "   Proszę podać poprawny kod z obrazka! Kod można zmienić klikając na obrazek."
        },
        onkeyup: false
    });
}

function FormularzZamowieniaValidate(){
    jQuery("#kb_form").submit();
}

function FormularzZamowieniaContentValidate() {
    jQuery("#kb_form").validate({
        submitHandler: function(form) {

            var KBDates = new Array();

            KBDates.push(o('kbEditText_Ilosc').value);
            KBDates.push(o('kbEditText_Imie').value);
            KBDates.push(o('kbEditText_Nazwisko').value);
            KBDates.push(o('kbEditText_NumerDokumnetu').value);
            KBDates.push(o('kbEditText_Ulica').value);
            KBDates.push(o('kbEditText_NumerDomu').value);
            KBDates.push(o('kbEditText_NumerMieszkania').value);
            KBDates.push(o('kbEditText_Miasto').value);
            KBDates.push(o('kbEditText_KodPocztowy').value);
            KBDates.push(o('kbEditText_Telefon').value);
            KBDates.push(o('kbEditText_AdresEmail').value);
            KBDates.push(o('kbStaticText_imprezaId').value);
            KBDates.push(o('kbStaticText_timeTsJS').value);
            jQuery("input:radio[name=paymentType]:checked").each(function()
            {
                KBDates.push($(this).val());
            });
            KBDates.push(o('kbStaticText_js').value);

            xajax_hSaveKBDatesAndSetRestInputValue(KBDates);

        //form.submit();

        },
        rules: {
            kbEditText_Ilosc: "required",
            kbEditText_Imie: "required",
            kbEditText_Nazwisko: "required",
            kbEditText_NumerDokumnetu: "required",
            kbEditText_Ulica: "required",
            kbEditText_NumerDomu: "required",
            //kbEditText_NumerMieszkania: "required",
            kbEditText_Miasto: "required",
            kbEditText_KodPocztowy: "required",
            kbEditText_Telefon: "required",
            kbEditText_AdresEmail: {
                required: true,
                email: true
            },
            captcha_img: {
                required: true,
                remote: "captcha/process.php"
            },
            kbEditText_Regulamin: "required"
        },
        messages: {
            kbEditText_Ilosc: "   Pole jest wymagane!",
            kbEditText_Imie: "   Pole jest wymagane!",
            kbEditText_Nazwisko: "   Pole jest wymagane!",
            kbEditText_NumerDokumnetu: "   Pole jest wymagane!",
            kbEditText_Ulica: "   Pole jest wymagane!",
            kbEditText_NumerDomu: "   Pole jest wymagane!",
            //kbEditText_NumerMieszkania: "   Pole jest wymagane!",
            kbEditText_Miasto: "   Pole jest wymagane!",
            kbEditText_KodPocztowy: "   Pole jest wymagane!",
            kbEditText_Telefon: "   Pole jest wymagane!",
            kbEditText_AdresEmail: "   Proszę podać poprawny adres email!",
            captcha_img: "   Proszę podać poprawny kod z obrazka! Kod można zmienić klikając na obrazek.",
            kbEditText_Regulamin: "   Niezbędna jest akceptacja regulaminu!"
        },
        onkeyup: false
    });
}

function refreshCaptchaImage(){
    xajax_hRefreshCaptchaImage();
}

function clearFMCommentForm(){
    o('fkEditText_name').value = "";
    o('fkEditText_surname').value = "";
    o('fkEditText_email').value = "";
    o('fkEditTextArea_message').value = "";
    o('fkEditText_img').value = "";
}

function clearKGCommentForm(){
    o('kgEditText_name').value = "";
    o('kgEditText_email').value = "";
    o('kgEditTextArea_message').value = "";
    o('kgEditText_img').value = "";
}

function clearNLCommentForm(){
    o('nlEditText_email').value = "";
}

function clearFRCommentForm(){
    o('frEditText_NazwiskoImie').value = "";
    o('frEditText_KodUlica').value = "";
    o('frEditText_Telefon').value = "";
    o('frEditText_email').value = "";
    ClearDate('#frRezerwacjaDateStart');
    ClearDate('#frRezerwacjaDateEnd');
    o('frEditText_IlDorosle').value = "";
    o('frEditText_IlDzieci').value = "";
    o('frEditTextArea_Uwagi').value = "";
    o('frEditText_img').value = "";
}

function rezerwacjeDataPicker(){
    jQuery('#frRezerwacjaDateStart, #frRezerwacjaDateEnd').datepicker(
    {
        showOn: "both",
        buttonImage: 'img/admin/kalendarz.gif',
        buttonImageOnly: true,
        dateFormat: 'yy-mm-dd',
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        beforeShow: rezerwacjaCustomRange
    });
}

function  rezerwacjaCustomRange(input)
{
    return {
        //minDate: (input.id == "txtStartDate" ? new Date(2008, 12 - 1, 1) : null),
        minDate: (input.id == "frRezerwacjaDateEnd" ? $("#frRezerwacjaDateStart").datepicker("getDate") : null),
        maxDate: (input.id == "frRezerwacjaDateStart" ? $("#frRezerwacjaDateEnd").datepicker("getDate") : null)
    };
}

function numbersonly(myfield, e, dec)
{
    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);

    // control keys
    if ((key==null) || (key==0) || (key==8) ||
        (key==9) || (key==13) || (key==27) )
        return true;

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;

    // decimal point jump
    else if (dec && (keychar == "."))
    {
        myfield.form.elements[dec].focus();
        return false;
    }
    else
        return false;
}

function DataPickerGetDate($selector, formatString){
    try {
        var _date = jQuery($selector).datepicker('getDate');
        return jQuery.datepicker.formatDate(formatString,_date);
    }
    catch(e){
        return '';
    }
}

function  ClearDate(tag){
    jQuery(tag).datepicker( 'setDate' , null );
}
