// JavaScript Document

// global settings
networkpagename = "net.cfm";
var uc=""; // userclicks
var ucinfo="";

ie = document.all?1:0
ns4 = document.layers?1:0

// rowselector
function allselector(formname){
	var evenoddcounter = 1;
	for (var i=0;i<formname.elements.length;i++)
	{
	var e = formname.elements[i];
	if ((e.name != 'allbox') && (e.type=='checkbox')) {
		e.checked = formname.allbox.checked;
		if (formname.allbox.checked) 
			hL(e);
		else 
			if (evenoddcounter==1) {
				dL(e,'tableodd');
				evenoddcounter = 2;
				}
			else {
				dL(e,'tableeven');
				evenoddcounter = 1;
				}
		}
	}
	if (formname.allbox.checked) {
		formname.action.disabled = 0;
		formname.fuseactionsubmit.disabled = 0;
	}
	else {
		formname.action.disabled = true;
		formname.fuseactionsubmit.disabled = true;
	}
}

function selector(row,formname,rowstyle){
	if (row.checked) {
		hL(row);
		formname.action.disabled = 0;
		formname.fuseactionsubmit.disabled = 0;
		}
	else
		dL(row,rowstyle);
	var TB=TO=0;
	for (var i=0;i<formname.elements.length;i++) {
		var e = formname.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			TB++;
			if (e.checked) TO++;
		}
	}
	if (TO==TB)
		formname.allbox.checked=true;
	else
		formname.allbox.checked=false;
	if (TO==0) {
		formname.action.disabled = true;
		formname.fuseactionsubmit.disabled = true;
	}
}

function hL(R){
	if (ie) {
		while (R.tagName!="TR")
		{R=R.parentElement;}
	}
	else
	{
		while (R.tagName!="TR")
		{R=R.parentNode;}
	}
	R.className = "highlighted";
}

function dL(R,rowstyle){
	if (ie)
	{
	while (R.tagName!="TR")
	{R=R.parentElement;}
	}
	else
	{
	while (R.tagName!="TR")
	{R=R.parentNode;}
	}
	R.className = rowstyle;
}
// end rowselector

// contact channel group selector
function checkpriv(status,thisform){
	var f = eval('document.'+thisform);
	f.show_email_priv.checked = f.show_phone_priv.checked = f.show_fax_priv.checked = f.show_address_priv.checked = f.show_mobile.checked = f.show_url_priv.checked = status;
}
function checkbiz(status,thisform){
	var f = eval('document.'+thisform);
	f.show_company.checked = f.show_email_biz.checked = f.show_phone_biz.checked = f.show_fax_biz.checked = f.show_address_biz.checked = f.show_url_biz.checked = status;
}     

// check text length
function checklength(formname,fieldname,maxsize,message) { 
	var wert, max;
	max = maxsize;
	thisfield=eval('document.'+formname+'.'+fieldname);
	currentlen = max-thisfield.value.length;
	if (currentlen < 0) {
		alert(message);
		thisfield.value = thisfield.value.substring(0,max);
		currentlen = max-thisfield.value.length;
	}
}

// open window
function openwindow(url,name,options) {
newwin=window.open(url,name,options);
newwin.focus();
}

// check if a value is an integer
function _checkinteger(object_value){
	if (object_value.length == 0)
		return true;
	//Returns true if value is an integer defined as
	//   having an optional leading + or -.
	//   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;
	
	check_char = object_value.indexOf(decimal_format)
	if (check_char < 1)
		return _checknumber(object_value);
	else
		return false;
}
	function _checknumber(object_value){
	if (object_value.length == 0)
	   return true;
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	check_char = start_format.indexOf(object_value.charAt(0))
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;
	for (var i = 1; i < object_value.length; i++)
	{
	check_char = number_format.indexOf(object_value.charAt(i))
	if (check_char < 0)
	return false;
	else if (check_char == 1)
	{
	if (decimal)
		return false;
	else
		decimal = true;
	}
	else if (check_char == 0)
	{
	if (decimal || digits)	
	trailing_blank = true;
	}
	    else if (trailing_blank)
	return false;
	else
		digits = true;
	}
	return true
}

