﻿// Checks if included UtilityLibrary.js
if( typeof( Syncfusion_BrowsersCompatibility_version ) == "undefined" || Syncfusion_BrowsersCompatibility_version != "1.0" )
  alert( "\"BrowsersCompatibility.js (1.0 version)\" not included!" );
// Version info
Syncfusion_UtilityLibrary_version = "1.0";

/////////////////////////////////////////////////////////
// String addition functionality
/////////////////////////////////////////////////////////

// Remove substring from String object
String.prototype.remove = function( start, length )
{   
  return this.substring( 0, start ) + this.substr( start + length );
}
// Insert string in String object
String.prototype.insert = function( str, pos )
{
  return this.substring( 0, pos ) + str + this.substr( pos );
}
// Update substring in String object
String.prototype.update = function( str, pos )
{
	var nLength = ( 0 != str.length ) ? str.length : 1;
	return this.substring( 0, pos ) + str + this.substr( pos + nLength );
}

// Replace substring to "replaceStr"
String.prototype.replaceStr = function( str, replaceStr )
{
  var pos = this.indexOf( str );
  var res = "", prevPos = 0;
  
  if( "" == str )
	  return replaceStr;
  
  while( pos > -1 )
  {
    res += this.substring( prevPos, pos );
	res += replaceStr;
	prevPos = pos + str.length;
	pos = this.indexOf( str, prevPos );
  }
  
  return res + this.substr( prevPos );
}

String.prototype.Equals = function( sVal )
{
	var bRes = false;
	
	var sSource = this;
	
	do
	{
		if( sSource.length != sVal.length )
		{
			break;
		}
		
		for( var c=0; c< sSource.length; ++c )
		{	
			if( sVal.charAt(c) != sSource.charAt(c) )
			{
				break;
			}
			if( c == sSource.length-1)
			{
				bRes = true;
			}
		}
	}
	while( false );
	
	return bRes;
}

// Encoded only "space" and "percent" symbols
String.prototype.lightEscape = function()
{
  var res = this.replaceStr( "%", "%25" );
  return res.replaceStr( " ", "%20" );
}
// Unencoded "space" and "percent" symbols
String.prototype.lightUnescape = function()
{
  var res = this.replaceStr( "%20", " " );
  return res.replaceStr( "%25", "%" );
}
// Fill char in String object
String.prototype.fillChar = function( ch, count, pos )
{
  var str = "";
  
  for( var i = 0; i<count; i++ ) str += ch;
  
  return this.update( str, pos );
}
// 
String.prototype.fill = function( ch, count )
{
  var str = "";
  for( var i = 0; i<count; i++ ) str += ch;
  return str;
}
// Convert string to int array
String.prototype.toIntArray = function()
{
  var sarr = this.split( " " );
  
  for( var i = 0; i<sarr.length; i++ ) 
    sarr[ i ] = new Number( sarr[ i ] );
    
  return sarr;
}

// removes leading characters that are equals to charToRemove
String.prototype.removeLeadingChars = function( charToRemove )
{
  var result = this;
  var i = 0;
  var len = this.length;
  var iCurLen = len;
  
  while( i < len && ( this.charAt( i ) == charToRemove ) && iCurLen > 1 )
  {
    result = result.substr( 1, --iCurLen );
    i++;
  }
  
  return result;
}

var c_sArraySeparator = ";";
String.prototype.ToArray = function( sSep )
{
	if (null == sSep)
	{
		sSep = c_sArraySeparator;
	}
	var arrRes = this.split( sSep );
	
	for( var c=0; c < arrRes.length; ++c)
	{
		arrRes[ c ] = parseInt( arrRes[ c ], 10 );
	}
	
	return arrRes;
}
/////////////////////////////////////////////////////////
// Math addition functionality
/////////////////////////////////////////////////////////
Number.prototype.toFloatPrecision = function( prec )
{
  if( prec == null ) prec = 3;
  
  pos = Math.pow( 10, prec );
  return Math.round( this*pos ) / pos;
}

/////////////////////////////////////////////////////////
// Array addition functionality
/////////////////////////////////////////////////////////
Array.prototype.ToString = function( sSep )
{
	if (null == sSep)
	{
		sSep = c_sArraySeparator;
	}
	return this.join( sSep );
}
// Convert array into string where values are separated by spaces
Array.prototype.toSeparatedString = function()
{
	var result = "";
  
	var len = this.length;
	for( var i = 0 ; i < len; i++ )
	{
		result += this[ i ].toString();

		if( i != len - 1 ) result += " ";
	}
  
	return result;
}

