/*******************************************************************************
* Copyright (C) XXX Co.,Ltd. All Rights Reserved
* All rights reserved.
* Project Meedee Version:
* $Author: czarft $
* $Date:  $
* $Source: $
* $Revision: $
*******************************************************************************/
/** @file
 *  @brief
 *
 */

// URL for default display picture if user doesn't specified one.

var flagCheckCanChangePage = true;
if (typeof Ext!="undefined") {
    Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif';
}


function openNewWindow (url) {
  window.open(url,null);
}
String.prototype.ellipse = function(maxLength){
    if(this.length > maxLength){
        return this.substr(0, maxLength) + '...';
        var space="&nbsp;";
        //return "<p style=\"width:70%;\">"+this.substr(0, maxLength) + space+ this.substr(maxLength,this.length - maxLength)+"</p>";
    }
    return this;
};
/*
Event.observe(window, 'load', function() {
    if ($('login_btt') !=null) {
        $('username').value = "";
        $('passwd').value = "";
        $('login_btt').observe('click', function(event){
            if ($F('username')=="") {
                alert ("Plase enter username");
                Event.stop(event);
                return false;
            } else  if ($F('passwd')=="") {
                alert ("Plase enter password");
                Event.stop(event);
                return false;
            } else {
                $('authForm').action = baseurl+"login/authentication";
                $('authForm').submit();
                return;
            }
        });
    }
    if ($('register_btt') !=null) {
        $('register_btt').observe('click', function(event){
            window.location = baseurl+"members/account/create";
            Event.stop(event);
            return false;
        });
    }
    if ($('logout_btt')!=null) {
        $('logout_btt').observe('click', function(event){
            $('authForm').action = baseurl+"login/logout";
            $('authForm').submit();
            Event.stop(event);
            return false;
        });
    }
    if ($('mypage_btt')!=null) {
        $('mypage_btt').observe('click', function(event){
            window.location = baseurl+"members/main";
            Event.stop(event);
            return;
        });
    }
});
*/
/**
 * @param  n=number,p=precission
 * @return  number to present
 */
 function FormatNumber_nozero (n,p)  {
    n = parseFloat(n);
    if ( (n%1) == 0 ) {
        return n;
    } else {
        if (p=="") {
            return n;
        } else {
            return n.toFixed(p);
        }
    }
 }


  function FormatNumber (n,p)  {
    n = parseFloat(n);
    if (p=="") {
        return n;
    } else {
        return n.toFixed(p);
    }
 }

/**
 * Funciton check
 * @param
 * @return
 */

 function checkNumeric(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if ( (charCode != 190)&&(charCode != 110)&& charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 94 || charCode > 105)) {
        return false
    }
    return true
}

function Validation(evt,obj) {
    if (!checkNumeric(event)){
        alert(" Numeric Only");
        obj.value = "";
    }
}
$(document).ready(function() {
    $('.numeric-only').keypress(function(event) {
        if (event.charCode && (event.charCode < 48 || event.charCode > 57))
        {
            event.preventDefault();
        }
    });
    $('.numericdot-only').keypress(function(event) {
        if (event.charCode && event.charCode != 46 && (event.charCode < 48 || event.charCode > 57))
        {
            event.preventDefault();
        }
    });
    
$(".datepicker").datepicker($.extend({}, 
    $.datepicker.regional["th"], {
    showStatus: true, 
    showOn: "both", 
    buttonImage: "templates/images/calendar.gif", 
    buttonImageOnly: true 
})); 

$(".birthdatepicker").datepicker($.extend({}, 
    $.datepicker.regional["th"], {
    yearRange: "1950:" + (new Date()).getFullYear(),
    minDate: new Date(1970, 1, 1),
    maxDate: 0,
    showStatus: true, 
    showOn: "both", 
    buttonImage: "templates/images/calendar.gif", 
    buttonImageOnly: true,
    dateFormat: "dd/mm/yy"

})); 

$('.flash').effect('highlight', {}, 5000);

if ((typeof user_edit_sidebar != "undefined")){
    $('#user-edit-sidebar li#user-edit-sidebar-' + user_edit_sidebar).toggleClass('active');
    $('#user-edit-sidebar li#user-edit-sidebar-' + user_edit_sidebar + ' a').removeAttr('href');
   }
   
if ((typeof nav_active != "undefined")){
    $('#'+ nav_active).toggleClass('active').removeAttr('href');
   }   
});
