function dc_actionAP(ac){
	var dcac = dc_getElementSafe('dc_ac');
	if (dcac){
		dcac.value = ac;
		//alert('dcac:'+dcac.value);
		document.dc_form.submit();
	}
}
function dc_action(md,tp,pg,rf,bg,w,h,wt){
	var dc_diffAction = (new Date()).getTime()-dc_lastAction;
	if (dc_diffAction>5000){
		var rn = Math.random();
		if (wt=='modal'){
			dc_popWindowDialog(_dc_index + '?dc_ac=3&dc_prms='+md+','+tp+','+pg+','+rf+','+bg+','+rn, w, h);
		}else if(wt=='full'){
			dc_popWindowFull(_dc_index + '?dc_ac=3&dc_prms='+md+','+tp+','+pg+','+rf+','+bg+','+rn, 'hotspot', w, h);
		}else if(wt=='fixed'){
			dc_popWindowFixed(_dc_index + '?dc_ac=3&dc_prms='+md+','+tp+','+pg+','+rf+','+bg+','+rn, 'hotspot', w, h);
		}else if(wt=='resize'){
			dc_popWindowResize(_dc_index + '?dc_ac=3&dc_prms='+md+','+tp+','+pg+','+rf+','+bg+','+rn, 'hotspot', w, h);
		}
		dc_lastAction=(new Date()).getTime();
	}
	return false;
}
function dc_popWindowDialog(url, width, height){
	if (window.showModalDialog){
		window.showModalDialog(url, '', 'dialogHeight:'+height+'px; dialogWidth:'+width+'px; status:no; scroll:no; resizable:yes;');
		return true;
	}else{
		var name = Math.random();
		dc_popWindowResize(url,name,width,height);
		return false;
	}
}
function dc_popWindowDialogFull(url, width, height){
	if (window.showModalDialog){
		window.showModalDialog(url, '', 'dialogHeight:'+height+'px; dialogWidth:'+width+'px; status:no; scroll:yes; resizable:yes;');
		return true;
	}else{
		var name = Math.random();
		dc_popWindowFull(url,name,width,height);
		return false;
	}
}
function dc_popWindowFixed(url, name, width, height){
	newWin = window.open(url, name,  'height='+height+',width='+width+',fullscreen=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no');
	if (newWin.opener == null){ newWin.opener = self; }
	newWin.focus();
	return newWin;
}
function dc_popWindowResize(url, name, width, height){
	newWin = window.open(url, name,  'height='+height+',width='+width+',fullscreen=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=yes');
	if (newWin.opener == null){ newWin.opener = self; }
	newWin.focus();
	return newWin;
}
function dc_popWindowFull(url, name, width, height){
	newWin = window.open(url, name,  'height='+height+',width='+width+',fullscreen=no,location=yes,menubar=yes,status=yes,toolbar=no,scrollbars=yes,resizable=yes');
	if (newWin.opener == null){ newWin.opener = self; }
	newWin.focus();
	return newWin;
}
function dc_popClose( submit ){
	if (submit){
		if (!window.dialogWidth){
			window.opener.document.dc_form.submit();
			window.opener.focus();
		}
	}
	window.close();
}

function dc_getElementSafe( id ){
	if (document.getElementById){

		// Check to see if we have this id
		if (document.getElementById(id)) {
			return document.getElementById(id);
		}

		// Check to see if we've got the name instead
		if (document.getElementsByName) {
			var elms = document.getElementsByName(id);
			if (elms.length == 1) {
				return elms.item(0);
			}
		}

		// Fail
		return document.getElementById(id);
	}else if (document.all){
		return document.all[id];
	}else if (document.layers){
		return document.layers[id];
	}else{
		return false;
	}
}
function dc_admin(){
	var dcac = dc_getElementSafe('dc_ac');
	if (dcac){
		dcac.value = '1';
		document.dc_form.submit();
	}
}
function dc_jumpToPage( pg ){
	var dcpg = dc_getElementSafe('page');
	if (dcpg){
		dcpg.value = pg;
		document.dc_form.submit();
	}
}
function dc_showError(mess){
	alert(mess);
	return true;
}
function dc_setCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function dc_getCookie(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;
}
function dc_dropCookie(name){
	dc_setCookie(name,"",-1);
}
// resize window so there are no scrollbars visible
function dc_resizeDialog( v, h ){
	// Check if window is a dialog
	var dw = window.dialogWidth;
	if (!dw){ if (window.sizeToContent){ window.sizeToContent(); } return; }
	// Check if we are resizing horizontally
	if (h){
		while (isNaN(dw)){ dw = dw.substr(0,dw.length-1); }
		difw = dw - this.document.body.clientWidth;
		window.dialogWidth = this.document.body.scrollWidth+difw+'px';
	}
	// Check if we are resizing vertically
	if (v){
		var dh = window.dialogHeight;
		while (isNaN(dh)){ dh = dh.substr(0,dh.length-1); }
		difh = dh - this.document.body.clientHeight;
		window.dialogHeight = this.document.body.scrollHeight+difh+'px';
	}
}