// Compares another array with this one.
Array.prototype.compareTo = function( array )
{
  var result = 0;
  var len1 = this.length;
  var len2 = array.length;
  
  var len = ( len1 > len2 ) ? len2 : len1;
  
  for( var i = 0; i < len; i++ )
  {
    if( this[ i ] > array[ i ] ) return 1;
    if( this[ i ] < array[ i ] ) return -1;
  }
  
  return len1 - len2;
}
/////////////////////////////////////////////////////////
// Document helper functions
/////////////////////////////////////////////////////////
function DocHelper()
{
  // Private members
  var bc = new BrowsersCompatibility();
  
  /////////////////////////////////////////////////////////
  // Check selected range
  this.getSelectedLength = function( element )
  {
    if( element.tagName != 'INPUT' ) return null;
      element.focus();
    
    return bc.getSelectedLength( element );
  }
  this.getSelectedText = function( element )
  {
    if( element.tagName != 'INPUT' ) return null;
      element.focus();
    
    return bc.getSelectedText( element );
  }
  // Gets caret position from INPUT element
  this.getCaretPos = function( element )
  {
    if( element.tagName != 'INPUT' ) return null;
      element.focus();       
    
    return bc.getCaretPos( element );
  }
  
  // Moves caret position in INPUT element
  this.moveCaret = function( element, offset )
  {
    if( element.tagName != 'INPUT' ) 
		return null;
		
    element.focus();
    bc.moveCaret( element, offset );
  }
  // Insert text into INPUT element
  this.insertText = function( element, str )
  {
    if( element.tagName != 'INPUT' ) return null;
       element.focus();
    
    bc.insertText( element, str );
  }
  // Remove text into INPUT element
  this.removeText = function( element, length, offset )
  {
    if( element.tagName != 'INPUT' ) return null;
      element.focus();
    
    bc.removeText( element, length, offset );
  }
  // Update text into INPUT element
  this.updateText = function( element, str, offset )
  {
    if( element.tagName != 'INPUT' ) return null;
      element.focus();
    
    bc.updateText( element, str, offset );
  }
  
  // Fill char in INPUT element
  this.fillChar = function( element, ch, count, offset )
  {
   if( element.tagName != 'INPUT' ) return null;

    var str = "";
    for( var i = 0; i<count; i++ ) str += ch;
    this.updateText( element, str, offset );  
  }
  // Set new text
  this.setText = function( element, text, pos )
  {
    //alert("Setting text " + text );
    if( element.tagName != 'INPUT' ) return null;
    
    if( pos == null ) pos = this.getCaretPos( element );
    
    element.value = text;
        
    this.moveCaret( element, pos );
  }
  
  // Get selection text
  this.getSelectText = function( element )
  {
    if( element.tagName != 'INPUT' ) return null;
    element.focus();
    
    return bc.getSelectText( element );
  }
    
  // Update selected text 
  this.updateSelectText = function( element, str )
  {
    if( element.tagName != 'INPUT' ) return null;
    element.focus();
    
    bc.updateSelectText( element, str );
  }
  // Select text into INPUT element
  this.selectText = function( element, pos, length )
  {
    if( element.tagName != 'INPUT' ) return null;
    element.focus();
    
    bc.selectText( element, pos, length );     
  }
}
  
