/*

io_globalfuncs.js    v. 1.00

copyright (c) 2000-2005 io-market ag
created 07.07.2005 by io-market ag (web: http://www.io-market.com)
last modified: 07.07.2005


license:

this library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

this library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

For more details on the GNU Lesser General Public License,
see http://www.gnu.org/copyleft/lesser.html

*/

w = window, d = document, mon = (screen) ? screen : false, isit = new String(d.location);
valmerke = true; document.mouseEff = true; document.clickBlock = false;

// open new window
function io_PopUp(qry, winNam, ww, wh, argRes, argSbar, argStt) {	// popup-fenster
	if (!argRes) {argRes = "yes";}
	if (!argSbar) {argSbar = "yes";}
	if (!argStt) {argStt = "no";}
	var winArgs = "width="+ww+",height="+wh+",scrollbars="+argSbar+",resizable="+argRes+",status="+argStt;
	winArgs = winArgs + ",dependent=yes,dialog=yes,minimizable=no,modal=yes,alwaysRaised=yes";
	var winUrl = (!qry)? "popup.cfm" : "popup.cfm?"+qry;
	winPop = window.open(winUrl,winNam,winArgs);
	if (winPop) {winPop.focus();winPop.dialogArguments = winArgs;}
}

n = navigator.userAgent.toLowerCase();
op = !!(window.opera && document.getElementById);
ie = !!(n.indexOf("msie") >= 0 && document.all && !op);

function io_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=io_SearchObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

// set footer on pos
d.imglis = "ioLAYER10000img";
d.showAutoFoot = true;
function io_FootLayer(imglis,x) 
{
	if (x == 'i') { d.showAutoFoot = true; }
	if (imglis) { d.imglis = imglis; }
	// get objects
	nav = io_SearchObj("webLayFootImg");
	fot = io_SearchObj("webLayFoot");
	// get subnav (minpos)
	pos_sub = io_GetCoordXY(nav);
	// contents (list)
	arr = d.imglis.split(",");
	// eval maxpos
	pos_tmp = 0; pos_min = 500; pos_now = Number(pos_sub.y);
	// loop all positions
	for (i=0;i<arr.length;i++) {
		if (isNaN(arr[i])) {
			con = io_SearchObj(arr[i]);
			pos_img = io_GetCoordXY(con);
			pos_tmp = pos_img.y;
		} else {
			pos_tmp = Number(arr[i]);
		}
		// compare
		pos_now = (pos_tmp>pos_now)? pos_tmp : pos_now;
	}
	// min 450
	pos = (pos_now < pos_min)? pos_min : (pos_now+10);		
	// set footer
	fot.style.top = (pos+35)+"px";
	if (d.showAutoFoot) { fot.style.visibility = "visible";	}
}

// show clicked images (impression)
function io_swapBigImage(pos) 
{
	if (!pos) {pos = 0;} d.showAutoFoot = false;
	try { 
		fot = io_SearchObj("webLayFoot"); if (fot != null) {fot.style.visibility = "hidden";}
		document.getElementById("imgShowInfo").innerHTML = 'loading... ('+imgName[pos]+')';		
		document.getElementById("imgShow").src = 'http://www.mslu.ch/_ecm/img/ai_ph.gif'; 
		document.imgBigNew = new Image(); document.imgBigNew.src = unescape(imgBig[pos]);
		document.imgBigInfo = new String(); document.imgBigInfo = unescape(imgName[pos]);	
		checkload = setTimeout("io_checkImageLoading()",100);
	} catch(e) { alert (e); }
}
function io_checkImageLoading() 
{
	if (document.imgBigNew.complete == true) {
		clearTimeout(checkload); 
		document.getElementById("imgShow").src = document.imgBigNew.src;		
		document.getElementById("imgShowInfo").innerHTML = 'Image: '+document.imgBigInfo;	
		setTimeout("io_FootLayer('','i')",1000);
	} else {
		checkload = setTimeout("io_checkImageLoading()",200);
	}
}

function formColorStyle(obj, rgb) {
	obj.style.backgroundColor = rgb;
	return;
}

