/******************************************************************************
* Main JS functions for Raket CMS
* By Fredric Palmgren | fredric@spenat.se
*
* Copyright &#169; Spenat Space AB | www.spenat.se
* 
* If you want to use this file. Please do so, but keep this notice intact.
 ******************************************************************************/
 
<!-- 
var TYPE_IMAGE	= 1;
var imgExtensions = new Array("gif", "jpg", "jpeg", "png", "bmp");	
var emailRegex = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$";
// Macromedia scripts
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v;
	 obj.display = (v == 'hidden') ? 'none' : ''; // Added by David.
	}
} 
function fixUglyIE()
{
for (a in document.links) document.links[a].onfocus = document.links[a].blur;
}
if (document.all)
{
document.onmousedown = fixUglyIE;
}
function gray_on(nr) {
}
function gray_off(nr) {
	this.filters.item(0).enabled=false
}
// Toggle tabs, this function uses an array that is created on the page with the layers
function toggle(layerName){		
	for (var i = 0; i < layerTabs.length; i++) {
		action = (layerTabs[i] == layerName) ? 'show' : 'hide';
		MM_showHideLayers(layerTabs[i], '', action);
	}
}
// Toggle tabs, this function uses an array that is created on the page with the layers
function toggleTab(name){
	toggleTab(name, 'images');
}
// Toggle tabs, this function uses an array that is created on the page with the layers
function toggleTab(name, imagePath){		
	for (var i = 0; i < tabs.length; i++) {
		
		var left = document.getElementById(tabs[i] + 'Left')
		var main = document.getElementById(tabs[i] + 'Main');
		var right= document.getElementById(tabs[i] + 'Right');
			
		var imgPath = systemRoot + "/" + imagePath;
			
		if (tabs[i] == name) {	
			MM_showHideLayers(tabs[i] + 'Tab', '', 'show');
			
			if(left != undefined)	
				left.src = imgPath + '/tabSLeft.gif';
			if(main != undefined)	
				main.style.backgroundImage = 'url(' + imgPath + '/tabSMain.gif)';
			if(right != undefined)	
				right.src = imgPath + '/tabSRight.gif';				
		}		
		else {
			MM_showHideLayers(tabs[i] + 'Tab', '', 'hide');
			if(left != undefined)		
				left.src = imgPath + '/tabLeft.gif';
			if(main != undefined)	
				main.style.backgroundImage = 'url(' + imgPath + '/tabMain.gif)';
			if(right != undefined)	
				right.src = imgPath + '/tabRight.gif';
		}
	}
}
/******************************************************************************
* Format a date in this format "2004.12.20". Takes a date object as argument and returns a string.
*/
function formatDate(dateObj) {
	dateStr =  dateObj.getFullYear();
	dateStr += ".";
	dateStr += (dateObj.getMonth() < 10) ? "0" + (dateObj.getMonth() + 1) : (dateObj.getMonth() + 1);
	dateStr += ".";
	dateStr += (dateObj.getDate() < 10) ? "0" + dateObj.getDate() : dateObj.getDate();
	return dateStr;
}
/******************************************************************************
* Parse a date in this format "2004.12.20" and return a date object.
*/
function parseDate(dateStr) {
	var re = /(\d{4})\.(\d{2})\.(\d{2})/;
	var matches = re.exec(dateStr);
	if (matches != null) {
		var dateObj = new Date(matches[1], parseInt(matches[2], 10) - 1, parseInt(matches[3], 10));
		return dateObj;
	}
	return null;
}
/******************************************************************************
* Parse a date in this format "2004.12.20 16:00" and return a date object.
*/
function parseDateTime(dateStr) {
	var re = /(\d{4})\.(\d{2})\.(\d{2}) (\d{2}):(\d{2})/;
	var matches = re.exec(dateStr);
	if (matches != null) {
		var dateObj = new Date(matches[1], parseInt(matches[2], 10) - 1, parseInt(matches[3], 10));
		dateObj.setHours(matches[4], matches[5], 0, 0);
		return dateObj;
	}
	return null;
}
				
/**************************************************************
 * Checks what if the file with extension [$1=ext] is a valid [$2=type].
 */
function isValidType(ext, type){
	var extensions;
	if(type == TYPE_IMAGE)
		extensions = imgExtensions;
	for(var i=0; i< imgExtensions.length; i++){
		if(imgExtensions[i] == ext)
			return true;
	}
	return false;
}
				
// Returns a date object where the time is set to 00:00:00 (used in contentEdit.xsl).
function getPlainDate() {
	var plainDate = new Date();
	plainDate.setHours(0);
	plainDate.setMinutes(0);
	plainDate.setSeconds(0);
	plainDate.setMilliseconds(0);
	return plainDate;
}
/**********************************************************************************************
 * Validates an email address using this regular expression:<br>
 * <code>^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$</code> 
 * 
 * @param email the email address that should be validated
 * @return
 */
function isValidEmail(email){
	return email.match(emailRegex);
}
/**************************************************************
 * Opens a support window
 */
function openSupport(url){
	var base = "http://support.spenat.se/";
	url = base + url;
	var supportWindow = window.open(url,
		"supportWindow",
		"width=733, height=500, toolbar=no, scrollbars=no, menubar=no, location=no, resizable=no, directories=no, status=no, left=0, top=0");
}	
