// JavaScript Document

var EcmCalls_image_assign = document.getElementById('EcmCalls_image_assign');
var EcmCalls_image_search = document.getElementById('EcmCalls_image_search');

function EcmCalls_viewAnMenu(img, number, record, module, id, name) {
	var anMenu = document.getElementById('anMenu');
	if(typeof(anMenu) == "object") {
		var imgPos = YAHOO.util.Dom.getXY(img);
		if(imgPos) {
			anMenuClear();
			if(module && module != '') {
				document.forms.anMenuEdit.an_menu_parent.value = module;
				document.forms.anMenuEdit.an_menu_old_parent.value = module;
			} else {
				document.forms.anMenuEdit.an_menu_old_parent.value = '';	
			}
			if(id && id != '') {
				document.forms.anMenuEdit.an_menu_parent_id.value = id;
				document.forms.anMenuEdit.an_menu_old_parent_id.value = id;
			} else {
				document.forms.anMenuEdit.an_menu_parent_id.value = '';
				document.forms.anMenuEdit.an_menu_old_parent_id.value = '';
			}
			if(name && name != '') 
				document.forms.anMenuEdit.an_menu_parent_name.value = name;
			else
				document.forms.anMenuEdit.an_menu_parent_name.value = '';
				
			if(record && record != '') 
				document.forms.anMenuEdit.an_menu_ecmcall_record.value = record;
			else
				document.forms.anMenuEdit.an_menu_ecmcall_record.value = '';
				
			if(number && number != '') 
				document.forms.anMenuEdit.an_menu_old_parent_phone.value = number;
			else
				document.forms.anMenuEdit.an_menu_old_parent_phone.value = '';
				
			document.forms.anMenuEdit.an_menu_new_phone.value = number;
			//document.forms.anMenuEdit.an_menu_update_all_old_records.checked = true;
			anMenu.style.display = '';
			var left = imgPos[0]+8-anMenu.offsetWidth/2;
			
			if((document.body.offsetWidth - imgPos[0] - anMenu.offsetWidth/2 - 25) < 0)
				left = document.body.offsetWidth - 25 - anMenu.offsetWidth;

			anMenu.style.left = left;
			anMenu.style.top = imgPos[1]-12-anMenu.offsetHeight;

		}
	}
}

function EcmCalls_showAssignImage(span, number, record, module, id, name) {
	if(typeof(span) == "object") {

		span.parentNode.appendChild(EcmCalls_image_assign);
		EcmCalls_image_assign.style.display = '';
		EcmCalls_image_assign.onclick = function() { EcmCalls_viewAnMenu(this, number, record, module, id, name); };
		
		if(typeof(module) != "undefined" && typeof(id) != "undefined") {
			span.parentNode.appendChild(EcmCalls_image_search);
			EcmCalls_image_search.style.display = '';
			EcmCalls_image_search.onclick = function() { 
				var url = 'index.php?searchFormTab=advanced_search&module=EcmCalls&action=index&query=true&parent_from_advanced='+module+'&parent_from_id_advanced[]='+id+'&orderBy=CALLDATE&sortOrder=DESC';
				if(document.getElementById('call_date_from_ecmcalls_tmp')) 	url += '&call_date_from_advanced='+document.getElementById('call_date_from_ecmcalls_tmp').value;
				if(document.getElementById('call_date_to_ecmcalls_tmp')) 	url += '&call_date_to_advanced='+document.getElementById('call_date_to_ecmcalls_tmp').value;
				if(document.getElementById('calldate_ecmcalls_tmp')) 	url += '&calldate_advanced='+document.getElementById('calldate_ecmcalls_tmp').value;
				window.location = url; 
			};
		} else {
			EcmCalls_image_search.style.display = 'none';
		}
	}
	
}

function EcmCalls_hideAssignImage(span, number) {
	
	if(typeof(span) == "object") {
		//EcmCalls_image_assign.style.display = 'none';
		//document.body.appendChild(EcmCalls_image_assign);
	}
	
}

function EcmCallsSearchRecord() {
	var div = document.getElementById("EcmCallsAdditionalDetails");
	if(div) {
		var url = 'index.php?searchFormTab=advanced_search&module=EcmCalls&action=index&query=true&parent_from_advanced='+div.ec_module+'&parent_from_id_advanced[]='+div.ec_id+'&orderBy=CALLDATE&sortOrder=DESC';
		if(document.getElementById('call_date_from_ecmcalls_tmp')) 	url += '&call_date_from_advanced='+document.getElementById('call_date_from_ecmcalls_tmp').value;
		if(document.getElementById('call_date_to_ecmcalls_tmp')) 	url += '&call_date_to_advanced='+document.getElementById('call_date_to_ecmcalls_tmp').value;
		if(document.getElementById('calldate_ecmcalls_tmp')) 	url += '&calldate_advanced='+document.getElementById('calldate_ecmcalls_tmp').value;
		window.location = url;
	}
}
function EcmCallsAssignRecord(img) {
	var div = document.getElementById("EcmCallsAdditionalDetails");
	if(div) {
		EcmCalls_viewAnMenu(img, div.ec_number, div.ec_record, div.ec_module, div.ec_id, div.ec_name);	
	}
}
function EcmCallsViewDetailRecord(img) {
	var div = document.getElementById("EcmCallsAdditionalDetails");
	if(div) {
		window.location = "index.php?module="+(div.ec_module == "Users" ? "Employees" : div.ec_module)+"&action=DetailView&record="+div.ec_id+"&return_module=EcmCalls&return_action=ListView";
	}
}