// rowblock switch
function showhiderowblock(ID,imgID){
	var obj = document.getElementById(ID);
	var img = document.getElementById(imgID);
	if(obj.style.display == 'none') {
		obj.style.display ='';
		img.src=curl+'siteimg/util/minus.gif';
	}
	else {
		obj.style.display ='none';
		img.src=curl+'siteimg/util/plus.gif';
	}
}

// show an element, hide another
function shownextblock(ID,hideID){
	var aCloseIDs = hideID.split(",");
	var cntr=0;
	var obj = document.getElementById(ID);
	while (cntr < aCloseIDs.length) {
		hideobj = document.getElementById(aCloseIDs[cntr]);
		if(hideobj)
			hideobj.style.display ='none';
		cntr+=1;
	}
	obj.style.display ='';
}

// tab switch
function showtab(tabsetnr,pagenr,total,gotop){
	tab = document.getElementById('T'+tabsetnr+'current');
	tab.id=eval('T'+tabsetnr+'currenttab');
	for (p = 1; p <= total; p++) {
		obj = document.getElementById('T'+tabsetnr+'p'+p);
		if (p==pagenr) {
			obj.style.display ='';
			ctab = document.getElementById('T'+tabsetnr+'tab'+p);
			ctab.id='T'+tabsetnr+'current';
			if (tabsetnr==1) T1currenttab='T'+tabsetnr+'tab'+p;
			else if (tabsetnr==2) T2currenttab='T'+tabsetnr+'tab'+p;
			else if (tabsetnr==3) T3currenttab='T'+tabsetnr+'tab'+p;
			else if (tabsetnr==4) T4currenttab='T'+tabsetnr+'tab'+p;
		}
		else {
			obj.style.display ='none';
			ctab = document.getElementById('T'+tabsetnr+'tab'+p);
			ctab.id='T'+tabsetnr+'tab'+p;
		}
	}
	if (gotop==1)
		document.location='#top';
}

// form: multiple checkbox selector
function allcheckboxes(formname,field){
	for (var i=0;i<formname.elements.length;i++) {
		var e = formname.elements[i];
		if ((e.name != 'all'+field) && (e.type=='checkbox') && (e.name==field)) {
			e.checked = eval('formname.all'+field+'.checked');
		}
	}
}
			
// form: multilanguage texts with show/hide-feature
function showhidelangrow(lang,formname){
	var f=eval('document.'+formname);
	for(i=0;i<f.length;i++){
		var j=f.elements[i].name;
		var jlang=j.substr(j.length-3,3);
		var b=false;
		if (lang=='all') {
			var langdiv = document.getElementById('mldiv'+j);
			if (langdiv) {
				aTemplang=String(langdiv.id).split("_");
				var ccheckbox = document.getElementById('show_form'+aTemplang[1]);
				if (f.show_formall.checked) {
					langdiv.style.display ='';
					ccheckbox.checked = f.show_formall.checked;
					}
				else 
					langdiv.style.display ='none';
					ccheckbox.checked = f.show_formall.checked;
			}
		} else if ('_'+lang==jlang) {
			var langdiv = document.getElementById('mldiv'+j);
			if (eval('f.show_form'+lang+'.checked'))
				langdiv.style.display ='';
			else {
				langdiv.style.display ='none';
				f.show_formall.checked = false;
			}
		}
	}
}

// form: radiobuttons - selection shows/hides certain areas 
function areashowhide(formname,radiofield,valuelist){
	var aAreas = valuelist.split(",");
	var fld = eval(formname+'.'+radiofield+'.getValue()');
	var val_num=0;
	while (val_num < aAreas.length) {
		obj = document.getElementById('area'+aAreas[val_num]);
		if(obj) {
			if (fld==aAreas[val_num]) 
				obj.style.display ='';
			else
				obj.style.display ='none';
		}
		val_num+=1;
	}
}

