// JavaScript Document
// Written by shaffee nasr mayoof
// email : scriptmx@scriptmx.com , shaffeem@batelco.com.bh
//Function to add image
function sss(rte) {
	var oRTE;
	
	alert(document.all.lf.document.all.frames[rte]);
	
	if (left_frame.document.all) {
		oRTE = frames[rte];
		
		//get current selected range
		var selection = oRTE.document.selection; 
		if (selection != null) {
			rng = selection.createRange();
		}
	} else {
		oRTE = left_frame.document.getElementById(rte).contentWindow;
		
		//get currently selected range
		var selection = oRTE.getSelection();
		rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
	}
	
	imagePath = prompt('Enter Image URL:', 'http://');				
	if ((imagePath != null) && (imagePath != "")) {
		//oRTE.focus();
		oRTE.document.execCommand('InsertImage', false, imagePath);
	}
	//oRTE.focus();
}

selected = new Array(); 
var inner;

function select_row( obj )
{
 
	id = obj.split("_");

	id = parseInt( id[1] );

	if( (eval("document.all."+obj+".innerHTML")).indexOf('notselected') != -1 )
	{
		eval("document.all."+obj+".innerHTML = '<img style=\"cursor:pointer\" src=../../images/selected.gif />'");
		//alert( obj.sty );
		
 		selected.push( id );

		//show the operations
		document.all.other_operations.style.display = "block";
	}
	else
	{
		eval("document.all."+obj+".innerHTML = '<img style=\"cursor:pointer\"  src=../../images/notselected.gif />'");
		eval("document.all."+obj+".style.background = '#F5F8FC'");
		
		for( i=0 ; i<selected.length; i++ )
		{
			if( selected[i] == id )
			{
				//shift the elements
				for( index = i ; index < selected.length; index++ )
				selected[index] = selected[index+1];
				
				//Remove the last element
				selected.pop();
				
				if( selected.length == 0 )
				{
					document.all.other_operations.style.display = "none";
				}
				
				break;
			}
		}
	}
	
	document.all.count.innerHTML = '( '+selected.length+' )';
}

function submitform( operation )
{

	inner = document.all.other_operations.innerHTML;
	
	for( i=0; i<selected.length; i++)
	{
		eval("document.all.row_"+selected[i]+".style.background = '#FFDDDD'");
	}
	
	document.all.other_operations.innerHTML = "	<input class=submit style='background-color:#FFDDDD;color:black;border-color:#FF8484' value=\"لتأكيد عملية الحذف ، إضغط هنا\" type=button onclick=deleteall('"+operation+"'); /><input class=submit style='background-color:#B8DAF1;color:black' value=\"إلغاء عملية الحذف\" type=button onclick=cancel_delete('"+operation+"'); />";
}

function deleteall( operation )
{
	if( confirm('هل تريد حذف جميع العناصر المُحددة') )
	{		
		document.location.href = 'index.php?act='+operation+'&id='+selected;
	}
	else
	{
		cancel_delete();	
	}

}

function cancel_delete()
{
	document.all.other_operations.innerHTML = inner;
	for( i=0; i<selected.length; i++)
	{
		eval("document.all.row_"+selected[i]+".style.background = '#F5F8FC'");
	}
}


