// history back?
if (ret = iomGetCookie('HISTORYCTRL')) {
	iomClearCookie('HISTORYCTRL');
	top.location.href = document.weburl+document.glourl+unescape(ret);
}

//
// onerror
//
function stopJSError() { 
	return true;
} 

window.onerror=stopJSError;

msgArray = new Array()
urlArray = new Array()
lnoArray = new Array()

function myOnError(msg, url, lno) {
	msgArray[msgArray.length] = msg
	urlArray[urlArray.length] = url
	lnoArray[lnoArray.length] = lno
	displayErrors();
	return true
}
function displayErrors() {
	var output = '';
	for (var i=0; i < msgArray.length; i++) {
		output += 'Error in file: ' + urlArray[i] + '\n';
		output += 'Line number: ' + lnoArray[i] + '\n';
		output += 'Message: ' + msgArray[i] + '\n';
	}
	//alert(output);
}

//
// extend
//
if (typeof Prototype != 'undefined'){

	// browser extend (IE/IE7/IE8/...)
	Object.extend(Prototype.Browser, {
		IE6: Prototype.Browser.IE && (typeof window.XMLHttpRequest == "undefined"),
		IE7: Prototype.Browser.IE && (typeof window.XMLHttpRequest == "object" && navigator.userAgent.indexOf('MSIE 7') > -1),
		IE8: Prototype.Browser.IE && (typeof window.XMLHttpRequest == "object" && navigator.userAgent.indexOf('MSIE 8') > -1)	
	});
	
	Object.extend(Prototype.Browser, {
		IEGTE7: Prototype.Browser.IE7 && Prototype.Browser.IE8
	});

}

/////////////////////////
function workProtector() {
	return true;
}
/////////////////////////

//
// initialize global variables
//
var w = window, d = document, mon = screen, isit = new String(d.location);

if (!document.glourl) {
	url_protocol = window.location.protocol;
	url_host = window.location.host;
	url_path = window.location.pathname;	
	document.glourl = url_protocol+"//"+url_host+url_path;
}

if (mon) {mon_w = mon.width;mon_h = mon.height; if(navigator.appName.indexOf("Microsoft")!=-1){mon_aw = mon.availWidth;mon_ah = mon.availHeight;} else {mon_aw = mon.availWidth;mon_ah = parseInt(mon.availHeight-100);}} else {mon_w = 750;mon_h = 500;mon_aw = 700;mon_ah = 450;}

//
// mousehandle
//
window.xpos = 0; window.ypos = 0;
function mouseHandleMove(ev) {
	window.xpos = Event.pointerX(ev);
	window.ypos = Event.pointerY(ev);
}
document.observe('mousemove', mouseHandleMove);


//
// round
//
function roundValue(x, n) {
	if (n < 1 || n > 14) return false;
	var e = Math.pow(10, n);
	var k = (Math.round(x * e) / e).toString();
	if (k.indexOf('.') == -1) k += '.';
	k += e.toString().substring(1);
	return k.substring(0, k.indexOf('.') + n+1);
}

//
// set price format
//
function ioPriceFormat(p, d) {
	return roundValue(roundValue((p/5), d)*5, d)
}

//
// cookie management
//
function iomClearCookie(cookieName) {
	var now = new Date();
	yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	iomSetCookie(cookieName, 'cookieValue', yesterday);
}
function iomSetCookie(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}
function iomGetCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}

