/*
		+--------------------------------------------------------------------+
		| conXL                                                              |
		+--------------------------------------------------------------------+
		| Copyright (c) 2003 - 2004 by Daniel Kohler                         |
		+--------------------------------------------------------------------+


		File			: js.global.js
		Project			: conXL
		Description		: contents often used javascript functions
		Author			: Daniel Kohler
		Created			: 10.04.2004
		Modified		: 01.07.2004
		Version			: 1.0
*/

/* openWin
* Opens a new custom window
*
* @param		url							string
* @param		name						string
* @param		width						int
* @param		height						int
* @param		top							int
* @param		left						int
* @param		status						bool
* @param		resizable					bool
* @param		menubar						bool
* @param		locationbar					bool
* @param		scrollbars					bool
* @param		dependent					bool
*
* @return		void
*/
function openWin(url, name, width, height, top, left, status, resizable, menubar, locationbar, scrollbars, dependent) {
	window.open(url, name, 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', status=' + status + ', resizable=' + resizable + ', menubar=' + menubar + ', locationbar=' + locationbar + ', scrollbars=' + scrollbars + ', dependent=' + dependent);
} // end function

/* openWysiwyg
* Opens a new window for "WYSIWYG-editor"
*
* @param		field						string
* @param		what						string
* @param		width						int
* @param		height						int
*
* @return		void
*/
function openWysiwyg(field, what, width, height) {
  openWin('wysiwyg/editor.php?what=' + what + '&field=' + field, 'wysiwyg', width, height, 20, 20, 1, 0, 0, 0, 0, 0);
} // end function

/* openPdf
* Opens a new window for a PDF file
*
* @param		url							string
* @param		width						int
* @param		height						int
*
* @return		void
*/
function openPdf(url) {
  openWin(url, 'pdfWin', 600, 700, 20, 20, 1, 1, 0, 0, 0, 0);
} // end function

/* insLink
* Opens a new custom for "insert link"
*
* @return		void
*/
function insLink(field) {
	var actlink = document.all['link_' + field].href;
	var acttarget = document.all['link_' + field].target;
	
	openWin('common/inslink.php?what=html&field=' + field + '&link=' + actlink + '&target=' + acttarget, 'insLink', 526, 430, 100, 100, 1, 0, 0, 0, 0, 0);
} // end function

/* insImage
* Opens a new custom for "insert image"
*
* @return		void
*/
function insImage(field) {
	var actimage = document.all[field].value;
	//var acttarget = document.all.link_target.value;
	
	openWin('common/insimage.php?what=html&field=' + field + '&img=' + actimage, 'insImage', 540, 480, 100, 100, 0, 0, 0, 0, 0, 0);
} // end function

/* openWysiwyg
* Opens a new window for "calendar"
*
* @param		field						string
*
* @return		void
*/
function calendar(field) {
	openWin('common/calendar.php?field=' + field, field, '445', '230', '150', '150', 0, 0, 0, 0, 0, 0);
} // end function

/* conf
* Opens a confirmation-window
*
* @param		msg							string
*
* @return		true/false
*/
function conf(msg) { 
	check = confirm(msg);
	return check; 
} // end function

/* refreshNav
* Reloads "structure-frame"
*
* @return		void
*/
function refreshNav() {
	parent.fraStr.location.reload();
} // end function

/* goto
* Goes somewhere
*
* @param		link						string
* @param		add_path					string
*
* @return		void
*/
function goto(link, add_path) {
	if(add_path) {
		parent.fraContent.location = add_path + link;
	} else {
		parent.fraContent.location = link;
	} // end if
} // end function

/* genEdSth
* Locates to save a field's content
*
* @param		form						string
* @param		where						string
* @param		what						int
*
* @return		void
*/
function genEdSth(form, where, what, addname, addval) {
	document[form].action = '?action=edsth&where=' + where + '&what=' + what + (addname ? '&' + addname + '=' + addval : '');
	document[form].submit();
} // end function

/* showCat
* Locates to a category
*
* @param		idcat						int
*
* @return		void
*/
function showCat(idcat) {
	parent.fraContent.location = './components/conSites.php?idcat=' + idcat;
} // end function

/* showSite
* Locates to a site
*
* @param		idsite						int
* @param		idcat						int
*
* @return		void
*/
function showSite(idsite, idcat) {
	parent.fraContent.location = './components/conSitesEditor.php?idsite=' + idsite + '&idcat=' + idcat;
} // end function

/* makeSelection
* Selects entries in a list
*
* @param		formname					string
*
* @return		void
*/
function makeSelection(formname) {
    flag = document.selecter.filter.options[document.selecter.filter.selectedIndex].value;
    if (flag.substring(0, 1) == "!") {
        selectFlagged(parseInt(flag.substring(1)), false, formname);
    } else {
        selectFlagged(parseInt(flag), true, formname);
    } // end if

    // reset formular
    document.selecter.reset();
	self.focus();
} // end function

var Flags;

/* selectFlagges
* Addional to makeSelection
*
* @param		flag						int
* @param		val							int
* @param		formname					string
*
* @return		void
*/
function selectFlagged(flag, val, formname) {
    shift = 0;
    for (var i = 0; i < document.forms[formname].elements.length; i++) {
        while (document.forms[formname].elements[i].name != "items[]") {
            i++;
            shift++;
            if (!document.forms[formname].elements[i]) {
                return;
            } // end if
        } // end while
		
        if (flag & Flags[i - shift]) {
            document.forms[formname].elements[i].checked = val;
        } else {
            document.forms[formname].elements[i].checked = !val;
        } // end if
    } // end for
} // end function
