function toggleDisplay(divid) {
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
	} else {
		document.getElementById(divid).style.display = 'none';
	}
}
function toggleDisplayInline(divid) {
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'inline';
	} else {
		document.getElementById(divid).style.display = 'none';
	}
}
function showBlock(divid) {
	document.getElementById(divid).style.display = 'block';
}
function showInline(divid) {
	document.getElementById(divid).style.display = 'inline';
}
function displayHide(divid) {
	document.getElementById(divid).style.display = 'none';
}

function go(link) {
	location.href=link;
}
function clearField(itemId, defaultText) {
	if (itemId.value==defaultText) {
		itemId.value = '';
		itemId.style.color = '#000';
	}
}
function unclearField(itemId, defaultText) {
	if (itemId.value=='') {
		itemId.value = defaultText;
		itemId.style.color = '#888';
	}
}

function insertTextFieldText(textfield, text) {
	document.getElementById(textfield).value = document.getElementById(textfield).value + text;
}	

function insertAtCursor(theField, myValue) {
	myField=document.getElementById(theField);
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}
function insertLink(textfield) {
	defaultValue = 'http://';
	var URL = prompt('Enter the URL' ,defaultValue);
	niceURL = URL.replace('http://', '');
	if (URL) {
		string = '<a href="' + URL + '">' + niceURL + '</a>';
	}
	insertAtCursor(textfield, string);
}

function explode( delimiter, string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
 
    var emptyArray = { 0: '' };
 
    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
 
    return string.toString().split ( delimiter.toString() );
}



function select_all(id_string, check) {
	
	ids = explode(',', id_string);
	
	for (i = 0; i < ids.length; i++) {
		document.getElementById(ids[i]).checked = check;
	}
	
/*
  for (i = 0; i < forminputs.length; i++) {
	alert(forminputs[i].value);
    // regex here to check name attribute
    var regex = new RegExp(name, "i");
    if (regex.test(forminputs[i].getAttribute('name'))) {
      if (value == '1') {
        forminputs[i].checked = true;
      } else {
        forminputs[i].checked = false;
  }
    }
  }
	*/
}





/*
function checkAll(fields, onoff) {
	// fields, a comma separated list of fields
	// onoff - 1 for on, 0 for off
	
	var objCheckBoxes=explode(',', fields);
	
	var countCheckBoxes = objCheckBoxes.length;
	
	for(var i = 0; i < countCheckBoxes; i++) {
		document.forms[FormName].elements[objCheckBoxes[i]].checked = onoff;
	}
	
}




function checkAll2(formname, fieldname) {
	chk = document.forms[formname].elements[fieldname+"[]"];
	alert(chk);
	for (i = 0; i < chk.length; i++)
		chk[i].checked = true ;
}

function unCheckAll2(chk) {
	for (i = 0; i < chk.length; i++)
		chk[i].checked = false ;
}
*/
