﻿if( typeof( Syncfusion_BaseEdit_version ) == "undefined" || Syncfusion_BaseEdit_version != "1.0" )
alert( "\"BaseEdit.js (1.0 version)\" not included!" );Syncfusion_MaskedEdit_version = "1.0";////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
function SF_MaskedEditTextBox( sRootID )
{ 
var self = this;SF_BaseEditTextBox.call( this, sRootID );////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
var c_sAttrPassivePromptCharacter = "passivePromptCharacter";var c_sAttrPromptCharacter = "promptCharacter";var c_sAttrPaddingCharacter = "paddingCharacter";////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
this.GetText = function()
{
var sRes = this.GetTextBox().value;return sRes;}
////////////////////////////////////////////////////////////////
this.GetValue = function()
{
this.EnsureTextBox();var sRes = "";var sValue = this.GetText();var oTextEl = this.GetTextBox();var sFormatMask = oTextEl.getAttribute( "formatMask" );var sPasivePromptCharacter = oTextEl.getAttribute( c_sAttrPassivePromptCharacter );var sPromptCaracter = oTextEl.getAttribute( c_sAttrPromptCharacter );var sPaddingCharacter = oTextEl.getAttribute( c_sAttrPaddingCharacter );var nValueLength = sValue.length;if( sFormatMask )
{
for( var c=0;c< sFormatMask.length;++c )
{
if( c >= nValueLength )
{
break;}
var chFormatMaskSymbol = sFormatMask.charAt( c );if( sPasivePromptCharacter == chFormatMaskSymbol || sPromptCaracter == chFormatMaskSymbol )
{
var sResCahr = sValue.charAt(c);if( sPasivePromptCharacter == sResCahr || sPromptCaracter == sResCahr )
{
sResCahr = sPaddingCharacter;}
sRes += sResCahr;}
}
}
else
{
sRes = sValue;} 
return sRes;}
////////////////////////////////////////////////////////////////
this.SetValue = function( sValue )
{
this.EnsureTextBox();if( !IsEmpty( sValue ) )
{
this.ValidateAndSet( sValue );}
}
///////////////////////////////////////////////////////////
this.Preparing = function()
{
if( !this.textbox.m_bIsPreparing && null != this.textbox )
{
this.textbox.m_bIsPreparing = true;this.textbox.m_sPassiveCharacter = this.textbox.getAttribute( c_sAttrPassivePromptCharacter );this.textbox.m_sPromptCaracter = this.textbox.getAttribute( c_sAttrPromptCharacter );this.textbox.m_bAllowPrompt = IsTrue( this.textbox.getAttribute( "allowPrompt" ) );}
}
function ReplaceStr( sText, sFormat, sChrBfr, sChrAftr )
{
var sRes = sText;if( sFormat )
{
for( var c=0;c<sFormat.length;++c )
{
var chFormat = sFormat.charAt( c );if( self.textbox.m_sPromptCaracter == chFormat )
{
if( sRes.length > c )
{
if( sChrBfr == sRes.charAt( c ) )
{
sRes = sRes.update( sChrAftr, c );}
}
}
}
}
return sRes;}
///////////////////////////////////////////////////////////
this.OnFocus = function( event, element )
{
this.keys.lastEvent = event;this.textbox = element;this.Preparing();var sValue = this.textbox.value;if( "" != ( this.textbox.m_sPromptCaracter && this.textbox.m_sPassiveCharacter ) )
{
var sFormatMask = self.GetTextBox().getAttribute( "formatMask" );this.textbox.value = ReplaceStr( sValue, sFormatMask, this.textbox.m_sPassiveCharacter, this.textbox.m_sPromptCaracter );}
if ( null == this.m_sSavingValue )
{
this.SaveDefaultValue();}
this.ProcessOnFocusIn( this.GetRoot(), event )
if( this.IsNetscape() )
{
this.SelectControlInNetscape();}
else
{
this.posCaret = this.CorrectCaretPos( 0 );this.hlp.moveCaret( this.textbox, this.posCaret );}
}
///////////////////////////////////////////////////////////
this.CorrectStartSelection = function()
{
this.posCaret = this.CorrectCaretPos( 0 );this.hlp.moveCaret( this.textbox, this.posCaret );}
///////////////////////////////////////////////////////////
this.OnBlur = function( event, element )
{
var sValue = this.textbox.value;if( "" != ( this.textbox.m_sPromptCaracter && this.textbox.m_sPassiveCharacter ) )
{
var sFormatMask = self.GetTextBox().getAttribute( "formatMask" );this.textbox.value = ReplaceStr( sValue, sFormatMask, this.textbox.m_sPromptCaracter, this.textbox.m_sPassiveCharacter );}
this.SaveDefaultValue();this.ProcessOnFocusOut( this.GetRoot(), event )
}
/////////////////////////////////////////////////////////////
this.ProcessSpecificKey = function()
{
if( this.keys.isMoveCaretKey() || 
this.keys.isTabKey() || 
this.keys.isAlphanumericKey()
)
{ 
return true;}
return this.ProcessKey();}
/////////////////////////////////////////////////////////////
this.ProcessKey = function()
{
return this.InternalProcessKey();}
/////////////////////////////////////////////////////////////
this.InternalProcessKey = function()
{
var bRes = false;do
{
var newText = this.textbox.value;var keyChar = this.keys.keyCharCode();var spaceSym = this.textbox.getAttribute( c_sAttrPromptCharacter );this.posCaret = this.hlp.getCaretPos( this.textbox );if( ETypeBrowser.Opera == this.GetTypeBrowser() && this.keys.isMoveCaretKey() )
{
bRes = true;break;}
else if( (ETypeBrowser.Opera == this.GetTypeBrowser() ) 
&& ( 0 == this.keys.lastEvent.keyCode ) )
{
var lenSelect = this.hlp.getSelectedLength( this.textbox );if( this.posCaret < newText.length + 1 ) 
{
if( lenSelect > 0 )
{
var formatMask = this.textbox.getAttribute( "formatMask" );var startPos = this.posCaret - lenSelect;var remSection = formatMask.substr( startPos, lenSelect );newText = this.UpdateText( newText, remSection, startPos );this.posCaret = startPos + lenSelect;} 
else
{
newText = this.FillChar( newText, spaceSym, 1, this.posCaret );this.posCaret++;}
}
}
else if( ETypeBrowser.Opera == this.GetTypeBrowser() && 
this.keys.isBackSpaceKey() )
{
this.posCaret = this.CorrectCaretPosBack( this.posCaret );if( this.posCaret > 0 )
{ 
newText = this.FillChar( newText, spaceSym, 1, this.posCaret - 1 );this.posCaret--;}
}
else if( this.keys.isPasteKey() )
{
var clipboardText = this.keys.bc.getClipboardData();newText = this.ProcessPasteValue( clipboardText );}
else if( this.keys.isCopyKey() )
{
bRes = true;break;} 
else if( this.keys.isDelKey() ) 
{
var lenSelect = this.hlp.getSelectedLength( this.textbox );if( this.posCaret < newText.length + 1 ) 
{
if( lenSelect > 0 )
{
var formatMask = this.textbox.getAttribute( "formatMask" );var startPos = this.posCaret - lenSelect;var remSection = formatMask.substr( startPos, lenSelect );if( "" == remSection )
{
newText = newText.substring( 0, startPos ) + newText.substr( startPos + lenSelect );this.posCaret = startPos;}
else
{
newText = this.UpdateText( newText, remSection, startPos );this.posCaret = startPos + lenSelect;} 
} 
else
{
newText = this.FillChar( newText, spaceSym, 1, this.posCaret );if( ( null != spaceSym )&&( "" != spaceSym ) )
{
this.posCaret++;}
}
}
}
else if( this.keys.isBackSpaceKey() )
{
this.posCaret = this.CorrectCaretPosBack( this.posCaret );if( this.posCaret > 0 )
{ 
newText = this.FillChar( newText, spaceSym, 1, this.posCaret - 1 );this.posCaret--;}
}
else if( this.keys.isAlphanumericKey() )
{
keyChar = this.CorrectCasing( keyChar, -1 );newText = this.UpdateText( newText, keyChar, this.posCaret );this.posCaret++;}
else if( ETypeBrowser.Opera == this.GetTypeBrowser() && "keydown" == this.keys.lastEvent.type )
{
keyChar = this.CorrectCasing( keyChar, -1 );newText = this.UpdateText( newText, keyChar, this.posCaret );this.posCaret++;bRes = false;}
else if( ETypeBrowser.IE == this.GetTypeBrowser() && "keydown" == this.keys.lastEvent.type )
{
bRes = true;}
else if( ETypeBrowser.Netscape == this.GetTypeBrowser() &&( "keypress" == this.keys.lastEvent.type ) )
{
if( ( this.keys.DEF_DEL != this.keys.lastEvent.keyCode )&&
( this.keys.lastEvent.keyIdentifier != "U+00007F" ) )
{
keyChar = this.CorrectCasing( keyChar, -1 );newText = this.UpdateText( newText, keyChar, this.posCaret );this.posCaret++;}
bRes = false;}
else if( ETypeBrowser.IE == this.GetTypeBrowser() && "keypress" == this.keys.lastEvent.type )
{
keyChar = this.CorrectCasing( keyChar, -1 );newText = this.UpdateText( newText, keyChar, this.posCaret );this.posCaret++;bRes = false;}
if(( this.textbox.m_sPromptCaracter == keyChar ) && !this.textbox.m_bAllowPrompt )
{
bRes = false;break;}
this.ValidateAndSet( newText, true );}
while( false );return bRes;}
/////////////////////////////////////////
this.ProcessPasteValue = function( clipboardText )
{ 
var newText = this.UpdateText( this.GetText(), clipboardText, this.posCaret );var tmp = "";for ( var i=0;i<newText.length;i++ )
tmp += this.CorrectCasing( newText.substr(i, 1) , i );newText = tmp;this.ValidateAndSet( newText, true );return newText;}
/////////////////////////////////////////
this.UpdateText = function ( newText,keyChar,posCarret )
{
return newText.update( keyChar, posCarret );}
//////////////////////////////////////////
this.FillChar = function( newText ,keyChar, len, posCarret )
{
return newText.fillChar( keyChar, len, posCarret );}
/////////////////////////////////////////
this.ValidateAndSet = function( value, bCanAttachEvent )
{ 
if( this.Validate( value ) && this.IsInRange( value ) )
{
value = this.ChangeCharacterCasingText( value );this.posCaret = this.CorrectCaretPos( this.posCaret );var sOldValue = this.textbox.value;this.hlp.setText( this.textbox, value, this.posCaret );if( IsTrue( bCanAttachEvent ) && !IsTrue( this.ProcessOnValueChange( this.GetRoot() , this.keys.lastEvent )) )
{
this.textbox.value = sOldValue;}
}
this.SetHiddenData( this.GetValue() );return this.textbox.value;}
//////////////////////////////////////////
this.ChangeCharacterCasingText = function( sValue )
{
var sRes = ( null != sValue ) ? sValue : "";var sCaseMode = this.textbox.getAttribute( "characterCasing" );if( "Normal" != sCaseMode )
{
sRes = ( "Upper" == sCaseMode ) ? sValue.toUpperCase() : sValue.toLowerCase();}
return sRes;}
////////////////////////////////////////////////////////////
this.IsInRange = function( nValue )
{
var bRes = true;var sUsageMode = this.textbox.getAttribute( "usageMode" );if( "Numeric" == sUsageMode )
{
var sSepSymbol = this.textbox.getAttribute( "decimalSeparator" );nValue = GetNumber( nValue, sSepSymbol );var nMinValue = this.textbox.getAttribute( "minValue" );var nMaxValue = this.textbox.getAttribute( "maxValue" );bRes = ( nValue >= nMinValue && nValue <= nMaxValue );}
return bRes;}
/////////////////////////////////////////////////////////////
this.ResetValueToDefault = function()
{
this.textbox.value = this.m_sSavingValue;}
///////////////////////////////////////////////////////////
this.SaveDefaultValue = function()
{
this.m_sSavingValue = this.textbox.value;;}
///////////////////////////////////////////////////////////
this.CorrectCaretPos = function( posCaret )
{
var formatMask = this.textbox.getAttribute( "formatMask" );var spaceSym = this.textbox.getAttribute( c_sAttrPromptCharacter );var value = this.textbox.value;if( null == posCaret )
{
posCaret = 0;}
if( "" != formatMask ) 
{
while( formatMask.substr( posCaret, 1 ) != spaceSym )
{
posCaret++;if( posCaret > value.length ) break;}
}
return posCaret;}
///////////////////////////////////////////////////////////
this.CorrectCaretPosBack = function( posCaret )
{
var formatMask = this.textbox.getAttribute( "formatMask" );var spaceSym = this.textbox.getAttribute( c_sAttrPromptCharacter );var value = this.textbox.value;if( "" != formatMask ) 
{
while( formatMask.substr( posCaret - 1, 1 ) != spaceSym )
{
posCaret--;if( posCaret < 1 ) break;}
}
return posCaret;}
////////////////////////////////////////////////////////////
this.CorrectCasing = function( keyChar, offset )
{
var fullMask = this.textbox.getAttribute( "fullMask" );var spaceSym = this.textbox.getAttribute( c_sAttrPromptCharacter );var pos = ( offset >= 0 ) ? offset : this.posCaret;for( var i=0;i < pos+1;i++ ) 
{
if( fullMask.substr( i, 1 ) == '<' || fullMask.substr( i, 1 ) == '>' )
pos++;}
for( var i=pos;i > -1 ;i-- )
{
if( fullMask.substr( i, 1 ) == '<' )
{
return keyChar.toLowerCase();}
if( fullMask.substr( i, 1 ) == '>' )
{
return keyChar.toUpperCase();}
}
return keyChar;}
this.EnsureTextBox = function()
{
if( null == this.textbox )
{
this.textbox = this.GetTextBox();}
}
}

MaskedEdit={
};

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();