function formCheckingStyle() {
	d.errview = d.errview+1;
	//d.fld.value = d.errview;
	if (d.ftyp == 's') {
		fsi = d.fld.options[d.fld.selectedIndex].value;
		if (fsi.NaN) {
			if (fsi != "") {
				formColorStyle(d.fld, ""); clearInterval(d.errcount);	
			}
		} else if (fsi != 0) {
			formColorStyle(d.fld, ""); clearInterval(d.errcount);		
		}
	} else if (d.ftyp == 'e') {
		if (d.fld.value.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)) {
			formColorStyle(d.fld, ""); clearInterval(d.errcount);				
		}
	} else if (d.ftyp == 'n') {
		if (d.fld.value.length > 0) {
			if (!isNaN(d.fld.value)) {
				formColorStyle(d.fld, ""); clearInterval(d.errcount);	
			}				
		}
	} else if (d.ftyp == 'bs') {
		if (d.fld.checked) {	
			formColorStyle(d.fld, ""); clearInterval(d.errcount);
		}		
	} else if (d.ftyp == 't') {
		if (d.fld.value.length > 0) {	
			formColorStyle(d.fld, ""); clearInterval(d.errcount);
		}
	}
	if (d.errview > 40) {
		formColorStyle(d.fld, ""); clearInterval(d.errcount);		
	}
}

function formErrorStyle(fld, ftyp) {
	try {
		d.fld = fld; d.ftyp = ftyp;
		formColorStyle(d.fld, "#CCFFFF"); //CCFFCC
		d.errview = 0; 
		d.errcount = setInterval("formCheckingStyle()", 100);
	} catch (e) {}
	finally {return;}
}

// ENDE muss von Marcel noch überarbeitet werden

function io_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;
}

function formValidate()
{
	var i,j=-1,o,a=formValidate.arguments;
	var errmy=true,errbs=false,msg='',otyp='';
	//alert (a.length);
	if (a.length>0) {
		for(i=0;i<a.length;i+=2) {
			j++;		
			if ((o=io_SearchObj(a[i]))!=null) {		
				if (!o.disabled) {

					otyp=a[i+1];
					if (otyp!='ba' && otyp!='bs') {formColorStyle(o, "");}
					
					if (otyp=='e') {		
						
						if (!o.value) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (o.value && !o.value.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)){
							errmy = true; msg = d.valmsg[j+1]; i=a.length;
						} else if (o.value && o.value.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)){
							j++;
						} else {errmy = false;}
								
					} else if (otyp=='t') {
					
						if (!o.value) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else {errmy = false;}		
														
					} else if (otyp=='n') {
						if (!o.value || isNaN(o.value)) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else {errmy = false;}					
					
					} else if (otyp=='s') {
						
						var osv = o.options[o.selectedIndex].value;
						
						if (!o.options[o.selectedIndex]) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (osv.NaN) {
							if (osv == "") {
								errmy = true; msg = d.valmsg[j]; i=a.length;
							}			
						} else if (osv <= 0) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else {errmy = false;}	
						
					} else if (otyp=='ba') {
					
						if (o.length) {
							tmperrmy = false;
							for (p=0;p<o.length;p++) {
								if (!o[p].checked) {
									tmperrmy = true;
									break;
								}
							}
							if (tmperrmy) {
								errmy = true; msg = d.valmsg[j]; i=a.length;
							}
						} else if (!o.length && !o.checked) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (!o.length) {errmy = false;}	
					
					} else if (otyp=='bs') {
				
						if (o.length) {
							tmperrmy = true;
							for (p=0;p<o.length;p++) {
								if (o[p].checked) {
									o[p].checked = true;
									tmperrmy = false;
									break;
								}
							}
							if (tmperrmy) {
								errmy = true; msg = d.valmsg[j]; i=a.length;
							}
						} else if (!o.length && !o.checked) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (!o.length) {errmy = false;}						
						
						/*		
						if (!errbs && o.checked) {
							o.checked = true;					
							errmy = false; errbs=true;
						} else if (!errbs && !o.checked) {
							errmy = true; msg = d.valmsg[j]; j--;
						}
						*/
						 		
					}
					if (errmy) {break;}
				}
			}
		}		
	} else {
		errmy=false;
	}
	
	if (errmy) {			
		if ((m=io_SearchObj(d.valinfo))!=null) {
			m.className = "x1rt"; 
			m.innerHTML = unescape(msg);
		} else {
			alert(unescape(msg));
		} 		
		if (otyp!='ba' && otyp!='bs' && o) {
			o.focus(); 
			formErrorStyle(o, otyp); 
		} else if ((m=io_SearchObj(d.valinfo))!=null) {
			m.className = "x1rt"; m.innerHTML = "Formfield to validate!?";
		}			
		return false;		
	} else {	
		if ((m=io_SearchObj(d.valinfo))!=null) {m.className = "x1gr"; m.innerHTML = unescape(d.saveinfo);}		
		return true;
	}
}
