
function modalDialogShow_IE(url,width,height) //IE
{
	return window.showModalDialog(url,window,
		"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:Yes;help:No;Resizable:Yes;Maximize:Yes");
};

function modalDialogShow_Moz(url,width,height) //Moz
{
    var left = screen.availWidth/2 - width/2;
    var top = screen.availHeight/2 - height/2;
    activeModalWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
    window.onfocus = function(){if (activeModalWin.closed == false){activeModalWin.focus();};};
};

var sActiveAssetInput;

function setAssetValue(v){
    document.getElementById(sActiveAssetInput).value = v;
};

function openAsset(s){
	sActiveAssetInput = s
	if(navigator.appName.indexOf('Microsoft')!=-1)
		document.getElementById(sActiveAssetInput).value=modalDialogShow_IE("/core/coreSrc/externalSrc/WYSIWYG/assetManager/assetmanager.asp",640,465); //IE	
	else
		modalDialogShow_Moz("/core/coreSrc/externalSrc/WYSIWYG/assetManager/assetmanager.asp",640,465); //Moz	
};
	// -----------------------------------------------------------------------------
	// the version of javascript supported
	var jsVersion = 1.1;
	// -----------------------------------------------------------------------------

	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

	// Just return wheter Flash was found or not
	function detectFlash(){
	 var testFlash = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);		
	 return testFlash;
	}
	
	// Render Flash if Flash was found, otherwise return false
	function renderFlash(theName,thePath,theWidth,theHeight,theBgColor){
	 var flashDetected = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	  if(flashDetected) { 
		var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
		+ 'width="'+theWidth+'" height="'+theHeight+'"'
		+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
		+ '<param name="movie" value="'+thePath+'" /><param name="quality" value="high" />'
		+ '<param name="bgcolor" value="'+theBgColor+'" />'
		+ '<embed src="'+thePath+'" quality="high" bgcolor="'+theBgColor+'" '
		+ 'width="'+theWidth+'" height="'+theHeight+'" name="'+theName+'" align="middle"'
		+ 'play="true"'
		+ 'loop="false"'
		+ 'quality="high"'
		+ 'allowScriptAccess="sameDomain"'
		+ 'type="application/x-shockwave-flash"'
		+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
		+ '<\/embed>'
		+ '<\/object>';
		document.write(oeTags);   // embed the flash movie
		return true;
	  } else {  
		return false;
	  }
	}






// -----------------------------------------------------------------------------
// GENERATED BY FLASH
// -----------------------------------------------------------------------------
	// JavaScript helper required to detect Flash Player PlugIn version information
	function JSGetSwfVer(i){
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
				descArray = flashDescription.split(" ");
				tempArrayMajor = descArray[2].split(".");
				versionMajor = tempArrayMajor[0];
				versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			} else {
				flashVer = -1;
			}
		}
		// MSN/WebTV 2.6 supports Flash 4
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		// WebTV 2.5 supports Flash 3
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		// older WebTV supports Flash 2
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		// Can't detect in all other cases
		else {
			flashVer = -1;
		}
		return flashVer;
	} 
	// -----------------------------------------------------------------------------	
	// -----------------------------------------------------------------------------
	// If called with no parameters this function returns a floating point value 
	// which should be the version of the Flash Player or 0.0 
	// ex: Flash Player 7r14 returns 7.14
	// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
	function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
		reqVer = parseFloat(reqMajorVer + "." + reqRevision);
		// loop backwards through the versions until we find the newest version	
		for (i=25;i>0;i--) {	
			if (isIE && isWin && !isOpera) {
				versionStr = VBGetSwfVer(i);
			} else {
				versionStr = JSGetSwfVer(i);		
			}

			if (versionStr == -1 ) { 
				return false;
			} else if (versionStr != 0) {
				if(isIE && isWin && !isOpera) {
					tempArray         = versionStr.split(" ");
					tempString        = tempArray[1];
					versionArray      = tempString .split(",");				
				} else {
					versionArray      = versionStr.split(".");
				}
				versionMajor      = versionArray[0];
				versionMinor      = versionArray[1];
				versionRevision   = versionArray[2];
				
				versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
				versionNum        = parseFloat(versionString);
				// is the major.revision >= requested major.revision AND the minor version >= requested minor
				if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
					return true;
				} else {
					return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
				}
			}
		}	
		return (reqVer ? false : 0.0);
	}	
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// GET OBJECTS /////////////////////////////////
function getFormObject(objectName){
	return document.forms[objectName];
};

