/**
 * @category  DeWeM
 * @author    DeWeM Team <admin@dewem.com>
 * @copyright	Copyright (C) 2011 dewem.com, All rights reserved.
 * @license		GNU General Public License version 3; see LICENSE.txt or http://www.gnu.org/licenses/gpl-3.0.html
 * @link      http://www.dewem.com 
 * THIS PROGRAM IS DISTRIBUTED "AS IS";. NO WARRANTY OF ANY KIND IS 
 *	EXPRESSED OR IMPLIED. YOU USE AT YOUR OWN RISK. I WILL NOT BE LIABLE FOR DATA 
 *	LOSS, DAMAGES, HACKING, SPAMMING, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS 
 *	WHILE USING OR MISUSING THIS SOFTWARE. 
 */

function showInnerMenuDewem(event, idInnerMenu){
	var innerMenu = document.getElementById(idInnerMenu);
	innerMenu.style.position = 'absolute';
	innerMenu.style.display = 'block';
	innerMenu.style.left =  getXDewem(event)+'px'; 
	innerMenu.style.top = getYDewem(event)+'px';
	innerMenu.style.visibility = 'visible';
	zIndexGlobalDewem = zIndexGlobalDewem + 1;
	innerMenu.style.zIndex = zIndexGlobalDewem;
}
function refreshDewem(parentFormName, name, art){
	var classToRefr = 'Area.php';
	if (art == 'workel'){
		classToRefr = 'Workel.php';
	}
	if (art == 'page'){
		classToRefr = 'Page.php';
	}
	sendDewemAjaxRequest(classToRefr, 'refresh', parentFormName, name);
	var innerMenuId = parentFormName+'_innerMenu';
	var innerMenu = document.getElementById(innerMenuId);
	if (innerMenu){
		innerMenu.parentNode.removeChild(innerMenu);
	}
}
function innerOnMouseoverDewem(menuElement){  //menuElement
	menuElement.style.backgroundColor = "#5EFFE5";
	if (bNSDewem){
		menuElement.style.opacity = '.70';
	}else if (bIEDewem){
		menuElement.style.filter = 'alpha(opacity=70)';
	}
}
function innerOnMouseoutDewem(menuElement){
	menuElement.style.backgroundColor = "#6DCFF6";
	if (bNSDewem){
		menuElement.style.opacity = '1';
	}else if (bIEDewem){
		menuElement.style.filter = 'alpha(opacity=100)';
	}
}
function submitCopyDewem(parentFormName, toCopyName, art){
	if (art == 'page'){
		sendDewemAjaxRequest('Shell.php', 'copy', 'name,art,formName', toCopyName+','+art+','+parentFormName);
	}else{
		sendDewemAjaxRequest('Shell.php', 'copy', 'name,art', toCopyName+','+art);
	}
	var innerMenuId = parentFormName+'_innerMenu';
	var innerMenu = document.getElementById(innerMenuId);
	innerMenu.style.visibility = 'hidden';
}
function copiedAlertDewem(success){
	alert(success);
}

function releaseOrLockDewem( formName, methodName){
	sendDewemAjaxRequest('Page.php', 'releaseOrLock', formName, methodName);
	var innerMenuId = formName+'_innerMenu';
	var innerMenu = document.getElementById(innerMenuId);
	innerMenu.parentNode.removeChild(innerMenu);
}

function submitWebUpdate (parentFormName, toUpdateName){
	sendDewemAjaxRequest('Page.php', 'webUpdate', parentFormName, toUpdateName);
	var innerMenuId = parentFormName+'_innerMenu';
	var innerMenu = document.getElementById(innerMenuId);
	innerMenu.style.visibility = 'hidden';
}

function updateAllDependenceDewem(parentFormName, toUpdateName, art){
	var scriptName = 'Workel.php';
	if (art == 'area'){
		scriptName = 'Area.php';
	}
	sendDewemAjaxRequest(scriptName, 'updateAllDependence', parentFormName, toUpdateName);
	var innerMenuId = parentFormName+'_innerMenu';
	var innerMenu = document.getElementById(innerMenuId);
	innerMenu.style.visibility = 'hidden';
}
function setPageVarDewem(parentFormName, areaName){
	if ( !confirm('Are you sure to set the area \"'+ areaName+'\" as Variable in the Pages? '
		+'Warning, all internals (if they exist) of this area will be deleted!') ){
		return;
	}
	sendDewemAjaxRequest('Area.php', 'setPageVar', parentFormName, areaName);
}
function unsetPageVarDewem(parentFormName, areaName){
	if ( !confirm('Are you sure to unset the area \"'+ areaName+'\" as Variable in the Pages? '
		+'Warning, after update all pages have this area not as Variable!') ){
		return;
	}
	sendDewemAjaxRequest('Area.php', 'unsetPageVar', parentFormName, areaName);
}
function submitSaveDewem(parentFormName, toSaveName, art){
	sendDewemAjaxRequest('Shell.php', 'saveZip', parentFormName+',art', toSaveName+','+art);
}
function submitStructureDewem(parentFormName, name, art, root){
	root = (root) ? root : 0;
	if (art == 'area'){
		sendDewemAjaxRequest('Area.php', 'submitStructure', parentFormName+',root',
			name+','+root);
	}else{
		//page
		sendDewemAjaxRequest('Page.php', 'submitStructure', parentFormName+',root',
			name+','+root);
	}
	if (jQuery( '#tabs' ).tabs( "option", "selected" ) != 2 ){
		jQuery("#tabs").tabs('select', 2);
	}
}
