var strGlobalDateFormat = 'dd-MM-yy' 

fmtMoney = function( n, c, d, t ) {
	var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec( n + "" ) ), x = m[1].length % 3;
	return ( x ? m[1].substr( 0, x ) + t : "" ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : "" );
};


addNamespace("Global")
addNamespace("Global.TextBox")
addNamespace("Global.Form")


Global.Loading_class = function()
{
	this.refWindow = null 	
	
	//this.fnOnError = function(res){Alert('Er is een fout opgetreden bij het uitvoeren van een functie');Global.Loading.Hide()}
	//this.fnOnTimeOut = function(res){Alert('Er is een timeout opgetreden bij het uitvoeren van een functie'); Global.Loading.Hide()}
}

Global.Loading_class.prototype.strMsgLoadingSmall = '<img="images/mootLoader108.gif"> Bezig met laden...'
Global.Loading_class.prototype.strMsgLoadingLarge = '<img="images/mootLoader175.gif"> Bezig met laden...'
Global.Loading_class.prototype.strMsgLoadingGSmall = '<img="images/mootLoaderGrey108.gif"> Bezig met laden...'
Global.Loading_class.prototype.strMsgLoadingGLarge = '<img="images/mootLoaderGrey175.gif"> Bezig met laden...'
Global.Loading_class.prototype.strMsgLoadingSmallUrl = 'images/mootLoader108.gif'
Global.Loading_class.prototype.strMsgLoadingLargeUrl = 'images/mootLoader175.gif'
Global.Loading_class.prototype.strMsgLoadingGSmallUrl = 'images/mootLoaderGrey108.gif'
Global.Loading_class.prototype.strMsgLoadingGLargeUrl = 'images/mootLoaderGrey175.gif'

Global.Loading_class.prototype.SetWindowTitleLoading = function(refWindow, strMessage)
{
	if (strMessage == null)
		strMessage = "Bezig met laden"
	var loading = document.createElement("img")
	loading.src=this.strMsgLoadingGSmallUrl
	var message = document.createTextNode(" " + strMessage)
	refWindow.SetTitleNodes([message, document.createElement("br"), loading])	
}

Global.Loading_class.prototype.InitializeGridLoading = function(refGrid, strMessage)
{
	if (strMessage == null)
		strMessage = "Bezig met laden"
	refGrid.loadingState.strMessage = strMessage
	refGrid.loadingState.InitializeFeedbackLayer = Global.Loading_class.prototype.InitializeGridLoadingLayer.bind(refGrid.loadingState)
	
}

Global.Loading_class.prototype.InitializeGridLoadingLayer = function()
{

	while(this.feedbackLayer.childNodes.length>0)
	{
		this.feedbackLayer.removeChild(this.feedbackLayer.firstChild)
	}
	var loading = document.createElement("img")
	loading.src=Global.Loading_class.prototype.strMsgLoadingLargeUrl
	var message = document.createTextNode(" " + this.strMessage)
	
	this.feedbackLayer.appendChild(message)
	this.feedbackLayer.appendChild(document.createElement("br"))
	this.feedbackLayer.appendChild(loading)
	
	
}



Global.Loading_class.prototype.CheckAjaxResponse = function(res)
{
	if (res && res.error && res.error.Message)
	{
		alert(res.error.Message)
		return false
	}
	else
	{
		return true
	}
	
}


Global.Loading_class.prototype.Show = function(strTitle, strMessage)
{
	if (this.refWindow)
		this.refWindow.Close()
	
	if (strMessage == null)
		strMessage = 'Bezig met laden'
	
	var nodes = new Array()
	var baseNode = document.createElement("div")
	baseNode.className = "containerLoading"
	nodes.push(baseNode)
	baseNode.appendChild(document.createTextNode(strMessage))
	baseNode.appendChild(document.createElement("br"))
	var imgLoading = document.createElement("img")
	baseNode.appendChild(imgLoading)
	imgLoading.src = this.strMsgLoadingLargeUrl
	
	
	this.refWindow = Aspacts.Script.Utils.InlineWin.System.OpenLoadingWindow(nodes, 'loading', 300, 90);
	
				
}

Global.Loading_class.prototype.Hide = function(strMessage)
{
	if (this.refWindow)
		this.refWindow.Close()
	this.refWindow = null
}
Global.Loading = new Global.Loading_class()


Global.TextBox.SetDefaultAction = function(target, fnAction)
{
	target.defaultAction = fnAction
	Aspacts.Script.Utils.Core.ImplementEvent(target)
	target.addEventListener('keydown', Global.TextBox.ExecuteDefaultAction, true)
	
}
Global.TextBox.ExecuteDefaultAction = function(evt)
{
	if (evt == null)
	{
		evt =event
		
	}
	if (evt.keyCode ==13)
	{
		
		if(evt.stopPropagation)
			evt.stopPropagation()
		if(evt.preventDefault)
			evt.preventDefault()
		evt.cancelBubble=true
		this.defaultAction()
		
		//return refTarget.onclick()
		
	}	
	
}

Global.Form.SetTarget = function()
{
    var myform;
    
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
    {
        myform = document.Form1;
    }
    else
    {
    
       myform = document.forms["Form1"];
    }
    if(myform)
		myform.action = location.href
}
Global.Form.SetTarget()


Global.OpenPopin = function(strAlias, intWidth, intHeight)
{
	if(!intWidth)
		intWidth = 800
	if(!intHeight)
		intHeight = 500
	var strPageUrl
	
	strPageUrl  = Global.MainApp.CategoryMapping.GetUrl(strAlias, '')
	
	var refWin = Aspacts.Script.Utils.InlineWin.System.OpenWindow(Global.ParsePopupUrl(strPageUrl), 'editOffer', intWidth, intHeight);
	refWin.AddButton('btnClose', 'Sluiten', 'Sluit het venster', 'CloseWindow', true, "btnTxt btnBackGrnd");
	return refWin	
}

Global.ParsePopupUrl=  function(strUrl)
{     
	if (typeof(btSiteMode) != "undefined")
	{
		if (btSiteMode && btSiteMode==1)
		{
			if (strUrl.indexOf('?') > -1)
				strUrl += "&"
			else
				strUrl += "?"
			strUrl +=  'btSiteMode=1'
		}	
	}
	return strUrl
	
}

Global.OpenPopinUrl = function(strUrl, intWidth, intHeight)
{
	if(!intWidth)
		intWidth = 800
	if(!intHeight)
		intHeight = 500
	
	
	var refWin = Aspacts.Script.Utils.InlineWin.System.OpenWindow(Global.ParsePopupUrl(strUrl), 'editOffer', intWidth, intHeight);
	refWin.AddButton('btnClose', 'Sluiten', 'Sluit het venster', 'CloseWindow', true, "btnTxt btnBackGrnd");
	return refWin	
}

function isNumeric(x) 
{
	// I use this function like this: if (isNumeric(myVar)) { } 
	// regular expression that validates a value is numeric 
	var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452. 
	// compare the argument to the RegEx 
	// the 'match' function returns 0 if the value didn't match 
	var result = x.match(RegExp);
	if (result==null) 
		return false
	else
		return result;
}


function copyPrototype(descendant, parent) {
    var sConstructor = parent.toString();
    var aMatch = sConstructor.match( /\s*function (.*)\(/ );
    if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
    for (var m in parent.prototype) {
        descendant.prototype[m] = parent.prototype[m];
    }
};
	