function getHTMLObject(objectName){
// Old browsers
	if (!document.getElementById) {
		getHTMLObject = function(objectName){
			if (document.layers) return document[objectName];
			if (document.all) return document.all[objectName];
			return null; // expect the unexpected
		}
	}
// New browsers
	return document.getElementById(objectName);
};


// TOGGLE DISPLAY /////////////////////////////////
function hideItem(theItem){
		getHTMLObject(theItem).style.display	= "none";
};

function showItem(theItem){
		getHTMLObject(theItem).style.display	= "block";	
};

function toggleShowItem(theItem){
	if(getHTMLObject(theItem).style.display	== "block"){
		getHTMLObject(theItem).style.display	= "none";
	}else{
		getHTMLObject(theItem).style.display	= "block";
	}
};

// EMAIL /////////////////////////////////
function renderEmail(username,hostname,subject){
	window.location = "mail" + "to:" + username + "@" + hostname +"?"+ subject;
};

// OPEN/CLOSE PAGE /////////////////////////////////
function closePage(){
	window.close();
};

// FORM - SELECT /////////////////////////////////
function moveOption(formName,fromField,toField,selectToField){
	var theForm = getFormObject(formName);
	fromField	= theForm[fromField];
	toField		= theForm[toField];
	fromLength	= fromField.length;
	
	// Get selected options in FromField
	for(i=0;i<fromLength;i++){
		// Create new option in ToField
		if(fromField.options[i].selected==true){
		  toField.options[toField.length] = new Option(fromField.options[i].text,fromField.options[i].value);
  		  fromField[i] = null;

			// Select toField
			if(selectToField==true){
				for (i=0;i<toField.length;i++){
					toField[i].selected=true;
				}
			}

			return true;
		}
	}

	return false;	
};
/* MAIN FUNCTIONS */
function winBRopen(theURL, theName, theWidth, theHeight) { 
	  var theLeft 	= (screen.width - theWidth) / 2;
	  var theTop 	= (screen.height - theHeight) / 2;
	  var theProps 	= "width="+theWidth+",height="+theHeight+",left="+theLeft+",top="+theTop+",scrollbars=yes,resizable=no";
	  theWindow		= window.open(theURL, theName, theProps);
	  theWindow.creator = self;
	  theWindow.window.focus();
};

function goto_URL(object) {
	    window.location.href = object.options[object.selectedIndex].value;
};


/* PICKERS */
function pickColor(fieldName,colorValue){
	opener.document.getElementById(fieldName).style.background = colorValue;
	opener.document.getElementById(fieldName).value 			= colorValue;	
	window.close();
};

// SMODE CONTACT /////////////////////////////////
function contactSmode(theHeader,theMessage){
	  var theWidth	= 510
	  var theHeight = 400
	  var theLeft 	= Math.round((screen.width - theWidth) / 2);
	  var theTop 	= Math.round((screen.height - theHeight) / 2);
	  var theProps 	= "width="+theWidth+",height="+theHeight+",left="+theLeft+",top="+theTop+",scrollbars=yes,resizable=yes";
	  theWindow		= window.open("/core/corePage/popUps/contactSmode.asp?message="+theMessage+"&header="+theHeader+"", "Kontakta_Smode", theProps);
	  theWindow.creator = self;
	  theWindow.window.focus();
};// Remember to list validation uppside down so that the first field
// i the form will be focus() last.

