/*
	iracer 3.0
	Javascipt-Unterstützung für die Administration
	Programmierung:		Andrei Tandoev
	Datum:				25.10.2000

	$Id: $
	$Log: $

*/
ns_flag = ( document.layers )? true : false;
ie4_flag = ( document.all )? true : false;
ie5_flag = false;

/*
 Falls die obige prüfung nicht hinhaut, kann auch diese genommen werden:
 
 var isMinNS4=(navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4)?1:0;
 var isMinIE4=(document.all)?1:0;
 var isMinIE5=(isMinIE4&&navigator.appVersion.indexOf("5.")>=0)?1:0;
*/

if( ie4_flag ) ie5_flag = navigator.userAgent.indexOf( 'MSIE 5' ) > 0;

function OnOpenCustomPopupWindow(void1, t, x, y, w, h, u, void2){
	var wndCustomPopupWindow = window.open('', 'wndCustomPopupWindow', 'left='+x+',top='+y+',pos-x='+x+',pos-y='+y+',width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=1,menubar=1');
	wndCustomPopupWindow.document.write('<html><title>'+t+'</title><body>Please wait...</body></html>');
	wndCustomPopupWindow.location.href=u;
	wndCustomPopupWindow.focus();
}

function openSitemap(){ //oeffnet das sitemap-fenster; 12.12.2000; cjohn
	window.open('sitemap.cfm', 'frmSitemap', 'width=300,height=450,resizable=yes,scrollbars=yes');
}
function onClickSitemap(newLocation){
	window.opener.location=newLocation;
}

/*
  Webshop
*/
function onDeletePrice( form_name, id ) {
	frm = eval( 'document.' + form_name );
	frm.del_price_list_id.value = id;
	frm.cmd.value = "save";
	frm.submit();
}

function OnAddBooking( form_name, id) {
	frm = eval('document.' + form_name );
	frm.bo_book.value = '1';
	frm.submit();
}

function onClickAccess( form_name, accid, objid, mi, vmax ) {
	frm = eval( 'document.' + form_name );
	fld = eval( 'document.' + form_name + '.data_' + accid );
	chg = eval( 'document.' + form_name + '.changed_' + accid );
	if( (!fld)  ||  (!chg) )  return;
	v = fld.value;
	if( v == '' ){
		v = 1;}
	else if( v < vmax ){
		v = parseInt(v) + 1;}
	else{
		v = 1;}
	fld.value = v;
	chg.value = 1;
	img = eval( 'document.' + form_name + '.img_' + accid );
	mand_img = eval( 'document.' + form_name + '.sign_' + v );
	img_text = eval( 'document.' + form_name + '.text_' + v );
	mand_text = eval( 'document.' + form_name + '.mand_text_' + mi );
	obj_text = eval( 'document.' + form_name + '.obj_text_' + objid );
	if( (!mand_img)  ||  (!img)  ||  (!mand_text)  ||  (!obj_text)  ||  (!img_text) )  return;
	img.src = mand_img.value;
	img.alt = mand_text.value + "/" + obj_text.value + ": " + img_text.value;
}

function onClickCheckbox( form_name, chk, val, func ) { // Checkbox
	frm = eval( "document." + form_name );
	ctl = eval( "document." + form_name + '.' + chk );
	if( val  &&  ctl.length ) {
		for( i=0; i<ctl.length; i++ ) {
			if( ctl[i].value == val )
				 ctl[i].checked = ! ctl[i].checked;
		}
	} else{
		ctl.checked = ! ctl.checked;}
	if( func ){
		func( form_name, chk, val );}
}

function onClickRadio( chk, val ) {
	ctl = eval( "document." + chk );
	if( ctl ) {
		if( ctl.length ){
			for( i=0; i<ctl.length; i++ ) ctl[i].checked = ctl[i].value == val;}
		else{
			ctl.checked = ctl.value == val;}
	}
}

function onSetShowHide( div, vis ) {
	if( vis == true ){
		document.all[div].style.setAttribute( 'display', 'inline', false );}
	else{
		document.all[div].style.setAttribute( 'display', 'none', false);}
}

function onShowHide( div ) {
	if( document.all[div].style.display == 'none' ){
		document.all[div].style.setAttribute( 'display', 'inline', false );}
	else{
		document.all[div].style.setAttribute( 'display', 'none', false);}
}

