function IsMSIE()
{
	return window.navigator.appName.toLowerCase().indexOf("microsoft") > -1;
}

function OpenWindowX(url, name, params){
	newWindow = window.open(url,name,params);
	newWindow.focus();
};

function OpenWindowY(url, urlparam, request, name, params){
	newWindow = window.open(url+'?'+urlparam+'='+escape(request),name,params);
	newWindow.focus(); 
};

function AxImageFormatWindow(Content){
	OpenWindowX(Content,'ImageWindow','width=550,height=720,toolbar=no,status=no,resizable=yes,scrollbars=yes');
};

function OpenWindow(url, name, width, height){
	OpenWindowX(url, name, 'width=' + width + ',height=' + height + ',screenX=40,screenY=40,toolbar=no,status=no,resizable=yes,scrollbars=yes');
};

function AxPreviewWindow(Content){
	PreviewWindow = window.open(Content,'PreviewWindow','width=660,height=700,screenX=10,screenY=40,toolbar=no,status=no,resizable=yes,scrollbars=yes');
	PreviewWindow.focus();
};

function AxWindowOpenScrollAbleWH(Content, Width, Height)
{
	AxWindowOpenScrollAbleTWH(Content, 'EditWindow', Width, Height);	
};

function AxWindowOpenScrollAbleTWH(Content, Target, Width, Height)
{
	windowwidth = (screen.availWidth/2)- Width/2;
    windowheight = (screen.availHeight/2) - Height/2;

	EditWindow = window.open('about:blank',Target,'width=' + Width + ',height=' + Height + ',top=' + windowheight + ',left=' + windowwidth + ',screenX=40,screenY=40,toolbar=no,status=no,resizable=yes,scrollbars=yes');
	EditWindow.document.write('Loading...');
	EditWindow.document.close();
	EditWindow.location = Content;
	EditWindow.focus();
}


function AxCalendarWindow(Content){
	CalendarWindow = window.open(Content,'CalendarWindow','width=155,height=205,toolbar=no,status=no,resizable=no,scrollbars=no');
	CalendarWindow.focus();
};

function AxHelpWindow(Content){
	CalendarWindow = window.open('http://help.axinom.de'+Content,'HelpWindow','width=1024,height=768,toolbar=no,status=no,resizable=no,scrollbars=no');
	CalendarWindow.focus();
};

function AxGetTopWin(startWindow)
{
	var topWin = startWindow;
	if(topWin)
	{
		while(topWin.parent != undefined && topWin.parent != topWin) 
		{
			topWin = topWin.parent;
		}
	}
	return topWin;
}

//Usage: AxReloadPage(window) or AxReloadPage(opener)
function AxReloadPage(startWindow)
{
	if(startWindow)
	{		
		var topWin = AxGetTopWin(startWindow);
		if(topWin && topWin.location)
			topWin.location.reload();
	}
}

// Reloads the page with the specified mode.
function AxChangeMode(theMode)
{
	var theRegExp = new RegExp('mode=\\d?', 'i');

	if(parent.location.toString().match(theRegExp))
		parent.location = parent.location.toString().replace(theRegExp, 'mode=' + theMode);	
	else
		if( parent.location.toString().match(new RegExp('\\\?')) )
			parent.location = parent.location.toString() + "&Mode=" + theMode;
		else
			parent.location = parent.location.toString() + "?Mode=" + theMode;
}

function AxContains(container, child)
{
	var parentContainer = child;
	do
	{
		if(parentContainer == container)
		{
			return true;
		}
		parentContainer = parentContainer.parentNode;
	}
	while(parentContainer != undefined && parentContainer != parentContainer.parentNode);
	
	return false;
}

// Necessary for hyperlinks in cases
// when void(null) doesn't work.
function AxDoNothing(){}

// Finds the first form-element in the document
// and sets target="_blank" to it
function AxSetTargetBlankToForm()
{
	if(document.forms.length)
	{
		var firstForm = document.forms[0]
		firstForm.target = "_blank";		
	}
}

// Finds the first form-element in the document
// and removes target-attribute from it.
function AxRemoveTargetFromForm()
{
	if(document.forms.length)
	{		
		var firstForm = document.forms[0]
		firstForm.target = "";		
	}
}


function GetScrollLeft(wnd)
{
	if(IsMSIE())
	{
		//a little bit hacking: sometimes it is in html object, sometimes in body...		
		return Math.max(wnd.document.documentElement.scrollLeft, wnd.document.body.scrollLeft); 
	}
	else
	{
		return wnd.scrollX;
	}
}

function GetScrollTop(wnd)
{
	if(IsMSIE())
	{
		//a little bit hacking: sometimes it is in html object, sometimes in body...		
		return Math.max(wnd.document.documentElement.scrollTop, wnd.document.body.scrollTop); 
	}
	else
	{
		return wnd.scrollY;
	}
}

function GetRandomNumber()
{
	return (Math.round((Math.random()*10000000)));
}



// Override standart  function for Firefox
function WebForm_FireDefaultButton(event, target) {
var element = event.target || event.srcElement;
if (!__defaultFired && event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {
 var defaultButton;
 if (__nonMSDOMBrowser) {
 defaultButton = document.getElementById(target);
 }
 else {
 defaultButton = document.all[target];
 }
 if (defaultButton && typeof(defaultButton.click) != "undefined") {
 defaultButton.click();
 event.cancelBubble = true;
 if (event.stopPropagation) event.stopPropagation();
 return false;
 }
 }
 return true;
}


function WebForm_FireDefaultButton(event, target) {
var element = event.target || event.srcElement;        
        if (event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {
    //  !__defaultFired &&    
    //  if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        }
        else {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}


function CountrySelection_Disable() {

countryField.selIndex=countryField.selectedIndex;
if(countryField!=undefined){countryField.onchange=new Function('countryField.selectedIndex=countryField.selIndex;');}
if(countryField!=undefined && countryFieldDisabled!=undefined && countryField.selectedIndex>-1){countryFieldDisabled.value=countryField.options[countryField.selectedIndex].text;}

regionField.selIndex=regionField.selectedIndex;
if(regionField!=undefined){regionField.onchange=new Function('regionField.selectedIndex=regionField.selIndex;');}
if(regionField!=undefined && regionFieldDisabled!=undefined && regionField.selectedIndex>-1){regionFieldDisabled.value=regionField.options[regionField.selectedIndex].text;}

stateField.selIndex=stateField.selectedIndex;
if(stateField!=undefined){stateField.onchange=new Function('stateField.selectedIndex=stateField.selIndex;');}
if(stateField!=undefined && stateFieldDisabled!=undefined && stateField.selectedIndex>-1){stateFieldDisabled.value=stateField.options[stateField.selectedIndex].text;}

}