//
// prepare text
//
function repNewline(txt) {
	try {newtxt = decodeURI(txt);} catch(e) {newtxt = txt;}
	if (newtxt.indexOf('\\n')!=-1) {	
		do {newtxt = newtxt.replace('\\n','\n');} 
		while(newtxt.indexOf('\\n')!=-1);	
	} else if (newtxt.indexOf('\r')!=-1) {	
		do {newtxt = newtxt.replace('\r','');} 
		while(newtxt.indexOf('\r')!=-1);	
	} else if (newtxt.indexOf('%0D')!=-1) {	
		do {newtxt = newtxt.replace('%0D','');} 
		while(newtxt.indexOf('%0D')!=-1);					
	} else if (newtxt.indexOf('%5Cn')!=-1) {	
		do {newtxt = newtxt.replace('%5Cn','\n');} 
		while(newtxt.indexOf('%5Cn')!=-1);
	} else if (newtxt.indexOf('<br>')!=-1) {	
		do {newtxt = newtxt.replace('<br>','\n');} 
		while(newtxt.indexOf('<br>')!=-1);	
	} else if (newtxt.indexOf('<br />')!=-1) {	
		do {newtxt = newtxt.replace('<br />','\n');} 
		while(newtxt.indexOf('<br />')!=-1);	
	}		
	return unescape(newtxt);
}

function repFormline(txt) {
	try {newtxt = decodeURI(txt);} catch(e) {newtxt = txt;}
	if (newtxt.indexOf('<')!=-1) {	
		do {newtxt = newtxt.replace('<','&lt;');} 
		while(newtxt.indexOf('<')!=-1);
	}	
	if (newtxt.indexOf('>')!=-1) {	
		do {newtxt = newtxt.replace('>','&gt;');} 
		while(newtxt.indexOf('>')!=-1);
	}		
	if (newtxt.indexOf('\n')!=-1) {	
		do {newtxt = newtxt.replace('\n','<br />');} 
		while(newtxt.indexOf('\n')!=-1);
	}
	return unescape(newtxt);
}

// 
// check ask array
//
function checkAskArr(arr) {
	if (!d.arrask) {
		d.arrask = new Array();
		for (i=0;i<=arr;i++) {d.arrask[i] = "Are you sure?\n";}
	}
}

//
// open new browser window (not popup)
//
function openBrowser(qry, url) {
	var wurl = (qry!="") ? url+".cfm?"+qry : url+".cfm";
	d.winBrowser = window.open(wurl);
	if (d.winBrowser) {d.winBrowser.window.focus();}
}

//
// open popup window
//
function openPopUp(qry, url, nam, ww, wh, res, bar, stt, sec) {
	if (!res) {res = "yes";}
	if (!bar) {bar = "yes";}
	if (!stt) {stt = "no";}	
	if (ww > mon_w) {ww = mon_w;}
	if (wh > mon_h) {wh = mon_h;}
	var wargs = "width="+ww+",height="+wh+",scrollbars="+bar+",resizable="+res+",status="+stt;
	var wurl = (qry!="") ? url+".cfm?"+qry : url+".cfm";	
	var winPop = window.open(wurl,"PoP"+nam,wargs);
	checkPopUp(winPop);
}

//
// check popup blocker
//
function checkPopUp(winPop) {
	if (winPop) {
		winPop.window.focus();
	} else {
		var popblockmsg = "PopUp-Blocker? Please disable it and reload this site!";
		alert(popblockmsg);
	}	
}

//
// ask/goto logout
//
function gloLogOut(msg, qry) {
	var asknow = repNewline(msg);
	var logoutchk = confirm(asknow);
	if (logoutchk != false) {top.location.replace(d.weburl+"?"+qry);}
}

//
// preload images
//
function preloadImg() {
	if(d.images){ if(!d.das_p) d.das_p=new Array();
	var i,j=d.das_p.length,a=preloadImg.arguments; for(i=0; i<a.length; i++)	
	if (a[i].indexOf("#")!=0){ d.das_p[j]=new Image; d.das_p[j++].src=d.locimg+"/"+a[i];}}
}

//
// change image
//
function changeImg() {	
	var i,j=0,x,a=changeImg.arguments; d.das_sr=new Array; for(i=0;i<a.length;i++)
	if ((x=searchObj(a[i]))!=null){d.das_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=d.locimg+"/"+a[i+1];}
}