function onEditObject( form_name, field_name, new_id ) {
	onClickObject( form_name, field_name, new_id );
	frm = eval('document.' + form_name);
	frm.cmd.value = "edit";
	frm.submit();
	if (parent.frmStatus){
		parent.frmStatus.location.href='../admin/status.cfm?wait=1';
	}
}

function onSort( form_name, field_name, sort_id ) {
	frm = eval('document.' + form_name);
	frm.cmd.value = "sort";
	frm.obj_id.value = sort_id;
	frm.submit();
}

function onClickObject( form_name, field_name, new_id ) {
	cur_id = eval('document.' + form_name + '.' + field_name + '.value');
	img = eval('document.' + form_name + '.' + field_name + '_img_' + new_id);
	if( img )  img.src = '../imgadmin/hand.gif';
	eval('document.' + form_name + '.' + field_name).value = new_id;
}

function ListOperation( list, id, op ) {
	id = "" + id;  // sonst funktioniert "id.length" nicht
	if( op == 1 ) { // delete
		bin = true;
		while( bin ) {
			bin = false;
			if( list == id ){
				list = '';
			} else if( list.substring(list.length-id.length-1,list.length) == ',' + id ) {
				list = list.substring(0,list.length-id.length-1);
				bin = true;
			} else if( list.substring(0,id.length+1) == id + ',' ) {
				list = list.substring(id.length+1,list.length);
				bin = true;
			} else {
				p = list.indexOf(',' + id + ',');
				if( p >= 0 ) {
					list = list.substring(0,p+1) + list.substring(p+id.length+2,list.length);
					bin = true;
				}
			}
		}
	} else { // add
		if( list != '' )  list = opened_objects + ',';
		list = list + id;
	}
	return list;
}

function onClickPlusMinusForm( form_name, field_name, id, op, em ) {
	opened_objects = eval('document.' + form_name + '.' + field_name + '_opened.value');
	eval('document.' + form_name + '.' + field_name + '_opened').value = ListOperation( opened_objects, id, op );
	if( em ){
		if( em == 0 ){
			eval('document.' + form_name + '.' + field_name).value = '';}}
	frm = eval('document.' + form_name);
	frm.submit();
}

function onClickPlusMinusCookie( cookie_name, id, op, href ) {
	opened_objects = "";
	oo = GetCookie( cookie_name );
	if( oo ) {
		if( oo.indexOf("null") >= 0 )  oo = "";
		opened_objects = oo;
	}
	oo = ListOperation( opened_objects, id, op );
	SetCookie( cookie_name, oo );
	location.href = href;
}
function DisabledForm(form_name){
	if (document.forms[form_name]){
		var f = document.forms[form_name];
		var e = f.elements;
		for (i=0;i<e.length;i++){
			if (e[i].type=='button'||e[i].type=='submit'){
				fe = e[i];
				fe.disabled=true;
				fe.enabled=false;
				if(document.all){
					if (fe.style)fe.style.setAttribute('color','silver',false);
				} else {
					fe.style.color = 'silver';
				}
			}
		}
	}
}
function onButtonClick( form_name, cmd, fld ) {
	DisabledForm(form_name);
	if( ! fld )  fld = 'cmd';
	fld = eval('document.' + form_name + '.' + fld);
	fld.value = cmd;
	frm = eval('document.' + form_name);
	frm.submit();
	if (parent.frmStatus){
		parent.frmStatus.location.href=intranetpath + 'admin/status.cfm?wait=1';
	}
}

/* Checkin für Workflow-Modus "PUSH" */
function OpenWorkflowAssign(form_name,obj_type,obj_id,cmd) {
	//DisabledForm(form_name);
	a_href = '../admin/workflow_assign.cfm?obj_type=' + obj_type + '&obj_id=' + obj_id + '&caller_form_name=' + form_name + '&cmd=' + cmd;
	window.open(a_href,'assign_workflow','width=650,height=550,top=50,left=50,resizable=yes,scrollbars=yes,toolbar=no,menubar=no');
}

function onHistoryRestore( form_name, vid ) {
	eval('document.' + form_name + '.restore_version_id').value = vid;
	onButtonClick( form_name, 'restore' );
}

function onOpenHref( href, trg ) {
  	var wndhr = window.open( intranetpath + 'admin/empty.html',trg,'dependent=yes,hotkeys=no,locationbar=no,menubar=no,resizable=yes,scrollbars=yes');
	alert('!');
		wndhr.location.href = href;
   	if ( wndhr.opener == null ){
		wndhr.opener = window;}
	wndhr.focus();

}