//////////////////////////////////////////////////////
// Keys helper methods
function DocHelperKeys()
{
  // key constants
  this.DEF_LEFT = 37;
  this.DEF_RIGHT = 39;
  this.DEF_UP = 38;
  this.DEF_DOWN = 40;
  this.DEF_PGUP = 33;
  this.DEF_PGDOWN = 34;
  this.DEF_HOME = 36;
  this.DEF_END = 35;
  this.DEF_TAB = 9;
  this.DEF_DEL = 46;
  this.DEF_MINUS = 189;
  this.DEF_0 = 48;
  this.DEF_9 = 57;
  this.DEF_A = 65;
  this.DEF_V = 86;
  this.DEF_v = 118;
  this.DEF_C = 67;
  this.DEF_c = 99;
  this.DEF_Z = 90;
  this.DEF_a = 97;
  this.DEF_z = 122;
  this.DEF_INS = 45;
  this.DEF_ESC = 27; 
  this.DEF_SPACE = 32; 
  this.DEF_NUMLOCK_DECIMALPOINT = 110; //.
  this.DEF_NUMLOCK_ZERO = 96; //0
  this.DEF_POINT = 46;
 
  this.bc = new BrowsersCompatibility();
  this.lastEvent;
  
  this.isPointKey = function()
  {
	var bRes = false;
	
	var nKeyCode =  this.bc.getKeyCode(this.lastEvent);
	if( this.DEF_POINT == nKeyCode )
	{
		bRes = true;
	}
	
	return bRes;
  }
  this.isShiftKey = function()
  {
	var bRes = this.lastEvent.shiftKey;
	return bRes;
  }
  this.keyCode = function( event )
  {
    return this.bc.getKeyCode( event )
  }
  this.isEscKey = function()
  {
    if( this.bc.getKeyCode(this.lastEvent) == this.DEF_ESC ) return true;
    return false;
  }
  this.isSpaceKey = function()
  {
	var bRes = false;
	
	var nKeyCode =  this.bc.getKeyCode(this.lastEvent);
	if( this.DEF_SPACE == nKeyCode )
	{
		bRes = true;
	}
	
	return bRes;
  }
  this.isDecimalSeparatorKey = function()
  {
	var bRes = false;
	
	var nKeyCode =  this.bc.getKeyCode(this.lastEvent);
	if( this.DEF_NUMLOCK_DECIMALPOINT == nKeyCode &&  "keydown" == this.lastEvent.type )
	{
		bRes = true;
	}
	
	return bRes;
  }

  this.isLeftKey = function()
  {
    //if( event.keyCode == this.DEF_LEFT ) return true;
    //alert( this.bc.getKeyCode(this.lastEvent) == this.DEF_LEFT );
    if( this.bc.getKeyCode(this.lastEvent) == this.DEF_LEFT ) return true;
    return false;
  }
  //
  this.isRightKey = function()
  {
    //if( event.keyCode == this.DEF_RIGHT ) return true;
    if( this.bc.getKeyCode(this.lastEvent) == this.DEF_RIGHT ) return true;
    
    return false;
  }
  // Indicates whether up cursor key was pressed.
  this.isUpKey = function()
  {
    //return ( event.keyCode == this.DEF_UP );
    return ( this.bc.getKeyCode(this.lastEvent) == this.DEF_UP );
  }
  // Indicates whether down cursor key was pressed.
  this.isDownKey = function()
  {
    //return ( event.keyCode == this.DEF_DOWN );
    return ( this.bc.getKeyCode(this.lastEvent) == this.DEF_DOWN );
  }
  // Indicates is pressed cursor key or follow keys: pgup, pgdown, home, end
  this.isMoveCaretKey = function( lastKey )
  {    
    //alert('isMoveCaretKey');
    //var key = event.keyCode;
    var key = lastKey;
    if( lastKey == null ) key = this.bc.getKeyCode( this.lastEvent );
    //alert(key);    
    
    switch( key )
      {
      case this.DEF_PGUP: case  this.DEF_PGDOWN: // pgup, pgdown
      case this.DEF_HOME: case this.DEF_END: // home, end
      case this.DEF_UP: case this.DEF_DOWN: 
      case this.DEF_LEFT : case this.DEF_RIGHT:  // cursor key
        return true;
      default: 
        return false;
    }
    return false;
  }
  // Indicates is pressed tab key
  this.isTabKey = function()
  {
    if( this.bc.getKeyCode(this.lastEvent) == this.DEF_TAB ) return true; // tab
    return false;
  }
  // Indicates is pressed zero key.
  this.isNumZeroKey = function()
  {
    var key = this.bc.getKeyCode( this.lastEvent );  
    var bRes = ( this.DEF_NUMLOCK_ZERO == key )
    return bRes;
  }
  // Indicates is pressed delete key
  this.isDelKey = function()
  {
    var key = this.bc.getKeyCode(this.lastEvent);
    if( key == this.DEF_DEL ) return true; // del
    return false;
  }
  // Indicates is pressed backspace key
  this.isBackSpaceKey = function()
  {
    if( this.bc.getKeyCode(this.lastEvent) == 8 ) return true; // backspace
    return false;
  }
  // Indicates is pressed '-' key
  this.isSignKey = function( specChar )
  { 
    // '-'
    if( specChar == 45 ) 
      return true
    else  if( this.bc.getKeyCode(this.lastEvent) == this.DEF_MINUS ) 
      return true;  
    else
      return false;
  }
  // Indicates is pressed 0-9 key
  this.isNumericKey = function()
  {
    //alert('isNumericKey');
    var key = this.bc.getKeyCode( this.lastEvent );    
    
    // 0-9 and no ctrl or shift or alt pressed
    return (
      ( key >= this.DEF_0 && key <= this.DEF_9 ) && !this.bc.ctrlKeyPressed( this.lastEvent )
      && !this.bc.shiftKeyPressed( this.lastEvent ) && !this.bc.altKeyPressed( this.lastEvent )) ; 
     
  }
  // Indicates is pressed 0-9 or A-Z key
  this.isAlphanumericKey = function()
  {
    var bRes = false;
    
    var key = this.bc.getKeyCode( this.lastEvent );
    var bIsNumericKey = (key >= this.DEF_0 && key <= this.DEF_9);
    
    // 0-9, A-Z, a-z    
    bRes = ( bIsNumericKey || this.isAlphaKey() );
			
	return bRes;
  }
   // Indicates is pressed  A-Z key
  this.isAlphaKey = function()
  {
	var bRes = false;
    var key = this.bc.getKeyCode( this.lastEvent );
    
    var bIsDecimalSeparatorKey = this.isDecimalSeparatorKey();
    var bIsUpperAlphaKey = ( key >= this.DEF_A && key <= this.DEF_Z  );
    var bIsLowwerAlphaKey = ( key >= this.DEF_a && key <= this.DEF_z );
    
    bRes = ( !bIsDecimalSeparatorKey && ( bIsUpperAlphaKey || bIsLowwerAlphaKey ))
    
    return bRes;
  }
  
  // 
  this.keyCharCode = function()
  {
    return String.fromCharCode( this.bc.getKeyCode( this.lastEvent ) );
  }
  // Indicates is pressed Shift+Ins or Ctrl+V
  this.isPasteKey = function()
  {
    /*if( ( this.bc.shiftKeyPressed( this.lastEvent ) && this.bc.getKeyCode( this.lastEvent ) == 45 ) ||
        ( this.bc.ctrlKeyPressed( this.lastEvent ) ) && 
        
        ( ( this.bc.getKeyCode( this.lastEvent ) == this.DEF_V ) || 
          ( this.bc.getKeyCode( this.lastEvent ) == this.DEF_v ) 
        ) )
    {
      return true;
    }
    */
    var t=100;
    if ( this.lastEvent.shiftKey  && (this.bc.getKeyCode( this.lastEvent ) == 45) )
      return true;
    
    if ( this.lastEvent.ctrlKey   &&         
        ( ( this.bc.getKeyCode( this.lastEvent ) == this.DEF_V ) || 
          ( this.bc.getKeyCode( this.lastEvent ) == this.DEF_v ) )
       )
    {
      return true;
    }
    return false;
    
  }
  // Indicates is pressed Shift+Ins or Ctrl+C
  this.isCopyKey = function()
  {
    if( ( this.bc.ctrlKeyPressed( this.lastEvent ) && this.bc.getKeyCode( this.lastEvent ) == this.DEF_INS ) ||
        ( this.bc.ctrlKeyPressed( this.lastEvent ) && this.bc.getKeyCode( this.lastEvent ) == this.DEF_C ) )
    {
      return true;
    }
    return false;
  }
}
///////////////////////////////////////
document._helper = new DocHelper; 
document._helper.keys = new DocHelperKeys;
///////////////////////////////////////
function IsTrue( sVal )
{
	var bRet = false;

	if ("boolean" == typeof( sVal ))
	{
		bRet = sVal;
	}
	else if (null != sVal && sVal.length > 0)
	{
		var ch = sVal.toLowerCase().charAt(0);
		if( ch == "t" || ch == "y" || ch == "1" )
		{                
			bRet = true;
		}
	}

	return bRet;
}