//
// resotre image ('rechange')
//
function restoreImg() {
	var i,x,a=document.das_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//
// serach object (id or name)
//
function searchObj(n, d) {
	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=searchObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//
// get coord of a object (return x:y)
//
function getCoordXY(iom) {
	if (document.layers) { return iom; }
	var io={ x:0 ,y:0 };
	do {io.x+=parseInt(iom.offsetLeft); io.y+=parseInt(iom.offsetTop); iom=iom.offsetParent;} 
	while (iom);
	return io;
}

//
// set window status
//
function changeStatus(qry) {
	if (qry) { w.defaultStatus=document.url+"?"+qry; }
	else { w.defaultStatus=""; }
}

//
// gourl now (func-cadaver? 29.11.06)
//
function goURLnow(qry) {
	if (qry) {top.location.replace(d.weburl+"?"+qry);} else {top.location.replace(d.glourl);}
}

//
// go any url
//
function goUrl() {
	var u = goUrl.arguments;
	for (i=0;i<(u.length-1);i+=2) {
	var url=u[i],qry=u[i+1],hir=u[i+2];
	  if (!hir) {location.replace(url+"?"+qry);} 
	  else if (hir=="top") {top.location.replace(url+"?"+qry);}
	  else if (hir=="blank") {window.open(url+"?"+qry);}}
}

//
// create info layer
//
function createInfoLayer() {
	var objInfoLayer = document.createElement('div');
	objInfoLayer.setAttribute('id', 'gloInfoLayer');
	objInfoLayer.style.display = 'none';
	objInfoLayer.style.position = 'absolute';
	objInfoLayer.style.top = '-2000px';
	objInfoLayer.style.left = '-2000px';
	$$('body')[0].appendChild(objInfoLayer);	
	return;
}

//
// page protector
//
function createPageProtector() {
	if ($('overlay')) return;
	
	var tmpContainer = new Element('div', {'id':'pageProtector'});	
	$$('body')[0].appendChild(tmpContainer);	
	return;
}


// init lightbox
function initLightbox() { myLightbox = new Lightbox(); }

//
// png goes transparency (simply the best^^ IE6)
//
if (Prototype.Browser.IE && !Prototype.Browser.IE7) {window.onload = function(){window.png = new PNGTransparency();window.png.create();}}
function PNGTransparency(){this.create = PNGTransparency_create;}
function PNGTransparency_create(){
	var i, img, oldsrc;
	var imgs = document.getElementsByTagName('img');
	for ( i=0; i < imgs.length; i++ ){
		img = imgs[i];
		if (img.src.indexOf('.png') != -1){
			img_w = img.offsetWidth;img_h = img.offsetHeight;
			oldsrc = img.src;img.src = document.imgurl+'/ai_ph.gif';
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldsrc + "', sizingMethod='scale')";
			img.setAttribute("width", img_w);img.setAttribute("height", img_h);
		}
	}
}

//
// remove 'index.cfm' in hyperlinks
//
function removeIndexLinks() {	
	links = d.getElementsByTagName('a');
	for(i=0;i<links.length;i++){
		var link = links[i];
		var actHref = String(link.getAttribute('href'));
		if (actHref.indexOf("/index.cfm") != -1) {
			var newHref = actHref.replace(/index.cfm/g, "");
			link.setAttribute('href', newHref);
		}
	}	
	forms = d.getElementsByTagName('form');
	for(i=0;i<forms.length;i++){
		var form = forms[i];
		var actHref = String(form.getAttribute('action'));
		if (actHref.indexOf("/index.cfm") != -1) {
			var newHref = actHref.replace(/index.cfm/g, "");
			form.setAttribute('action', newHref);
		}
	}		
	return;
}

//
// init onload 
//
function initSiteOnLoad() {	
	// create infolayer
	createInfoLayer();
	createPageProtector();
	// remove index.cfm
	removeIndexLinks();
}

document.observe('dom:loaded', initSiteOnLoad);

// script is loaded...
document.pageloaded = true;
// eof