function onOpenHrefwh( href, trg, t, l, w, h ) {
  	var wndhr = window.open( intranetpath + 'admin/empty.html',trg,'top='+t+',left='+l+',width='+w+',height='+h+',dependent=yes,hotkeys=no,locationbar=no,menubar=no,resizable=yes,scrollbars=yes');
	wndhr.location.href = href;
   	if ( wndhr.opener == null ){
		wndhr.opener = window;}
	wndhr.focus();
}

function onOpenHrefwhEx( href, trg, t, l, w, h ) {
  	var wndhr = window.open( intranetpath + 'admin/empty.html',trg,'top='+t+',left='+l+',width='+w+',height='+h+',dependent=yes,hotkeys=no,locationbar=no,menubar=no,resizable=no,scrollbars=no');
	wndhr.location.href = href;
   	if ( wndhr.opener == null ){
		wndhr.opener = window;}
	wndhr.focus();
}

function onHistoryPreview( uuid, vid, fid ) {
	if( ! fid )  fid = '';
	var href = intranetpath + 'index.cfm?uuid=' + uuid + '&preview_version_id=' + vid + '&field_id=' + fid + '&mode=preview&use_cache=0';
  	var wndprv = window.open( intranetpath + 'admin/empty.html','preview','dependent=yes,hotkeys=no,locationbar=no,menubar=no,resizable=yes,scrollbars=yes');
	wndprv.location.href = href;
   	if ( wndprv.opener == null ){
		wndprv.opener = window;}
	wndprv.focus();
}

function onObjectDelete( form_name, msg ) {
	if( confirm( msg ) ) {
		frm = eval( 'document.' + form_name );
		frm.cmd.value = "delete";
		frm.submit();
	}
}
var recurs_resize = 0;
function onResize( div_name, focus_name ) {
//return; // FEHLER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if( recurs_resize != 0 ) return;
	recurs_resize = 1;
	if( document.all ) {
		area = document.all[div_name];
		if( area ) {
			if( area.style ) {
				body = document.body;
				h = body.clientHeight - area.offsetTop - area.style.border;
				h = h - 16;
				if( h > 0 )
					area.style.height = h;
				w = body.clientWidth - area.offsetLeft - area.style.border;
				ww = area.style.getAttribute('width','false');
			}
		}
		if( focus_name ){
			if( focus_name != '' ) {
				fn = document.all[focus_name];
				if( fn )  fn.focus();
			}
		}
	}else{
		alert('!');
	}
	recurs_resize = 0;
}
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1){
		endstr = document.cookie.length;}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie( name ) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while( i < clen ) {
		var j = i + alen;
		if( document.cookie.substring(i, j) == arg )
			return getCookieVal( j );
		i = document.cookie.indexOf(" ", i) + 1;
		if( i == 0 )  break; 
	}
	return null;
}

function SetCookie( name, value ) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 4) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain));
}

function DeleteCookie(name){
	exp=new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie ("name");
	document.cookie = name + "=" + cval +"; expires=" + exp.toGMTString();
}

function onDummy() {
}

function onFrontendEdit( uuid ) {
	alert( 'Noch nicht ...' );
}

function onMoveDown( form_name, listname ) {
	ctl = eval( 'document.' + form_name + '.' + listname );
	if( ! ctl )  return;
	n = ctl.length;
	if( ctl.options[n-1].selected ){
		return;}
	for( i=n-2; i>=0; i-- ) {
		if( ctl.options[i].selected ) {
			tmp1 = new Option( ctl.options[i+1].text );
			tmp1.value = ctl.options[i+1].value;
			tmp = new Option( ctl.options[i].text );
			tmp.value = ctl.options[i].value;
			ctl.options[i] = tmp1;
			ctl.options[i+1] = tmp;
			ctl.options[i+1].selected = true;
		}
	}
}

function onMoveUp( form_name, listname ) {
	ctl = eval( 'document.' + form_name + '.' + listname );
	if( ! ctl )  return;
	if( ctl.options[0].selected ) return;
	for( i=1; i<ctl.length; i++ ) {
		if( ctl.options[i].selected ) {
			tmp1 = new Option( ctl.options[i-1].text );
			tmp1.value = ctl.options[i-1].value;
			tmp = new Option( ctl.options[i].text );
			tmp.value = ctl.options[i].value;
			ctl.options[i-1] = tmp;
			ctl.options[i-1].selected = true;
			ctl.options[i] = tmp1;
		}
	}
}

