/*
*	MudiBlox Framework.
*	Javascript functions
*	Author : Jeffrey van Hal (Digitien), Muhamed Durakovic (Mubis)
*	CopyRight 2008 
*	Date: 30-07-2008
*/
var default_init_page = 49;

function a(){
var str='';
window.status=str;
return true;
}

function b(){
	self.status = "";
}

var QueryString = {
   //params : $H(window.location.search.toQueryParams()), <-- prototype 1.5
   params : window.location.search.toQueryParams(),
   get : function(key, defaultValue) {
       if (defaultValue == null) defaultValue = null;
       var value = this.params[key]
       if (value==null) value = defaultValue;
       return value;
   },
  
   set : function(key, value) {
       this.params[key] = value;
   },
  
   remove : function(key) {
       this.params = this.params.collect(function(param) {
           if (key != param.key) return param;
       }).compact();
   },
  
   make : function() {
       return "?" + this.params.collect(function(param) {
           return escape(param.key) +"="+ escape(param.value);
       }).join("&");
   },
  
   go : function() {
       window.location.href = location.pathname + this.make();
   }
}

var currSelectedMenu = null;
var currContent = new Array();
/*
	AJAX FrameWork Functions 	
*/

function openAjax(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	if (!ajaxRequest) { 
   		alert("Unfortunately your browser doesn’t support this feature."); 
   		return false; 
 	} 

	return ajaxRequest;
}

function closeAjax(objAjax){	
	objAjax.send(null); 
}

function imgdivloader(objAjax, strImg)
{
	if(objAjax.readyState == 1){
	document.getElementById(strImg).style.display="block";	
	}
	if(objAjax.readyState == 2){
	document.getElementById(strImg).style.display="none";	
	}	
}

function callfunction(url, callbackFunction, strImgId ,return_xml){

	var ajaxRequestObj = openAjax();	
	ajaxRequestObj.onreadystatechange = function(){
	imgdivloader(ajaxRequestObj,strImgId);
	
		if(ajaxRequestObj.readyState == 4){
			
			if (return_xml) { 
				 response = ajaxRequestObj.responseXML; 
			}else{ 
				 response = ajaxRequestObj.responseText; 
			} 
			if (typeof callbackFunction == 'function') {				
				callbackFunction(response);
			}
			else{
				alert("callbackFunction: "+callbackFunction+" not defined");
			}
			

		}
	}
	if(isEmptyStr(url)){
		alert("No Url defined for this function.");
	}
	ajaxRequestObj.open("POST", url, true);
	closeAjax(ajaxRequestObj); 
}
   	function setHeight(){
			<!--

		 var viewportwidth;
		 var viewportheight;

		 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		 if (typeof window.innerWidth != 'undefined')
		 {
			  viewportwidth = window.innerWidth,
			  viewportheight = window.innerHeight
		 }
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		 else if (typeof document.documentElement != 'undefined'
			 && typeof document.documentElement.clientWidth !=
			 'undefined' && document.documentElement.clientWidth != 0)
		 {
			   viewportwidth = document.documentElement.clientWidth,
			   viewportheight = document.documentElement.clientHeight
		 }
		 // older versions of IE
		 else
		 {
			   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			   viewportheight = document.getElementsByTagName('body')[0].clientHeight
		 }
		//document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
		//-->
			var pageHeight = document.getElementById('mainContent');
			var fillHeight = document.getElementById('container');
			var defaultSize = 770;

			var offSet = pageHeight.offsetHeight;
			//available height is offset minus viewport height -1px
			var container = viewportheight;
			
			if(offSet && container < defaultSize){
				var rightcolumn = $('rightcolor');
				if(rightcolumn){
					rightcolumn.style.height = defaultSize.toString() + 'px';
				}
				pageHeight.style.height = defaultSize.toString() + 'px';
				fillHeight.style.height = defaultSize.toString() + 'px';
			}else{
				//fillHeight.style.height = offSet.toString() + 'px';
				var rightcolumn = $('rightcolor');
				if(rightcolumn){
					rightcolumn.style.height = container.toString() + 'px';
				}
				fillHeight.style.height = container.toString() + 'px';
			}
		}

/* 
	AJAX Wrapper Functions
*/
	function callMenu(id){
		callfunction("?stype=majax&action=menu&cid="+id, mycallback, "imgload",false);
       	currSelectedMenu = id;        
	}
	
	var globPageId;
	function callArea(id){
		callfunction("?stype=majax&action=area&area="+id, productAreaCallBack, "imgload",false);
		globPageId = id;
	}
	
	

/* 
	AJAX callBackFunctions
*/
	function mycallback(ajxresponseText){
		//alert(ajxresponseText);
		document.getElementById('contentblock').innerHTML = ajxresponseText;
		currContent.push = [ {currSelectedMenu:ajxresponseText} ];
	}
	
	function productAreaCallBack(ajxresponseText){
			document.getElementById('div_area_description').innerHTML = ajxresponseText;
			if(globPageId == 60){
			document.getElementById('backlink').style.display = 'none';
			}else{
			document.getElementById('backlink').style.display = 'block';
			}
			
		}
		

/* 
	init function
*/
function init(){
	var cid = QueryString.get('cid',null);
	
	if(cid != null){
		id=cid;			
	}else{
		id=default_init_page; //default startpage				
	}
	
	if(typeof currContent == 'object'){
		if(currContent.length > 0){
		alert(currContent[cid]);
		}
	}
	if(currSelectedMenu != null && currSelectedMenu == cid){
			document.getElementById('contentblock').innerHTML = currContent;
	}else{
		callMenu(id);
	}
	
	
}

/*
	Custom string and validation functions
*/



function isEmptyStr(s)
{
   var whitespace = " \t\n\r";
   var i;
   if((s == null) || (s.length == 0))
      return true;
   // Search string looking for characters that are not whitespace
   for (i = 0; i < s.length; i++)    
    {   
      var c = s.charAt(i);
      if (whitespace.indexOf(c) == -1) 
        return false;
    }
    // At this point all characters are whitespace.
    return true;
}

function urlencode(text) 
{		
	
	text=text.replace("/\//g","%2F");
	text=text.replace("/?/g","%3F");
	text=text.replace("/=/g","%3D");
	text=text.replace("/&/g","%26");	

		
	/*
	//text=ReplaceAll(text, "/\", "%2F"); 
	text=ReplaceAll(text, "?", "%3F");
	text=ReplaceAll(text, "=", "%3D");
	text=ReplaceAll(text, "&", "%26");
	text=ReplaceAll(text, " ", "+");
	text=ReplaceAll(text, ",", "%2c");	
	*/
	return text;
}