function GetNumber( sValue, chSeparator )
{
	var nRes = "0";
	
	for( var c=0; c<sValue.length; ++c )
	{
		var chSymbol = sValue.charAt( c );
		if( IsDigit( chSymbol ) )
		{
			nRes+=chSymbol;
		}
		if( chSeparator == chSymbol )
			nRes += ".";
	}
	
	return parseFloat( nRes, 10 );
}

function IsNumber( sValue, chDecSep )
{
	var bRes = false;
	
	for( var c=0; c<sValue.length; ++c )
	{
		var chSymbol = sValue.charAt( c );
		if( !IsDigit( chSymbol ) && chDecSep != chSymbol  )
		{
			break;
		}
		if( c == sValue.length-1 )
		{
			bRes = true;
		}
	}
	
	return bRes;
}

function IsEmpty( sVal )
{
	var bRes = false;
	
	if( null == sVal || ("" == sVal && null != sVal.length) )
	{
		bRes = true;
	}
	
	return bRes;
}

function IsDigit( chSymbol )
{
	var bRes = false;
	var sNumbers = "0123456789";
	
	if( !IsEmpty( chSymbol ) )
	{
		bRes =  ( -1 != sNumbers.indexOf( chSymbol ))
	}
	
	return bRes;
}
var ETypeBrowser = 
{
	IE	   		: "Microsoft Internet Explorer",
	Netscape 	: "Netscape",
	Opera	   	: "Opera",
	Unknow   	: "Unknow"	
}

function PostExec( fn, oData )
{
	function fnPostHandler()
	{	
		fn( oData );
	}
	return window.setTimeout( fnPostHandler, 0 );
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();