// form: help texts
function formhelpshowhide() {
var h=document.getElementsByTagName('span');
var fld = objForm.show_formhelp.getValue();
for(i=0;i<h.length;i++){
    if(h[i].className=='formrowhelp'){
		if (fld)
	        h[i].style.display ='';
		else
			h[i].style.display ='none';
        }
    }
}

function areashowall(valuelist){
	var aAreas = valuelist.split(",");
	var val_num=0;
	while (val_num < aAreas.length) {
		obj = document.getElementById('area'+aAreas[val_num]);
		if(obj) 
			obj.style.display ='';
		val_num+=1;
	}
}

// form: action setter
function setformaction(newaction,thisform){ 
	var f = eval('document.'+thisform);
	f.fuseaction.value = newaction;
}

// form: set other language text
function setText(form,field,obj) {
	var f = eval('document.'+form+'.'+field);
	if (f.value == '') f.value = obj.value;
}

// form: multiple selection
function add_ID(field) {
	var o=eval('document.mainform.'+field+'_select');
	var cID = o.options[o.selectedIndex].value;
	var was = document.getElementById(field+'_'+cID);
	if ((cID > 0) && !was) {
		var ctxt = o.options[o.selectedIndex].text;
		var t = document.getElementById(field+'_selected');
  			var r = document.createElement("TR");
		r.setAttribute("id",field+"_"+cID);
   		var c = document.createElement("TD");
		var c2 = document.createElement("TD");
   		r.appendChild(c);
		r.appendChild(c2);
   		t.appendChild(r);
  			c.innerHTML = ctxt + '<input type="hidden" name="'+field+'" value="'+cID+'">';
		c2.innerHTML = '<a href="Javascript:delete_ID(\''+field+'\','+cID+');"><img src="'+curl+'siteimg/icons/16/delete.gif" width="16" height="16" align="absmiddle"></a>'; 
		o.selectedIndex = 0;
	}
}
function delete_ID(field,ID) {
	var t = document.getElementById(field+'_selected');
	var r = document.getElementById(field+'_'+ID);
	t.removeChild(r);
}
// form: upload check mime type
function checkMimeType(f,m,n,oMimeTypes) {
	var file = f.value;	
	var found = false;
	if (file != '') {
		var ext = file.substring(file.lastIndexOf('.') + 1, file.length);
		ext = ext.toLowerCase();
		for(var mext in oMimeTypes) {
			if (ext==mext) {
				found = true;
				if(m&&n){
					if(oMimeTypes[mext]) {
					   m.style.display = "";
					   n.checked = false;
					   } else m.style.display = "none";
				}	
			}	
		}
		if (!found) {		
			if(m&&n) m.style.display = "none";	
			return false;
		}
	}	
	return true;	
}
// form: upload preview
function doPreview(f, iNr, maxw, maxh){
	if(document.all) {
	preImg = new Image(); 
	preImg.setImage = function() {
			var w = maxw;
			var h = maxh;
			if(preImg.width>0 && preImg.height>0) {
				if(preImg.width<w && preImg.height<h) {
					w = preImg.width;
					h = preImg.height;
				} else {						
					if(preImg.width>preImg.height)
						h = (preImg.height*w)/preImg.width;
					else
						w = (preImg.width*h)/preImg.height;
				}	
			}	
				document.getElementById('previewimage' + iNr).src=preImg.src;
				document.getElementById('previewimglink' + iNr).href=curl+'apps/services/popupimage.cfm?viewmode=1&img='+preImg.src+'&title='+preImg.src+'&w='+preImg.width+'&h='+preImg.height+'&id='+iNr;
				document.getElementById('previewimage' + iNr).width=w;
				document.getElementById('previewimage' + iNr).height=h;
				document.getElementById('imagewidth' + iNr).innerHTML=preImg.width;
				document.getElementById('imageheight' + iNr).innerHTML=preImg.height;
				document.getElementById('ImagePreview' + iNr).style.display="";
	}
	preImg.attachEvent("onload",preImg.setImage);
	document.getElementById('span_imagesize' + iNr).style.display="";
	preImg.src = f.value;		
	}
}

