/**
*	Called in index.php of engine
*	Contains all javascript functions which will be used all over engine
**/

/* Pop up block checker */
function checkOpenWindow (openWin)
{
    var exists = false;
    if (openWin && !openWin.closed)
    {
        exists = true;
        try {
            openWin.focus();
        }
        catch (e) {
            //keepFocus = false;
            exists = false;
        }
        //if (!keepfocus)
        //{
         //   window.focus();
        //}
    }
    if (!exists)
    {
    	//Fire alert and print message on screen
        alert("Pop up blocker was detected, please disable this to continue.");
        document.write('<span style="color: #ff0000"><b>This website needs to open a window to continue with your image upload. Please disable your popup blocker.</b></span>');
    }
}

/*** USED IN MEDIA UPLOAD ***/

function getOptionValue(obj)
{
	var index0, index1;
	if (obj.name == "media_type")
	{
		index0 = document.img_upload.media_type.selectedIndex;
		value0 = document.img_upload.media_type[document.img_upload.media_type.selectedIndex].value;

 		if(value0 == "i") {
			document.img_upload.edit_option1.disabled=false;
			//document.img_upload.edit_option2.disabled=false;
			document.img_upload.edit_option3.disabled=false;
			
			//document.img_upload.fixed_sizes.disabled=false;
 		}
 		else {
			document.img_upload.edit_option1.disabled=true;
			//document.img_upload.edit_option2.disabled=true;
			document.img_upload.edit_option3.disabled=true;
			
			//document.img_upload.fixed_sizes.disabled=false;
 		}
	} 
}

function enableSize(){
	if (document.img_upload.edit_option1.checked){
		document.img_upload.fixed_sizes.disabled=false;
	}else{
		document.img_upload.fixed_sizes.disabled=true;
	}
}

function showLoading() {
	document.loading = eval('document.getElementById("processing")');
	document.loading.style.visibility = "visible";
}

/*** End functions used in MEDIA UPLOAD ***/

/*** USED IN BEN UPDATE ***/

//Tells IE browsers that attach image button has been pressed
function attachClickSubmit() {
document.getElementById('attach').value=1;
}
//Tells IE browsers that save button has been clicked
function formSave() {
document.getElementById('attach').value=0;
}

/*** USED in USERGROUP / USERS MANAGEMENT ***/

//Check ALL textboxes, uses name as identifier
function checkAll(checkAllState, field) {
	if(field.length == undefined) {
		field.checked = checkAllState.checked;
	}
	for (i = 0; i < field.length; i++) {
		field[i].checked = checkAllState.checked;
	}
}

//Check all checkboxes in a GROUP, uses ID as identifier
function checkAllGroup(checkAllState, cbGroup) {
	if(cbGroup.length == undefined) {
		cbGroup.checked = checkAllState.checked;
	}
	for (i = 0; i < cbGroup.length; i++)
	{
		cbGroup[i].checked = checkAllState.checked;
	}
}

/**** HOME PAGE ****/

function template_check(item) {
	if( document.getElementById('template1').checked == false
	 && document.getElementById('template2').checked == false ) {
		document.getElementById('template1').checked = true;
	}
	else if(item == 'template1') {
		document.getElementById('template2').checked = false;
	}
	else if(item == 'template2') {
		document.getElementById('template1').checked = false;
	}
}