// general functions
	function navigateTo(strUrl,urlTarget){
		//check if the url should be opened in an new window
		if (urlTarget != null && urlTarget != ""){
			switch( urlTarget ) {
			case "_new":
				window.open(strUrl);
				break;
			default:
				alert( 'Not an valid url target.');				
				return null;
			}
		}else{
			location.href=strUrl;
		}
	}
	
	function OpenWizard(strUrl){
		showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Wizards/WizardMain.aspx?'+ strUrl,window,'dialogHeight: 406px; dialogWidth: 500px; help: No; resizable: No; status: yes; scroll: No;');
	}
	
	function OpenWizardKeyWords(strUrl){
		showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Wizards/WizardMain.aspx?Url='+ strUrl,window,'dialogHeight: 406px; dialogWidth: 500px; help: No; resizable: No; status: yes; scroll: No;');
	}
	
	function OpenDialog(strUrl,strHeight,strWidth,strTitle,strCategory,strKeyWord){
		var strHeight = (parseInt(strHeight) + 20) + "px";
		showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/dialogMain.aspx?Url='+ strUrl + '&Height=' + strHeight + '&Width=' + strWidth + '&Title=' + strTitle + ((typeof strCategory != "undefined")? '&Category=' + strCategory + '&KeyWord=' + strKeyWord : ''),window,'dialogHeight:' + strHeight + '; dialogWidth:' + strWidth + '; help: No; resizable: No; status: yes; scroll: No;');
	}
	
	function OpenDialogDefined(strUrl,strHeight,strWidth,strTitle,strFeatures){
		var strHeight = (parseInt(strHeight) + 20) + "px";
		showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/dialogMain.aspx?Url='+ strUrl + '&Height=' + strHeight + '&Width=' + strWidth + '&Title=' + strTitle,window,'dialogHeight:' + strHeight + '; dialogWidth:' + strWidth + ';' +strFeatures);
	}
	
	
	function OpenTabDialog(strUrl,strTitle){
		showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/TabDialog.aspx?Url='+ strUrl +'&Title='+ strTitle +'',window,'dialogHeight: 481px; dialogWidth: 456px; help: No; resizable: No; status: yes; scroll: No;');
	}
	
	/**/
	function OpenDialogWithReturnValues(strUrl,strHeight,strWidth,strTitle){
		var strHeight = (parseInt(strHeight) + 20) + "px";
		var s = showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/dialogMain.aspx?Url='+ strUrl + '&Height=' + strHeight + '&Width=' + strWidth + '&Title=' + strTitle,window,'dialogHeight:' + strHeight + '; dialogWidth:' + strWidth + '; help: No; resizable: No; status: yes; scroll: No;');
		return s;
	}
	
	/**/
	
	/*
	-----------------------------------------------------------------
	Function:	OpenConfirmDialog
	Created:	2002-10-25 : Joakim Westerlund
	Summary:	This function should be used instead of javascripts alerts, confirm and errors...
	Return:		Returns the value you specified by each button click
	Notes:		If the user clicks on close button in header then the return value are undefined
	-----------------------------------------------------------------
	Usage:
		strButtonTexts = 'keyword1,keyword2,keyword3'; (text on buttons in the dialog category) (btnSaveAsNew,btnOverwrite,btnCancel)
		strDefaultButton = 'keyword1'; (this sets the first sent in button as the defaultbutton in the above example)
		strButtonReturnValues = 'true,false,cancel'; (what ever you want) (this is the values that the buttonclick events return to you)
		strHeader = 'keyword'; (for header text in the dialog category)
		strDescription = 'keyword'; (for Description text in the dialog category)
		strTitle = 'keyword'; (for Window title text in the dialog category)
		strAction = 'confirm'; (the action image you should display in Confirm Dialog) (confirm,varning,error)
	*/
	function OpenConfirmDialog(strButtonTexts,strDefaultButton,strButtonReturnValues,strHeader,strDescription,strTitle,strAction){
		return OpenExtendedConfirmDialog(strButtonTexts,strDefaultButton,strButtonReturnValues,strHeader,strDescription,strTitle,strAction,false,false,'');
	}

	/*
	-----------------------------------------------------------------
	Function:	OpenExtendedConfirmDialog
	Created:	2004-06-15 : Vladimir Ljepoja
	Summary:	This function should be used instead of javascripts alerts, confirm and errors...
	Return:		Returns the value you specified by each button click or value that user entered in adequate 
				text box within dialog. The visibility of mention text box is controled by "strUseTextField"
				parameter. If returned value presents text of TextBox field, it will contain "txt_" prefix concated
				to text defined by user within mentioned field. Mentioned prefix is added to avoid
				conflict that can be arrised if user enters for example "false" value in text field. 
				In that case 'txt_false' is different from 'false' and that makes difference between
				clicked "btnContinue" and "btnCancel" buttons.
	Notes:		If the user clicks on close button in header then the return value are undefined
	-----------------------------------------------------------------
	Usage:
		strButtonTexts = 'keyword1,keyword2,keyword3'; (text on buttons in the dialog category) (btnSaveAsNew,btnOverwrite,btnCancel)
		strDefaultButton = 'keyword1'; (this sets the first sent in button as the defaultbutton in the above example)
		strButtonReturnValues = 'true,false,cancel'; (what ever you want) (this is the values that the buttonclick events return to you).
								NOTE: (If user wants to use TextBox field 
								within dialog, he has to insert in this parameter "useTextField" value (e.g. 'useTextField,false,cancel'). 
								This value will influence on adequate button to return text 
								defined within TextBox field). This will be hapened only if "strUseTextField" parameter
								is set on 'true' value, otherwise button will return "useTextField" word.
		strHeader = 'keyword'; (for header text in the dialog category)
		strDescription = 'keyword'; (for Description text in the dialog category)
		strTitle = 'keyword'; (for Window title text in the dialog category)
		strAction = 'confirm'; (the action image you should display in Confirm Dialog) (confirm,varning,error)
		strUseTextField = 'true' or 'false' (in the confirm dialog will be shown text box control)
		strRequiredTextField = 'true' or 'false' (is value in text box control required or not)
		strTextValue = "whatever" (initial value of text box)
	*/	
	function OpenExtendedConfirmDialog(strButtonTexts,strDefaultButton,strButtonReturnValues,strHeader,strDescription,strTitle,strAction,strUseTextField,strRequiredTextField,strTextValue){
		var Params = '&strButtonTexts='+ strButtonTexts +'&strDefaultButton='+ strDefaultButton +'&strButtonReturnValues='+ strButtonReturnValues +'&strHeader='+ strHeader +'&strDescription='+ strDescription +'&strAction='+ strAction +'&bolUseFormatting=false'+'&boolUseTextField='+strUseTextField+'&boolRequiredTextField='+strRequiredTextField+'&strTextValue='+strTextValue;
		var s = showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/ConfirmDialog.aspx?Url='+ WEBROOT +'CORE/SpirelloSystem/Dialogs/Confirm/ConfirmClientSide.aspx?'+ Params +'&Height=154px&Width=300px&Title=' + strTitle,window,'dialogHeight:174px; dialogWidth:300px; help: No; resizable: No; status: yes; scroll: No;');
		return s;
	}
	
	//This function does not use a keyword for description text
	function OpenConfirmDialogFormatted(strButtonTexts,strButtonReturnValues,strHeader,strDescription,strTitle,strAction){
		var Params = '&strButtonTexts='+ strButtonTexts +'&strButtonReturnValues='+ strButtonReturnValues +'&strHeader='+ strHeader +'&strDescription='+ strDescription +'&strAction='+ strAction +'&bolUseFormatting=true';
		var s = showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/ConfirmDialog.aspx?Url='+ WEBROOT +'CORE/SpirelloSystem/Dialogs/Confirm/ConfirmClientSide.aspx?'+ Params +'&Height=154px&Width=300px&Title=' + strTitle,window,'dialogHeight:174px; dialogWidth:300px; help: No; resizable: No; status: yes; scroll: No;');
		return s;
	}
	// This function has same funcionality as OpenExtendedConfirmDialog function except one more parameter
	// This function open dialog with information for Elements length
	function OpenExtendedConfirmDialogForElements(strButtonTexts,strDefaultButton,strButtonReturnValues,strHeader,strDescription,strTitle,strAction,strUseTextField,strRequiredTextField,strTextValue){
		var Params = '&strButtonTexts='+ strButtonTexts +'&strDefaultButton='+ strDefaultButton +'&strButtonReturnValues='+ strButtonReturnValues +'&strHeader='+ strHeader +'&strDescription='+ strDescription +'&strAction='+ strAction +'&bolUseFormatting=false'+'&boolUseTextField='+strUseTextField+'&boolRequiredTextField='+strRequiredTextField+'&strTextValue='+strTextValue;
		var s = showModalDialog(WEBROOT + 'CORE/SpirelloSystem/Dialogs/ConfirmDialog.aspx?Url='+ WEBROOT +'CORE/SpirelloSystem/Dialogs/Confirm/ConfirmClientSide.aspx?'+ Params +'&Height=154px&Width=300px&Title=' + strTitle,window,'dialogHeight:174px; dialogWidth:300px; help: No; resizable: No; status: yes; scroll: No;');
		return s;
	}
	
	function ShowWarning(ErrorMsg,ErrorTitle)
	{
		OpenConfirmDialog('btnOk','btnOk','false','',ErrorMsg,ErrorTitle,'error');
	}
	
	function DisplayJavaScriptError(e){
		var strError = "Error:\n";
		strError += e.description + "\n";
		alert(strError);
	}
	
	//Function for open new windows with different features
	function openCMSWindow(url,width,height,name,features){
		width = (width > 0) ? ",width=" + width : "";
		height = (height > 0) ? ",height=" + height : "";
		name = (name != null) ? name : "";
		features = (features != null) ? ","+ features : "";
			
		var newWin = window.open(url,name,""+ width +""+ height +""+ features);
		newWin.focus();
	}
	//Open the SpirelloCMS help window
	function openCMSHelpWindow(){
		//"http://localhost/dev/spirello30/robohelp_test/Spirello-HelpFile.htm"
		var url = WEBROOT + "HELP/Swedish/Spirello-HelpFile.htm";
		openCMSWindow(url,700,600,"SpirelloCMSHelp","resizable=yes,status=no");
	}
		

	// name - name of the cookie
	// value - value of the cookie
	// [expires] - expiration date of the cookie (defaults to end of current session)
	// [path] - path for which the cookie is valid (defaults to path of calling document)
	// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
	// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
	// * an argument defaults when it is assigned null as a placeholder
	// * a null placeholder is not required for trailing omitted arguments
	function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
	}

	// name - name of the desired cookie
	// * return string containing value of specified cookie or null if cookie does not exist
	function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
	}

	// name - name of the cookie
	// [path] - path of the cookie (must be same as path used to create cookie)
	// [domain] - domain of the cookie (must be same as domain used to create cookie)
	// * path and domain default if assigned null or omitted if no explicit argument proceeds
	function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	}

	// date - any instance of the Date object
	// * hand all instances of the Date object to this function for "repairs"
	function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
	}

	//Adds an gets the index to add values in an array, used instead of push,
	function ArrayPushIndex(arr){
		return (arr.length > 0)?arr.length:0;
	}
	
	
	function SwapImage(id,imgSrc){
		document.getElementById(id).src = imgSrc;
	}
//