function validateNewPage(){
	var theForm 	= getFormObject("newPage");
	var status 		= true;

	if(validateString(theForm.link_external,"MUST_HAVE_INDEXOF_IF_GIVEN","http")==false){status  = false;}
	if(validateDate(theForm.meta_expire,"MUST_BE_IF_GIVEN",0)==false){status  = false;}
	if(validateLength(theForm.meta_description,"MIN",3)==false){status  = false;}
	if(validateLength(theForm.meta_keywords,"MIN",3)==false){status  = false;}
	if(validateDate(theForm.page_expire_date,"MUST_BE",0)==false){status  = false;}
	if(validateDate(theForm.page_publish_date,"MUST_BE",0)==false){status  = false;}
	//if(validateLength(theForm.text_content,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.text_teaser,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.text_head,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.page_title,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.page_name,"MIN",1)==false){status  = false;}

	return statusControl(status,validateNewPageErrorText);
};

function validateUpdatePage(){
	var theForm 	= getFormObject("updatePage");
	var status 		= true;

	if(validateString(theForm.link_external,"MUST_HAVE_INDEXOF_IF_GIVEN","http")==false){status  = false;}
	if(validateDate(theForm.meta_expire,"MUST_BE_IF_GIVEN",0)==false){status  = false;}
	if(validateLength(theForm.meta_description,"MIN",3)==false){status  = false;}
	if(validateLength(theForm.meta_keywords,"MIN",3)==false){status  = false;}
	if(validateDate(theForm.page_expire_date,"MUST_BE",0)==false){status  = false;}
	if(validateDate(theForm.page_publish_date,"MUST_BE",0)==false){status  = false;}
	//if(validateLength(theForm.text_content,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.text_teaser,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.text_head,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.page_title,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.page_name,"MIN",1)==false){status  = false;}

	return statusControl(status,validateNewPageErrorText);
};

function validateUpdateUser(){
	var theForm 	= getFormObject("updateUser");
	var status 		= true;

	if(validateExactMatch(theForm.userPassword,theForm.userPassword2)==false){status  = false;}
	if(validateLength(theForm.userPhone,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userEmail,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userCountry,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userCity,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userZipcode,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userStreet,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userEName,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userFName,"MIN",1)==false){status  = false;}
	return statusControl(status,validateUpdateUserErrorText);	
};

function validateCreateUser(){
	var theForm 	= getFormObject("newUser");
	var status 		= true;

	if(validateLength(theForm.userPassword,"MIN",1)==false){status  = false;}
	if(validateExactMatch(theForm.userPassword,theForm.userPassword2)==false){status  = false;}
	if(validateLength(theForm.userPhone,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userEmail,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userCountry,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userCity,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userZipcode,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userStreet,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userEName,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.userFName,"MIN",1)==false){status  = false;}
	return statusControl(status,validateUpdateUserErrorText);
};

function validateUpdateSiteContacts(){
	var theForm 	= getFormObject("updateSettings");
	var status 		= true;

	if(validateLength(theForm.supportMobile,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportPhone,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportCountry,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportCity,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportZipCode,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportAddress,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportEmail,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.supportName,"MIN",1)==false){status  = false;}

	if(validateLength(theForm.adminMobile,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminPhone,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminCountry,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminCity,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminZipCode,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminAddress,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminEmail,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.adminName,"MIN",1)==false){status  = false;}

	if(validateLength(theForm.customerMobile,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.customerPhone,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.customerCountry,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.customerCity,"MIN",1)==false){status  = false;}	
	if(validateLength(theForm.customerZipCode,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.customerAddress,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.customerEmail,"MIN",1)==false){status  = false;}	
	if(validateLength(theForm.customerName,"MIN",1)==false){status  = false;}
	
	return statusControl(status,validateSiteSettingsErrorText);
};

function validateUpdateSiteSettings(){
	var theForm 	= getFormObject("updateSettings");
	var status 		= true;

	if(validateLength(theForm.systemExpireDate,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.systemMaxLevels,"MIN",1)==false){status  = false;}	
	if(validateLength(theForm.systemMaxPages,"MIN",1)==false){status  = false;}

	if(validateLength(theForm.systemRobotEmail,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.systemSMTPServer,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.systemDatabase,"MIN",1)==false){status  = false;}	

	if(validateLength(theForm.systemDescription,"MIN",1)==false){status  = false;}
	if(validateLength(theForm.systemKeywords,"MIN",1)==false){status  = false;}	
	if(validateLength(theForm.systemName,"MIN",1)==false){status  = false;}
	
	return statusControl(status,validateSiteSettingsErrorText);
};