// client-side list paging
function showlistpage(listnr,pagenr,total){
	// set old active tab to inactive
	listpage_current=eval('L'+listnr+'listpage_current');
	if (listpage_current>0) {
		tab = document.getElementById('L'+listnr+'current');
		tab.id='L'+listnr+'tab'+listpage_current;
		tab = document.getElementById('L'+listnr+'currentbottom');
		tab.id='L'+listnr+'tab'+listpage_current+'bottom';
	} else {
		tab = document.getElementById('L'+listnr+'current');
		tab.id='L'+listnr+'_all_top';
		tab = document.getElementById('L'+listnr+'currentbottom');
		tab.id='L'+listnr+'_all_bottom';
	}
	listpage_current=pagenr; // 2optimize:
	if (listnr==1) L1listpage_current = pagenr;
	else if (listnr==2) L2listpage_current = pagenr;
	else if (listnr==3) L3listpage_current = pagenr;
	else if (listnr==4) L4listpage_current = pagenr;
	for (lp = 1; lp <= total; lp++) {
		obj = document.getElementById('L'+listnr+'lp'+lp);
		if (lp==pagenr) {
			obj.style.display ='';
			tab = document.getElementById('L'+listnr+'tab'+lp);
			tab.id='L'+listnr+'current';
			tab = document.getElementById('L'+listnr+'tab'+lp+'bottom');
			tab.id='L'+listnr+'currentbottom';
		}
		else {
			obj.style.display ='none';
		}
	}
	if (total > 3) {
		obj = document.getElementById('L'+listnr+'_first_top');
		if (listpage_current > 1) 	
			obj.style.display ='';
		else
			obj.style.display ='none';
		obj = document.getElementById('L'+listnr+'_first_bottom');
		if (listpage_current > 1) 	
			obj.style.display ='';
		else
			obj.style.display ='none';
		obj = document.getElementById('L'+listnr+'_last_top');
		if (listpage_current < total)
			obj.style.display ='';
		else
			obj.style.display ='none';
		obj = document.getElementById('L'+listnr+'_last_bottom');
		if (listpage_current < total)
			obj.style.display ='';
		else
			obj.style.display ='none';
	}
	obj = document.getElementById('L'+listnr+'_previous_top');
	if (listpage_current > 1) 	
		obj.style.display ='';
	else
		obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'_previous_bottom');
	if (listpage_current > 1) 	
		obj.style.display ='';
	else
		obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'_next_top');
	if (listpage_current < total) 	
		obj.style.display ='';
	else
		obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'_next_bottom');
	if (listpage_current < total) 	
		obj.style.display ='';
	else
		obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'listalltitle_top');	obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'listalltitle_bottom');	obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'listpagetitle_top');	obj.style.display =''; 
	obj = document.getElementById('L'+listnr+'listpagetitle_bottom');	obj.style.display =''; 
	obj = document.getElementById('L'+listnr+'listpagenr_top'); obj.innerHTML=listpage_current;
	obj = document.getElementById('L'+listnr+'listpagenr_bottom'); obj.innerHTML=listpage_current;
}
function showlistpageall(listnr,total){
	var listpage_current=eval('L'+listnr+'listpage_current');
	if (total>1 && listpage_current>0) {
		tab = document.getElementById('L'+listnr+'current');
		tab.id='L'+listnr+'tab'+listpage_current;
		tab = document.getElementById('L'+listnr+'_all_top');
		tab.id='L'+listnr+'current';
		tab = document.getElementById('L'+listnr+'currentbottom');
		tab.id='L'+listnr+'tab'+listpage_current+'bottom';
		tab = document.getElementById('L'+listnr+'_all_bottom');
		tab.id='L'+listnr+'currentbottom';
	} else {
		// tab = document.getElementById('_all_top');
	}
	listpage_current=0; // 2optimize:
	if (listnr==1) L1listpage_current = 0;
	else if (listnr==2) L2listpage_current = 0;
	else if (listnr==3) L3listpage_current = 0;
	else if (listnr==4) L4listpage_current = 0;
	for (lp = 1; lp <= total; lp++) {
		obj = document.getElementById('L'+listnr+'lp'+lp);
		obj.style.display ='';
	}
	if (total > 3) {
		obj = document.getElementById('L'+listnr+'_first_top'); obj.style.display ='none';
		obj = document.getElementById('L'+listnr+'_first_bottom'); obj.style.display ='none';
		obj = document.getElementById('L'+listnr+'_last_top'); obj.style.display ='none';
		obj = document.getElementById('L'+listnr+'_last_bottom'); obj.style.display ='none';
	}
	obj = document.getElementById('L'+listnr+'_previous_top'); obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'_previous_bottom'); obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'_next_top'); obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'_next_bottom'); obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'listalltitle_top');	obj.style.display ='';
	obj = document.getElementById('L'+listnr+'listalltitle_bottom');	obj.style.display ='';
	obj = document.getElementById('L'+listnr+'listpagetitle_top');	obj.style.display ='none';
	obj = document.getElementById('L'+listnr+'listpagetitle_bottom');	obj.style.display ='none';
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// resolution dependent layout script
function checkBrowserWidth() {
	var theWidth = getBrowserWidth();
	if (theWidth > 1150) {
		if (readCookie("resolution")!="hi") {
			setStylesheet("hires");
			document.cookie = "resolution=hi";
			document.location.reload();
		}
	} else {
		if (readCookie("resolution")!="lo"){
			setStylesheet("lores");
			document.cookie = "resolution=lo";
			document.location.reload();
		}
	}
	return true;
}