function onSaveSort( form_name, cmd, sctl, slist ) {
	ctl = eval( 'document.' + form_name + '.' + sctl );
	list = eval( 'document.' + form_name + '.' + slist );
	if( (!ctl)  ||  (!list) )  return;
	slist = '';
	for( i=0; i<ctl.length; i++ ) {
		if( slist != '' )  slist = slist + ',';
		slist = slist + ctl.options[i].value;
	}
	list.value = slist;
	onButtonClick( form_name, cmd );
}

function onCheckDateFormat( form_name, field_name, format ) {
	form_field = eval('document.' + form_name + '.' + field_name );
	if( ! form_field ){
		return true;}
	if( form_field.value=='' ){
		return true;}
	var jahr, monat, day, hour, minute, second, fmt, fld, pos, len, dlm, dmy;
	jahr = monat = day = hour = minute = second = 0;
	fmt = format.toLowerCase();
	fld = TrimStr( form_field.value );
	pos = 1;
	dlm = " :./-";
	dmy = 0;
	imonth = 0;
	while( fmt != ""  &&  fld != "" ) {
		if( fmt.substring(0,4) == "yyyy" ) {
			jahr = fld.substring( 0, 4 );
			if( isNaN( jahr ) )  break;
			if( jahr > 2099  ||  jahr < 1900 ) break;
			len = 4;
			dmy++;
		} else if( fmt.substring(0,2) == "yy" ) {
			jahr = fld.substring( 0, 2 );
			if( isNaN( jahr ) )  break;
			if( jahr < 0 ) break;
			if( jahr > 70 ){
				jahr += 1900;}
			else{
				jahr += 2000;}
			len = 2;
			dmy++;
		} else if( fmt.substring(0,2) == "mm" && imonth == 0) {
			monat = fld.substring( 0, 2 );
			if( monat < 0  ||  monat > 12 ) break;
			if( isNaN( monat ) )  break;
			len = 2;
			imonth = 1;
			dmy++;
		} else if( fmt.substring(0,2) == "dd" ) {
			day = fld.substring( 0, 2 );
			if( isNaN( day ) )  break;
			if( day < 0  ||  day > 31 ) break;
			len = 2;
			dmy++;
		} else if( fmt.substring(0,2) == "hh" ) {
			hour = fld.substring( 0, 2 );
			if( isNaN( hour ) )  break;
			if( hour < 0  ||  hour > 24 ) break;
			len = 2;
		} else if( fmt.substring(0,2) == "mi" || (fmt.substring(0,2) == "mm" && imonth == 1) ) {
			minute = fld.substring( 0, 2 );
			if( isNaN( minute ) )  break;
			if( minute < 0  ||  minute > 59 ) break;
			len = 2;
		} else if( fmt.substring(0,2) == "ss" ) {
			second = fld.substring( 0, 2 );
			if( isNaN( second ) )  break;
			if( second < 0  ||  second > 59 ) break;
			len = 2;
		} else if( dlm.indexOf( fmt.substring(0,1) ) >= 0 ) {
			if( dlm.indexOf( fld.substring(0,1) ) < 0 )  break;
			len = 1;
		} else if( fmt.substring(0,1) == fld.substring(0,1) )
			len = 1;
		else
			break;
		fmt = fmt.substring( len, fmt.length );
		fld = fld.substring( len, fld.length );
		pos = pos + len;
	}
	if( fld == ""  &&  fmt == "" ){
		pos = -1;}
	if( fld == ""  &&  fmt != ""  &&  jahr != 0  &&  monat != 0  &&  day != 0 ){
		pos = -1;}
	if( fld == ""  &&  ( fmt == ":ss"  ||  fmt == ":mi:ss" ) ){
		pos = -1;}
	if (pos > -1) {
		alert('Das Datumsformat ' + form_field.value + ' ist nicht in Ordnung.\nBitte geben Sie ein gültiges Datum ein.\nFormat: ' + format + '.');
		form_field.focus();
		form_field.value='';
		onCalendar( form_name, field_name, format, '' );
	}
	return pos;
}

function TrimStr( str ) {
	var pos, pos1, pos2;
	for( pos = 0; pos < str.length; pos++ ) {
		pos1 = pos;
		if( str.substr( 0, 1 ) != " " ) break;
	}
	for( pos = str.length - 1; pos >= pos1; pos-- ) {
		pos2 = pos;
		if( str.substr( pos, 1 ) != " " ) break;
	}
	if( str == "" ){
		return str;}
	else{
		return str.substring( pos1, pos2 + 1 );}
}

