﻿// JScript File

function OpenPublicViewHelp(url)
{
	mywin = open(url,'displaywindow','height=500,width=700,status=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes');
}

function openpopup(elementName){											
	var el = elementName.name.replace('btnVali','txtDate');
	mywin = open('calendar.aspx?ename='+el,'displaywindow','height=200,width=225,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');	
}

function dateChooserPostBack(postBackTxtBox) 
 {
	var PostBackIndicator = postBackTxtBox.name.replace('txtDate','toPostBack');
	var postBackNotice = postBackTxtBox.name.replace('txtDate','isPostBack');
 
	if(document.forms[0].elements[PostBackIndicator].value == '1')
	{
		document.forms[0].elements[postBackNotice].value = postBackTxtBox;		
		document.forms[0].submit();
	}
}


function date_onkeydown()
 {
	if(window.event.srcElement.readOnly)return;  
	var key_code = window.event.keyCode;  
	var oElement = window.event.srcElement;  
	
	//if shift + t are pressed insert current date
	if(window.event.shiftKey && String.fromCharCode(key_code) == "T")
	{	
		var d = new Date();
		/*oElement.value = String(d.getMonth() + 1).padL(2, "0") + "/" +  
		String(d.getDate()).padL(2, "0") + "/" +  d.getFullYear();*/
		oElement.value = String(d.getDate()).padL(2, "0") + "." +  
		String(d.getMonth()).padL(2, "0") + "." +  d.getFullYear();
		window.event.returnValue = 0;    
	} 
	//If ctr, alt and shift are not pressed, proceed
	if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey)
	{	
		//If a number key is pressed
		if ((key_code > 47 && key_code < 58) || (key_code > 95 && key_code < 106))
		{  
			//Convert numpad key value to keyboard numeric key value
			if (key_code > 95)key_code -= (95-47);
			
			//add the inserted char to the current location in the textbox value
			oElement.value = oElement.value.replace(/[x]/, String.fromCharCode(key_code));}
			
			//if backspace is pressed
			if (key_code == 8)
			{
				//if the value inserted does not match the regular expression of the input mask, 
			    if (!oElement.value.match(/^[x0-9]{2}\.[x0-9]{2}\.[x0-9]{4}$/))
			    {	
					//clear the inserted contents
					oElement.value = "xx.xx.xxxx";
			    }
			    //if it does match then delete a single character from cursor
			     oElement.value = oElement.value.replace(/([x\.]*)[0-9]([x\.]*)$/,function ($0, $1, $2)
			{
			
		var idx = oElement.value.search(/([x\.]*)[0-9]([xy\.]*)$/);
			/*if (idx >= 5){return $1 + "y" + $2;} 
			else if (idx >= 2){return $1 + "d" + $2;}
			else {return $1 + "m" + $2;}*/
			if (idx >= 5){return $1 + "x" + $2;} 
			else if (idx >= 2){return $1 + "x" + $2;}
			else {return $1 + "x" + $2;}
		} );
		window.event.returnValue = 0;
	}
	}    
	if (key_code != 9){event.returnValue = false;}
 }


 /// Opening Telerik Window
 function OpenRadWindow(url, radWinId, width, height, isModal, visibleStatusbar) {

   // alert(url);
     var wnd = radopen(url, radWinId);
     if (width == null || height == null)
         wnd.setSize(400, 400);
     else
         wnd.setSize(width, height);
     wnd.Center();
     wnd.set_visibleStatusbar(visibleStatusbar);
     //  wnd.Behavior = Telerik.WebControls.RadWindowBehaviorFlags.Close;
     wnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Resize);
     wnd.SetModal(isModal);     
     return false;
 }

