// +------------------------------------------------------------------+
// | JavaScript version 1.0                                           |
// +------------------------------------------------------------------+
// | general.js – Some standard functions used in the CMS cleint      |
// |              side. Script is loaded in template by parser.       |
// +------------------------------------------------------------------+
// | Copyright (c) 2008 MultiMove                                     |
// +------------------------------------------------------------------+
// | Authors: S.F.Beck <sander@multimove.nl>     					  |
// +------------------------------------------------------------------+

/**
 * The load function
 * 
 * @return void
 */
function doLoad( bgImage ){
	
	// Preload the bgImage
	image1 = new Image();
	image1.src = bgImage;
	
	// Check if flash is installed
	if(!FlashDetect.majorAtLeast(9)){
		document.getElementById('flashcontainer').style.display='none';
		if(	confirm('Om deze website correct weer te geven heeft u Adobe Flash Player 9 of hoger nodig.\nDe Adobe Flash player nu (gratis) downloaden?')) 
		{
			window.location="http://www.macromedia.com/go/getflashplayer";
		}
	}	

	//make a random number, prevents caching!
	var randomnumber=Math.floor(Math.random()*9999999999999999999);
	
	// Initiate flash background
	var flashvars = {	
		bitmap:""+bgImage
	}
	var params = {                   
			allowfullscreen:"false", 
			allowscriptaccess:"sameDomain",
			wmode:"transparent",
			quality:"high",
			scale:"noscale",
			salign:"lt",
			align:"middle",
			bgcolor:"#000000"				
	}
	var attributes = {
			id:"backgroundPlayer",  
			name:"backgroundPlayer"
	}
	swfobject.embedSWF(BASE_URL+"flash/body_bg.swf?233="+randomnumber, "flashcontainer", "100%", "100%", "9.0.0", false, flashvars, params, attributes);	  
}

/**
 * Make pop-up windows
 * 
 * @return void
 */
function popup( url, width, height )
{
	var iLeft = (screen.width - width) / 2 ;
	var iTop  = (screen.height - height) / 2 ;

	var sOptions = "resizable=yes,dependent=yes,scrollbars=yes," ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	window.open( url, "FCKBrowseWindow", sOptions ) ;
}


/**
 * Clear textfields preset text and turn to black
 * 
 * @return void
 */
function clearText(thefield) {
	if (thefield.defaultValue == thefield.value) {
		thefield.value = "";
		thefield.style.color = "#b2b2b2";
	}
	else thefield.value = thefield.defaultValue;
}


var PositionX = 100;
var PositionY = 100;
var defaultWidth  = 100;
var defaultHeight = 100;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}
var optNN='scrollbars=no, status=yes, width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no, status=yes, width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle,imageTitle2){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=10+document.images[0].width;');
		writeln('height=59+document.images[0].height;');
		
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');
		writeln('window.innerWidth=document.images["George"].width;');
		writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle2+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle(); self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src="'+imageURL+'" alt="'+imageTitle+'" onClick="window.close();" style="display: block; cursor: pointer;"></body></html>');
		close();
	}
}

function mailinglistXmlhttpPost(url, query)
{
    var xmlHttpReq = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('POST', url, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
      if(self.xmlHttpReq.readyState == 4)
      {
        var type = self.xmlHttpReq.responseText.split('|');
        
        switch(type[0])
        {
          default:
            alert(type[1]);
            break;
          
          case 'succes=2':
            alert(type[1]);
            document.getElementById('mailinglist_unsubscribe').style.display = 'none';
            document.getElementById('mailinglist_content').style.display = 'block';
            break;
          
          case 'succes=1':
            document.getElementById('mailinglist_content').style.display = 'none';
            document.getElementById('mailinglist_succes').style.display = 'block';
            break;
          
          case 'error=3':
          case 'error=2':
            alert(type[1]);
            break;
          
          case 'error=1':
            document.getElementById('mailinglist_content').style.display = 'none';
            document.getElementById('mailinglist_error').style.display = 'block';
            document.getElementById('error_text').innerHTML = type[1];
            break;
        }
      }
    }
    
    self.xmlHttpReq.send(query);
}


function disableSubmit(id,form){
	try{
		document.getElementById(id).style.display = 'none';
		document.getElementById(id).disabled = 'disabled';
		
		document.inputForm.submit();		
		document.getElementById('displayLoading').style.display = 'block';	
		}
	catch(e){}
}


function load_image(id){ 
	var imgpath = document.getElementById(id).value; 
	if(imgpath != "") {
		// code to get File Extension..
		
		var arr1 = new Array;	
		arr1 = imgpath.split("\\");	
		var len = arr1.length;	
		var img1 = arr1[len-1];	
		var filext = img1.substring(img1.lastIndexOf(".")+1);	
		
		// Checking Extension	
		if(filext == "jpg" || filext == "jpeg" || filext == "JPG" || filext == "JPEG")	
		{
			return true;
		}
		else	
		{
			alert("Het geselecteerde bestand is niet toegestaan.\nSelecteer een geldige extensie (*.jpg/*.jpeg)");
			document.getElementById(id + '_span').innerHTML = "";
   			document.getElementById(id + '_span').innerHTML = "<input type=\"file\" name=\"afbeeldingFile[]\" id=\""+id+"\" onchange=\"load_image(this.id)\" style=\"width:200px;\" />";		
			return false;
		}
	}
}


/**
 * Get the parentnode of the tab
 * @return node
 */
function findTabs(tab)
{
	return tab.parentNode;
}


/**
 * Get the tab
 * @return node
 */
function getTabId(tab)
{
	return tab.getElementsByTagName("a")[0].id;
}


/**
 * Show tab
 * @return bool
 */
function showTab(o)
{
	var current_tab = o.parentNode;
	var current_tabs = current_tab.parentNode.getElementsByTagName("li");
	for (var i = 0; i < current_tabs.length; i++) {
		current_tabs[i].id="";
		document.getElementById(getTabId(current_tabs[i]) + "-content").style.display="none";
	}
	current_tab.id = "current";
	document.getElementById(getTabId(current_tab) + "-content").style.display="block";
	document.cookie = findTabs(current_tab).id + "=" + getTabId(current_tab);
	return false;
}


/**
 * Focus field
 * @return void
 */
function eFocus(field,value){
	if (field.value == value){
		field.value ='';
	}
	field.className="bfilter"
}


/**
 * Blur field
 * @return void
 */
function eBlur(field,value){
	if (field.value == ''){
		field.value = value;
		field.className="rfilter";
	}else{
		field.className="bfilter";
	}
}


/**
 * Add load event
 * @return void
 */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


/**
 * AJAX clientside include
 * @return bool
 */
function clientSideInclude(id, url){
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}