function getBrowserWidth() {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && document.documentElement.clientWidth ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && document.body.clientWidth ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}

function setStylesheet(styleTitle) {
	var currTag;
	if (document.getElementsByTagName) {
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++) {
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title")) {
				currTag.disabled = true;
				if(currTag.getAttribute("title") == styleTitle)
					currTag.disabled = false;
			}
		}
	}
	return true;
}

function user(id,h,uc,ucindinfo,fuseaction) {
	var uci="";
	if (arguments.length > 3)
		uci='&uci='+ucindinfo;
	else if (ucinfo.length > 0)
		uci='&uci='+ucinfo;
	if (arguments.length < 5)
		fuseaction='Overview';
	document.location=networkpagename+'?fuseaction=userprofile.user&nextaction=userprofile.'+fuseaction+'&user_ID='+id+'&h='+h+'&uc='+uc+uci;
}

function ovlCust(headline,content,cwidth) {
	overlib(content, STICKY, CAPTION,'&nbsp;'+headline+':', WIDTH, cwidth, BELOW, OFFSETX, -20, OFFSETY, 0, CELLPAD, 4, 4, CLOSETEXT, '<img src="'+curl+'siteimg/util/closepop.gif" width="14" height="14" alt="" border="0">', CAPCOLOR, '#000000', CAPTIONSIZE, '11px', TEXTSIZE, '11px', FGCOLOR, '#FFFFFF', BGCOLOR, '#e9e9e9', BORDER, 2);
}

var iclose= new Image(); 
iclose.src = curl+'siteimg/util/closepop.gif'; // preload

// detailpage breadcrumb navi
function getDetailpageNavi(){
	if(document.getElementById('detailpagetext')!=null){
		var obj = document.getElementById('detailpagenavi');
		var textdetail= document.getElementById('detailpagetext').innerHTML;
		if (obj) {
			obj.innerHTML=textdetail;
		}
	}
}

//reloads the window if Nav4 resized
function MM_reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// for ajax features
//resets input-fields
function clearInputField(field,defaultValue){
	if(field && field.type=="text"){
		if(field.value==defaultValue) 
			field.value="";
		if(!field.onblur)
			field.onblur=function(){
				if(this.value=="") 
					this.value=defaultValue;
			}
	}
	else if(field && field.type=="textarea"){
		if(field.innerHTML==defaultValue) 
			field.innerHTML="";
		if(!field.onblur)
			field.onblur=function(){
				if(this.innerHTML=="") 
					this.innerHTML=defaultValue;
			}			
	}	
}

function isDefined(variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}