function ShowAdditionalDetails(title,obj,call,module)
{ 
 var div = document.getElementById("EcmCallsAdditionalDetails");
 
 if(!div) {
 	div = document.createElement("div");
 	div.style.background="#ffffff";
 	div.style.position="absolute";
 	div.style.left = '10px';
 	div.style.top = '10px';
 	div.id="EcmCallsAdditionalDetails";
 
	var divi ='<div id="" class="olBgClass" style="background-image: none;"><table class="olBgClass" width="300" border="0" cellpadding="0" style="border:none;" cellspacing="0"><tbody><tr><td><div id="EcmCallsAdditionalDetailsContainer"><table id="EcmCallsAdditionalDetailsHeader" class="olCgClass" width="100%" border="0" cellpadding="2" cellspacing="0"><tbody><tr><td id="EcmCallsAdditionalDetailsHeaderTD" class="olCgClass" width="100%" style="margin-left:2px; padding-left:2px;"><div id="EcmCallsAdditionalDetailsHeaderDIV" class="olCapFontClass">';
	
	divi += '<div style="float: left;" id="EcmCallsAdditionalInfoTopButtons">';
	divi += '<img id="EcmCalls_search_img" onClick="EcmCallsSearchRecord();" src="modules/EcmCalls/images/search.gif" border="0" style="cursor:pointer;">';
	divi += '<img id="EcmCalls_assign_img" onClick="EcmCallsAssignRecord(this);" style="margin-left: 2px; cursor:pointer;" src="modules/EcmCalls/images/assign.gif" border="0">';
	divi += '<img id="EcmCalls_view_detail_img" onClick="EcmCallsViewDetailRecord(this);" style="margin-left: 2px; cursor:pointer;" src="modules/EcmCalls/images/view_detail.gif" border="0">';
	divi += '<span id="EcmCallsStatusPhoneIcon" style="margin-left: 2px;"><img src="include/ECM/EcmFormatPhoneNumber/images/additional_details_phone.gif" border="0" style="cursor:pointer;"></span>';
	divi += '<img style="margin-left:2px;margin-right: 2px; cursor:pointer;" onClick="lock_unlock_Position();" src="modules/EcmCalls/images/close.gif" border="0" style="cursor:pointer;">';
	divi += '</div>';
	
	divi += '<div style="float:left;margin-left:2px;padding-left:2px;" id="EcmCallsAdditionalDetails_title" ></div>';
	
	divi += '</div></td></tr></tbody></table><table id="EcmCallsAdditionalDetailsFooter" class="olFgClass" width="100%" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td id="EcmCallsAdditionalDetailsFooterTD" class="olFgClass" valign="top"><div id="EcmCallsAdditionalDetails_description" class="olFontClass"></div></td></tr></tbody></table></div></td></tr></tbody></table></div>';
	div.innerHTML = divi;
 	document.body.appendChild(div);
 }
 
 if(div) {
	if(call) {
		document.getElementById("EcmCalls_search_img").style.display = "";
		document.getElementById("EcmCalls_assign_img").style.display = "";
	} else {
		document.getElementById("EcmCalls_search_img").style.display = "none";
		document.getElementById("EcmCalls_assign_img").style.display = "none";	
	}


	
	
	var title_tmp = "";
	if(typeof(title) == "undefined")
		title_tmp = call;
	else 
		title_tmp = title;

	if(typeof(module) == "undefined" && typeof(call) != "undefined") module = "Others";
	
	if(typeof(module) != "undefined")
		title_tmp = SUGAR.language.get('EcmCalls','LBL_NUMBER_OWNER_TYPE_'+module.toUpperCase()) + ": " + title_tmp;
	
	document.getElementById("EcmCallsAdditionalDetails_title").innerHTML = title_tmp;
	var ddd = document.getElementById("EcmCallsAdditionalDetails_description");
	if(ddd.firstChild) { 
		ddd.firstChild.style.display = 'none';
		if(ddd.firstChild.parentNode_) 
			ddd.firstChild.parentNode_.appendChild(ddd.firstChild);
		else
			document.body.appendChild(ddd.firstChild);
	}
	if(obj) {
		obj.style.position = 'relative';
		obj.style.left = 0;
		obj.style.top = 0;
		obj.parentNode_ = obj.parentNode;
		ddd.appendChild(obj);
		obj.style.display = '';
		obj.parentNode_.appendChild(div);
	}
	return div;
 }
}