function onCalendar( form_name, field_name, format, olddate ) {
	form_field = eval('document.' + form_name + '.' + field_name );
	if( ! form_field )
		return true;
	if( form_field.value == '' ){
		dval = olddate;}
	else{
		dval = form_field.value;}

	var href = intranetpath + 'admin/showcal.cfm?formname=' + escape(form_name) + '&datfield=' + escape(field_name) + '&AktDate=' + escape(dval) + '&fmt=' + escape(format);
  	var wndcal = window.open( intranetpath + 'admin/empty.html','Calendar','width=370,height=370,dependent=yes,hotkeys=no,locationbar=no,menubar=no,resizable=no,screenX=25,screenY=25,status=no,scrollbars=no,top=32,left=32,topx=32,topy=32');
	wndcal.location.href = href;
   	if ( wndcal.opener == null ){
		wndcal.opener = window;}
	return false;
	}

function onTopWindowHREF( href ) {
	window.top.location.href = href;
}

function onDocumentDownload( uuid, vid ) {
	var href = intranetpath + 'doc/doc_download.cfm?'
	if( (! vid)  ||  vid == 0 ){
		href = href + uuid;}
	else{
		href = href + 'uuid=' + uuid + '&version_id=' + vid;}
  	var wnddl = window.open( intranetpath + 'admin/empty.html','Download' + uuid,'width=370,height=370,dependent=yes,hotkeys=yes,locationbar=yes,menubar=yes,resizable=yes,screenX=25,screenY=25,status=yes,scrollbars=yes');
	wnddl.location.href = href;
	wnddl.focus();
}

function onSelectDocument(uuid, title, type) {
//alert("link");
	if( parent ){
	//alert("parent");
		if( parent.parent ){
		//alert("parent.parent");
			if( parent.parent.opener ){
			//alert("parent.parent.opener");
			
				if( parent.parent.opener.CallbackSelectDocument ) {
				//alert(parent.parent.opener.CallbackSelectDocument);
					parent.parent.opener.CallbackSelectDocument(uuid, title, type);
					parent.parent.close();
				}}}}
	//alert(parent.parent.opener);
}

function onAttachFile( doc_mode ) {
	var href = intranetpath + 'doc/index.cfm?doc_mode=' + doc_mode;
  	var wnddoc = window.open(intranetpath + 'admin/empty.html','iracer_doc_' + doc_mode,'width=700,height=370,dependent=yes,hotkeys=yes,locationbar=yes,menubar=yes,resizable=yes,screenX=25,screenY=25,status=yes,scrollbars=yes');
	wnddoc.location.href = href;
	wnddoc.opener = window;
	wnddoc.focus();
}

function onInsertLink( page ) {

	//if( ! page )  page = 'insert_link.cfm';
	var href = intranetpath + 'admin/' + page;
	//alert(href);
	//var href = intranetpath + 'doc/index.cfm?doc_mode=1';
	  	var wndart = window.open(intranetpath + 'admin/empty.html','nedit','width=700,height=370,dependent=yes,hotkeys=yes,locationbar=yes,menubar=yes,resizable=yes,screenX=25,screenY=25,status=yes,scrollbars=yes');
  	//var wndart = window.open(intranetpath + 'admin/empty.html','iracer_search_art','width=780,height=425,dependent=yes,hotkeys=yes,locationbar=yes,menubar=yes,resizable=yes,screenX=25,screenY=25,status=yes,scrollbars=yes');
	wndart.location.href = href;
	wndart.opener = window;
	wndart.focus();
}

function onSelectTreeInList( form, fld, type ) {
	var href = intranetpath + 'treeinlist.cfm?form_name=' + form + '&field_name=' + fld + '&type=' + type;
  	var wndsel = window.open( 'empty.html','iracer_sel_tree_in_list' + type,'width=700,height=370,dependent=yes,hotkeys=yes,locationbar=yes,menubar=yes,resizable=yes,screenX=25,screenY=25,status=yes,scrollbars=yes');
	wndsel.location.href = href;
	wndsel.opener = window;
	wndsel.focus();
}

function onStoredSearchSave( form, fld ) {
	alert( 'Noch nicht' );
}

function onStoredSearchDelete( form, fld ) {
	alert( 'Noch nicht' );
}


