//
// +----------------------------------------------------------------------+
// | IVM                                                                  |
// | Copyright (c) 2003 monsun media                                      |
// +----------------------------------------------------------------------+
// | @file   : js/mcmfunctions.js                                         |
// | @date   : 2004-03-26                                                 |
// | @version: 1.0                                                        |
// +----------------------------------------------------------------------+
//


/**
* @function getObj(id)
* @param	string:id
* @retunr	object||false
* @date		2003-12-19
*/
function getObj(id){
	var o;         
	if( document.getElementById && document.getElementById(id) ){
		o = document.getElementById(id);
		return o;
	}else if( document.all && document.all(id) ){
		o = document.all(id);
		return o;
	}else{
		return;
	}
}


/**
* @function preloadImg(src)
* @param	src - URI of an image
* @return	Image-Object
* @date		2003-12-19
*/
function preloadImg(src){
	var img = new Image();
	img.src= src;
	return img;
}


// ------------------------------------------------------------------------
// servicebar
// ------------------------------------------------------------------------
function mcmHome(){
	location.href = "/";
}
function mcmPopupIndex(){
	var url = '/mcm/siteindex.php';
	x=(parseInt(screen.width)/2)-150;
	y=(parseInt(screen.height)/2)-165;
	var wh = window.open(url,'winSitemap','width=300,height=300,left='+x+',top='+y+',scrollbars=yes');
	wh.focus();
}


function mcmPopupPrintVersion(){
	var url = location.pathname;
	var winwidth = 590;
	var winheight = 560
	x=(parseInt(screen.width)/2)-(winwidth/2);
	y=(parseInt(screen.height)/2)-(winheight/2);
	if( location.search == "" ){
		url += '?print=1';
	}else{
		var re = /print=1/;
		if( !re.exec(location.search) ){
			url += location.search + '&print=1';
		}else{
			url += location.search;
		}
	}
	window.open(url,'print','menubar=yes,width='+winwidth+',height='+winheight+',left='+x+',top='+y+',scrollbars=yes');
}


function mcmPopupHistory(){
	var url = '/mcm/urlhistory.php';
	x=(parseInt(screen.width)/2)-150;
	y=(parseInt(screen.height)/2)-150;
	var wh = window.open(url,'history','width=335,height=299,left='+x+',top='+y+',scrollbars=no');
	wh.focus();
}


function mcmPopupRecommend(){
	var url = '/mcm/recommend.php?url='+window.location.href;
	x=(parseInt(screen.width)/2)-210;
	y=(parseInt(screen.height)/2)-185;
	var wh = window.open(url,'winRecommend','width=420,height=390,left='+x+',top='+y);
	wh.focus();
}


function mcmPopupSearch(){
	var frm = document.forms["mcmSearch"];
	var el = frm.elements["keyword"];
	var keyword = el.value;
	var url = '/mcm/search.php?keyword='+keyword;
	var wh = window.open(url,'winSearch','width=420,height=390');
	wh.focus();
	return false;
}


function mcmShowGallery(gallery_id){
	var url = '/mcm/galerie.php?gallery_id='+gallery_id;
	var wh = window.open(url,'gallery','width=580,height=580');
	wh.focus();
	return;
	var url = 'galerie.php?gallery_id='+gallery_id;
	var winwidth = 584;
	var winheight = 464;
	x=(parseInt(screen.width)/2)-(winwidth/2);
	y=(parseInt(screen.height)/2)-(winheight/2);
	window.open(url,'gallery','width='+winwidth+',height='+winheight+',left='+x+',top='+y);
}

/* ============ navi-menu ============ */
var activeMenuId=1;
var hideDropdownMenuInt=null;

function showMenu(menuId){
	if(isNaN(menuId)) return;
	if( activeMenuId!=0 ){
		hideMenu(activeMenuId);
	};
	var menu = document.getElementById("dropdownMenu"+menuId);
	if( menu==null || typeof menu!='object' || typeof menu.style!='object' ) return false;
	menu.style.display = 'block';
	activeMenuId = menuId;
}
function hideMenu(menuId){
	var menu = document.getElementById("dropdownMenu"+menuId);
	if( typeof menu != "object" ){
		alert(" some error occured in hideMenu("+menuId+")\n\n");
		return;
	};
	menu.style.display = 'none';
	if( menu.style.display != "none" ){
		alert("fatal error");
		return;
	}
	activeMenuId = 0;
}
function startHideMenu(menuId){
	// noop
}






/**
* @function printDebug(html)
* @date		2003-05-27
*/
function printDebug(html){
	if( typeof mcmDebugWindow=="undefined" || mcmDebugWindow.closed == true){
		var left = 1152; var width = 400;
		left -= (width + 13);
		mcmDebugWindow = window.open('','mcmDebugWin','width='+width+',height=400,status=yes,resizable=yes,scrollbars=yes,left='+left+',top=0');
		mcmDebugWindow.document.open();
		mcmDebugWindow.document.writeln('<html>\n<title>Javascript-Debugger</title>\n<head>\n<style type="text/css">\nbody,th,td { font-family:Courier; font-size:11px;}\n</style>\n</head><body scroll="auto">');
		mcmDebugWindow.document.writeln('<div align="center" style="background-color:buttonface;"><button onclick="document.getElementById(\'debugOutput\').innerHTML=\'\';">clear page</button></div><div id="debugOutput"></div>');
		mcmDebugWindow.document.writeln('</body></html>');
		mcmDebugWindow.document.close();
	};
	mcmDebugWindow.document.getElementById("debugOutput").innerHTML += html;
	//mcmDebugWindow.focus();
};


/**
* @function printDebugOject(obj,bSortIt)
* @param	obj		object 	object to inspect
* @param	bSortIt	bool	sort the object-properties?
* @date		2003-05-27
*/
function printDebugObject(obj,bSortIt){
	if( typeof obj=="object" ){
		var i;
		var htmlBuffer = '';
		var bufferAry = new Array();
		var htmlStr = "";
		for( i in obj ){
			htmlStr  = '<tr><td valign="top"><b>'+i+'</b></td><td valign="top">';
			if( typeof obj[i] == "boolean" ){
				htmlStr += obj[i]==true ? 'true' : 'false';
			//}else if( typeof obj[i] == "object" ){
			//	htmlStr += '<a href="#" onclick="printDebugObject(obj[i]);">' + obj[i] + '</a>';
			}else{
				htmlStr += (obj[i]==''?'&nbsp;':obj[i])
			};
			htmlStr += '</td><td>['+(typeof obj[i])+']</td></tr>';
			bufferAry[bufferAry.length] = htmlStr;
		};
		if( bSortIt!=false ){
			bufferAry.sort();
		};
		htmlBuffer  = '<table border="1" cellpadding="2" cellspacing="0">';
		htmlBuffer += bufferAry.join("\n");
		htmlBuffer += '</table>';
		printDebug(htmlBuffer);
	};
}