// STATUS CONTROLL /////////////////////////////////
// Checks if validation completed, if not message is
// returned to user
function statusControl(status,message){
	if(status==false){
		alert(message);		
		return false;
	}else{
		return true;	
	}
};


// VALIDATION HELPERS /////////////////////////////////
// validateLength: validates the length of given field's value
// validateNumber: validates the number of given field's value
// validateDate: validates the date of given field's value
function checkInputDigit(theField){
	if(theField.value.match(/\D/)){
		theField.value = theField.value.replace(/\D/g,"");
		theField.className = "formAttention";
		alert("Detta fält får endast innehålla siffror.");	
		theField.focus();
	}else{theField.className = "formRequired";}
};


function validateLength(theField,validationType,requirement){
	switch (validationType) {
	   case "MIN":
		if(theField.value.length < requirement){
			theField.className	= "formAttention";
			theField.focus();
			return false;		
			break;			
		}else{theField.className = "formRequired";}

		case "MAX":
		 if(theField.value.length < requirement){
			theField.className	= "formAttention";
			theField.focus();			
			return false;		
			break;			
		 }else{theField.className = "formRequired";}
	}
	return true;
};

function validateNumber(theField,validationType,requirement){
	switch (validationType) {
	   case "MUST_BE":
		 if(theField.value.match(/\D+/)!=null){
			theField.className	= "formAttention";
			theField.focus();			
			return false;		
			break;		 			
		 }else{theField.className = "formRequired";}

	   case "CANT_BE":
		 if(theField.value.match(/\d+/)){
			theField.className	= "formAttention";
			theField.focus();			
			return false;		
			break;		 			
		 }else{theField.className = "formRequired";}
		
	   case "MIN":
		if(theField.value.parseInt() < requirement){
			theField.className	= "formAttention";
			theField.focus();			
			return false;		
			break;		 
		  }else{theField.className = "formRequired";}
		
	   case "MAX":
		if(theField.value.parseInt() > requirement){
			theField.className	= "formAttention";
			theField.focus();			
			return false;		
			break;			
		 }else{theField.className = "formRequired";}
	}
	return true;
};


function validateString(theField,validationType,requirement){
	switch (validationType) {
	   case "MUST_HAVE_INDEXOF_IF_GIVEN":
	    if(theField.value.length>0){	   
		 if(theField.value.indexOf(requirement)<0){
			theField.className	= "formAttention";
			theField.focus();
			return false;			
		 }else{theField.className = "";}
		 }else{theField.className = "";}
	}
};

function validateExactMatch(theField,theField2){
    if(theField.value != theField2.value){	   
		theField.className	= "formAttention";
		theField2.className	= "formAttention";			
		theField.focus();
		return false;			
	 }else{theField.className = "";}
};

function validateDate(theField,validationType,requirement){
	switch (validationType) {
	   case "MUST_BE":
	    var rExp = new RegExp(/\d{4}-\d{2}-\d{2}/);
		if(rExp.test(theField.value)==false){
			theField.className	= "formAttention";
			theField.focus();			
			return false;			
		}else{theField.className = "formRequired";}
	
	   case "MUST_BE_IF_GIVEN":
	    if(theField.value.length>0){
			var rExp = new RegExp(/\d{4}-\d{2}-\d{2}/);
			if(rExp.test(theField.value)==false){
				theField.className	= "formAttention";
				theField.focus();			
				return false;			
			}else{theField.className = "formRequired";}	
		}else{theField.className = "";}	
	}
	return true;
};
function initSystem(){
	
}
	// Version of Flash required
	var requiredMajorVersion = 8;
	var requiredMinorVersion = 0;
	var requiredRevision = 0;


	var validateNewPageErrorText 		= "Några fel upptäcktes bland inmatade uppgifter, funna fält har markerats ovan.";
	var validateUpdateUserErrorText 	= "Några fel upptäcktes bland inmatade uppgifter, funna fält har markerats ovan.";
	var validateSiteSettingsErrorText 	= "Några fel upptäcktes bland inmatade uppgifter, funna fält har markerats ovan.";