//Script voor baladharshan site.
//creatie datum : 22-12-2005
//door : cocpit	
//
//Werkwijze :
// Voor het vermijden van (i)frames worden er 3 div's voorzien.
// -div top_banner en div menu ==> wordt adhv meta 'menuItem' in de html, 
//                 door de functie buildMenuAndTopBanner opgebouwd en via innerHTML in de div geplaatst.
// -div content ==> wordt in de html zelf gecodeerd
//


var aMENU = new Array("home","hulpproject","nieuws","steun","fotos","over-ons","koppelingen","contact");
var menuMouseOut = new Array();
var menuMouseOver = new Array();



function buildMenuAndTopBanner()
{
 var cMENUITEM=document.getElementById('menuItem').content;
 nMAX = aMENU.length;
 lang=GetCookie('language');
 if ((lang != 'en') && (lang != 'nl')) {lang = 'nl';}
 if (document.images)
 {
  for (nSUB=0;nSUB < nMAX;nSUB++)
  {
   menuMouseOut[nSUB] = new Image;
   menuMouseOver[nSUB] = new Image;
   menuMouseOut[nSUB].src = "/"+lang+"/images/menu_"+aMENU[nSUB]+".gif";
   menuMouseOver[nSUB].src = "/"+lang+"/images/menu_"+aMENU[nSUB]+"_s.gif";
  }
 }

 var menustr = '<table height=100% width="125px" align="left" border="1" bordercolor="#443D36" cellpadding="0" cellspacing="0">';
 for (nSUB=0;nSUB < nMAX;nSUB++)
 {
 menustr = menustr + '<tr><td style="border-bottom:0;border-top:0;"><a href="/'+lang+'/'+ aMENU[nSUB] +'.html" ';
  if (aMENU[nSUB] == cMENUITEM) 
   {menustr = menustr + '><img src="/'+lang+'/images/menu_' + aMENU[nSUB] + '_s.gif" ';}
  else
   {menustr = menustr + ' onMouseOver="mouseOver('+nSUB+')" onMouseOut="mouseOut('+nSUB+')"><img id="imgMENU_' + aMENU[nSUB] + '" src="/'+lang+'/images/menu_' + aMENU[nSUB] + '.gif" ';}
  menustr = menustr + 'border="0"></a></td></tr>';
  }
 menustr=menustr+'<tr height="100%"><td bgcolor="#FFFFFF" background="/'+lang+'/images/menu_bg_'+cMENUITEM+'.gif" style="background-repeat: no-repeat;border-bottom:0;border-top:0;"><img src="/'+lang+'/images/spacer.gif"></td></tr></table>';

 var strTopBanner='<table width="100%" align="left" border="1" bordercolor="#443D36" cellpadding="0" cellspacing="0">';
 strTopBanner=strTopBanner+'<TR><TD colspan="2" BACKGROUND="/'+lang+'/images/top_background_'+cMENUITEM+'.gif">';
 strTopBanner=strTopBanner+'<table align="left" border="0" cellpadding="0" cellspacing="0">';
 strTopBanner=strTopBanner+'<tr><td align="left" width="382"><img src= "/'+lang+'/images/top_r1_c1_'+cMENUITEM+'.gif"></TD>';
 strTopBanner=strTopBanner+'<td  width="354" align="left"><br><br><br><br><br><img src= "/'+lang+'/images/top_baladharshan.gif"></td>';
 strTopBanner=strTopBanner+'<td width="100%" align="right"><br><br><br><br><br><br><a href="/index.html"><img src= "/'+lang+'/images/top_taalkeuze.gif" border="0" onClick="DeleteCookie('+"'language'"+');"></a></td></tr></table>';
 strTopBanner=strTopBanner+'</TD></TR><TR><td><table width=100% align="left" border="0" cellpadding="0" cellspacing="0"><tr>';
 strTopBanner=strTopBanner+'<td width="125px" style=""><img src="/'+lang+'/images/top_r2_c1_'+cMENUITEM+'.gif"></td>';
 strTopBanner=strTopBanner+'<td width="2px" bgcolor="#443D36" style=""><img src="/'+lang+'/images/spacer.gif"></td>';
 strTopBanner=strTopBanner+'<td bgcolor="#FFFFFF" background="/'+lang+'/images/top_r2_c2_'+cMENUITEM+'.gif" style="background-repeat: no-repeat;">';
 var strLink=document.getElementById('whereAreYou').innerHTML;
 if (strLink != '') 
  {strTopBanner=strTopBanner+strLink;}
 else
  { strTopBanner=strTopBanner+'&nbsp;';}
 strTopBanner=strTopBanner+'</td> </TR></TABLE></td></tr></table>';
 document.getElementById('menu').innerHTML = menustr;
 document.getElementById('top_banner').innerHTML = strTopBanner;
}

function mouseOver(n)
{
 document.getElementById('imgMENU_' + aMENU[n]).src = menuMouseOver[n].src;
}

function mouseOut(n)
{
 document.getElementById('imgMENU_' + aMENU[n]).src = menuMouseOut[n].src;
}

function setContentWidth()
{
// alert(document.getElementById('myFeed').style.width);
if (document.body.clientWidth - 150 < 575) document.getElementById('content').style.width=(document.body.clientWidth - 150) + 'px';
else document.getElementById('content').style.width='575px';
// if (document.getElementById('myFeed')) document.getElementById('myFeed').style.width=(document.body.clientWidth - 170) + 'px';
 document.getElementById('top_banner').style.width = document.body.clientWidth;
 if (document.body.clientHeight - 153 > document.getElementById('content').offsetHeight) 
  document.getElementById('menu').style.height = (document.body.clientHeight - 153) + 'px';
 else
  document.getElementById('menu').style.height = (document.getElementById('content').offsetHeight + 25) + 'px';
 // alert(document.getElementById('content').offsetHeight);
 window.onresize = setContentWidth;
}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
    var exdate=new Date();
    exdate.setDate(100); 
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : "; expires="+ exdate.toGMTString()) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


function changeLanguage(){
  lang=GetCookie('language');
  var strLoc = new String(window.location);
  if (lang!=null) {
    if (lang=='nl') {
	  lang='en';
	  var test=strLoc.replace(/\/l\//,'/en/');
      }
	else
	  {
	  lang='nl'; var test=strLoc.replace(/\/en\//,'/nl/');
      }
//	SetCookie('language',lang);
    alert("before location");
	self.location.href='../en/home.html';
	}
  else 
    {alert('No language set : please allow cookies before switching to other language');
    window.location="../index.html";
	}
}


function show_photo( pFileName, pTitle) {

// specify window parameters
  photoWin = window.open( "", "photo", "width=600,height=450,status,scrollbars,resizable,screenX=20,screenY=40,left=20,top=40");
  photoWin.document.write('<html><head><title>' + 
    pTitle + '</title></head>');	
  photoWin.document.write('<BODY BGCOLOR=#000000 TEXT=#FFFFCC LINK=#33CCFF VLINK=#FF6666>');
  photoWin.document.write('<center>');
  photoWin.document.write('<img src="' + 
    pFileName + '"><p>');

  photoWin.document.write('</body></html>');
  photoWin.document.close();	
	
// If we are on NetScape, we can bring the window to the front
	if (navigator.appName.substring(0,8) == 
	   "Netscape") photoWin.focus();
}


