﻿/* this is to prevent Enter key from submitting the form  */
function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 

document.onkeypress = stopRKey; 
/* END /this is to prevent Enter key from submitting the form  */


String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

String.prototype.toArray = function ()
{
	var ar1 = this.split(',');
	var ar2 = new Array();
	for(y=0;y<ar1.length;y++)
	{
		ar2[y] = ar1[y];
	}
	return ar2;
};

Array.prototype.arrayFind = function (val)
{
	for(y=0;y<this.length;y++)
	{
		if(this[y] == val) return y;
	}
	return -1;
};

// adding it as a prototype object enables it to be used from any array
Array.prototype.removeItem = function(itemsToRemove)
{
	this.splice(itemsToRemove, 1);
};

var selectall = function(frmid,chkval,cbid){
	var checkboxes = new Array();
	var form = $(frmid);;
	checkboxes = form.getInputs('checkbox',cbid);//alert(checkboxes);
	checkboxes.each(function(e){ e.checked = chkval });
}



var suggest = function (infoType, target)
	{
		var url = 'index.cfm?do=cms.autocomplete&infoType=' + infoType + '&target=' + target;
		
		new Ajax.Request(url, 
					 {
						method: 'get',
						onSuccess: function(t) {alert(t.responseText); return t.responseText;}
						});
};




// related contents fixed id variaBvless
REL_relatedContentIDListField = 'currRelated';
REL_relatedContentsListBlock = 'relatedContentsList';
REL_relatedContentsresultBlock = 'relatedContentsResults';
LOADING_IMAGE = '<div align="center"><img src="images/ajax-loader.gif" border="0" /></div>';

//var searchRelCont = function (text,contid,qttl)
//	{
//		if(!$(text).value.trim().length)
//		{
//			alert('أدخل النص أولا');
//			return;
//		}
//		var searchIn = ($(qttl).checked)?'title':'all';
//		var success	= function(t){showRelSearchRes(t);}
//		var input = $(REL_relatedContentIDListField);
//		//var failure	= function(t){alert('Error ...');}
//		$(REL_relatedContentsresultBlock).update(LOADING_IMAGE);
//		var url = 'index.cfm?do=cms.searchRelCont&contentid='+ contid +'&exc='+input.value+'&q='+$(text).value+'&qin='+searchIn;
//		new Ajax.Request(url, 
//					 {
//						method: 'get',
//						onSuccess: success,
//						onFailure: fail
//						});
//		
//	}

var showRelSearchRes = function(t)
	{
		//t.responseText;
		//alert('1 ' + t.responseText);
		//alert('2 ' + REL_relatedContentsresultBlock);
		//alert('3 ' + $(REL_relatedContentsresultBlock));
		$(REL_relatedContentsresultBlock).update(t.responseText);
	};

var linkContentTo = function (contid)
	{
		var input = $(REL_relatedContentIDListField);
		input.value.trim();
		var relArr = input.value.toArray();
		//alert(arrayFind(relArr,contid));
		if(relArr.arrayFind(contid) != -1)	// if already exist
		{
			relArr.removeItem(relArr.arrayFind(contid));
			//relArr.without(contid);
			input.value = relArr.join(',');
			
			
			/* moveRelItem('rel_'+contid,'out'); */  	/* 	Ameen 23/02/2009: instade of moving content to the result list, remove it at all 
																										thats why i hilighted this line and added the second */
			moveRelItem('rel_'+contid,'out');
			Element.remove('rel_'+contid);
			//alert('هذا المحتوى مرتبط مسبقا بالمحتوى الحالي');
			return true;
		}
		relArr.push(contid);
		input.value = relArr.join(',');
		moveRelItem('rel_'+contid,'in');
		return true;
	};

var moveRelItem = function (itemID,inOut)
	{
		// itemID, id of item to move
		// inOut, string 'in' or 'out', move the item into the list or out from the list 
		// mFrom, [move From] source container id
		// mTo, [move To] distionation container id
   var element = $(itemID);
	 //alert(REL_relatedContentsresultBlock);
   var oldParent = $(REL_relatedContentsresultBlock);
	 //alert(oldParent);
   var newParent = $(REL_relatedContentsListBlock);
   // Move to new parent.
	 if(inOut == 'out')
		 {
		 oldParent.appendChild(element);
		 }
	 else	// into the list 
		 {
		 newParent.appendChild(element);
		 }
   // Back to old parent.
   //oldParent.appendChild(element);
	};

var quickAddAuthor = function (titleInputId,nameInputId)
	{
		if(!$(nameInputId).value.trim().length)
		{
			alert('أدخل اسم الكاتب');
			return;
		}
		var success	= function(t)
			{
				// taskDone, newAuthorID, errmsg
				t.responseText.evalScripts();
				//$(formDivId).style.visibility='visible';
				//$(formDivId).enable();
				if(taskDone)
					{
						//$('authorID').value = newAuthorID;
						//$('target').value= $(titleInputId).value + ' ' + $(nameInputId).value;
						addAuthor(newAuthorID,$(titleInputId).value + ' ' + $(nameInputId).value);
//						$('authorID').value = newAuthorID;
//						$('author_blue_name').value = $(titleInputId).value + ' ' + $(nameInputId).value;
//						$('removeCurrentAuthor').show();
						$(titleInputId).value = '';
						$(nameInputId).value = '';
						//$(hasPageInputyID).checked=false;
						//winObj.close();
						// ??????
					$('pop_author').hide();
					}
				else
					{
						alert(errmsg);
					}
			}
		// hide the form to show the loding image
		//$(formDivId).style.visibility='hidden';
		//$(formDivId).disable();
		//var hp = ($(hasPageInputyID).checked)?1:0;
		var hp = 0;
		var url = 'index.cfm?do=cms.quickAddAuthor&ttl='+ $(titleInputId).value +'&name=' + $(nameInputId).value +'&haspage=' + hp;
		new Ajax.Request(url, 
					 {
						method: 'get',
						onSuccess: success,
						onFailure: fail
						});
	}



/* ================ upload iframe stuff ================ */
var ifrvar = 0;
/*var closeFrame = function (ifrm)
	{
		//ifrm.close();
		window.frames[ifrm].style.display='none';
		window.frames[ifrm].close();
		//ifrm.style.display='none';
	};
*/

var moreUpload= function (placeid,url,callBack,type,onRemove)
	{
  var iframeElm = document.createElement('iframe');
	iframeElm.name = 'abcd_'+ifrvar;
	iframeElm.id = 'abcd_'+ifrvar;
	iframeElm.scrolling = "no";
	iframeElm.src = url + 'callBack=' + callBack + '&fd=abcd_' + ifrvar + '&uploadtype=' + type + '&onRemove=' + onRemove;
	iframeElm.className = 'fileuploadframe';
	$(placeid).appendChild(iframeElm);
	ifrvar++;
	};
/* ================ /upload iframe stuff ================ */

var fail = function (e)
	{
			alert(e);
	}
	
var isCateAssigned = function(){
	if($('inputCatID').value == 0){
		alert('لم تقم باختيار اي محور');
		return false;
	}
	return true;
}	
	
	
// ============================================================ //
function showloading(){
	$('loadingdiv').innerHTML = "<img src='images/loadingtext.gif' border='0'>";
	new Effect.Appear('loadingdiv', {duration: 0.1});
}
function hideloading(){
	new Effect.Fade('loadingdiv', {duration: 0.1});
}

//IE likes to cache so we will fix it's wagon!
function _noCache(url){
	var cond = (arguments.length==1)?1:arguments[1];
	var qs = new Array();
	var arr = url.split('?');
	var scr = arr[0];
	if(arr[1]){ qs = arr[1].split('&'); }
	qs[qs.length]='noCache='+new Date().getTime()+'&simplelayout='+cond;
return scr+'?'+qs.join('&');
}

function setClassName(id, cls, newcls){
	$(id).removeClassName(cls);
	$(id).addClassName(newcls);
}

function sysmsgdisplay(clsname,repMsg){
	//display the status to the user
	if(clsname == 'sysnote')
		$('sysmsgtxt').removeClassName('alertnote');
	else
		$('sysmsgtxt').removeClassName('sysnote');
		
	$('sysmsgtxt').addClassName(clsname);
	$('sysmsg').hide();
	$('sysmsgtxt').innerHTML = repMsg;
	Effect.Appear('sysmsg', {duration:2, afterFinish:function(){Effect.Fade('sysmsg', {delay:5, duration:2}); return false;} });
}

var toggleSlide = function(id){ 
	if(!$(id).visible())									
		new Effect.BlindDown(id, {duration: 0.5});
	else
		new Effect.BlindUp(id, {duration: 0.5});
}

function editFailed(t, obj){
	//alert(t.responseText);
	obj.innerHTML	= t.responseText;
	//cleanUp(obj);
}

var deletecontent = function(id){
	var success	= function(t){contentremoved(t,id);}
	var failure	= function(t){editFailed(t);}
	var url = 'index.cfm?do=cms.deletecontent&contentid='+id;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});	
}

var contentremoved = function(t,id){
	t.responseText.evalScripts();
	
	if(task == true){
		sysmsgdisplay('sysnote',msg);
		new Effect.Fade('content_'+id, {afterFinish:function(){$('content_'+id).remove()} });
	}
	else{
		sysmsgdisplay('alertnote',msg);
	}
}

var setContentState = function(id){
	var success	= function(t){contentstatechanged(t,id);}
	var failure	= function(t){editFailed(t);}
	var url = 'index.cfm?do=cms.setcontentstate&contentid='+id;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});	
}

var contentstatechanged = function(t,id){
	t.responseText.evalScripts();

if(task == true){
		$('contstatusimg_'+id).src = img;
		$('contstatustxt_'+id).innerHTML = txt;
	}
}

var chkcategorydelete = function(cateid){
	var success	= function(t){doescategoryhaveitems(t,cateid);}
	var failure	= function(t){editFailed(t);}
	var url = 'index.cfm?do=cms.chkcategorydata&categoryid='+cateid;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});
}

var doescategoryhaveitems = function(t,cateid){
	t.responseText.evalScripts();
	
	if(task==true){
		if(totalitems==0){
			deleteitem('category',cateid,'cate_'+cateid);
		}
		else{
			Modalbox.show('index.cfm?do=cms.AssignCategoryItems2OtherCategory&categoryid='+cateid+'&simplelayout=1', {title:'Assign Content to Other Categories', width: 602, overlayClose: false });	
		}
	}
}
var assign2othercategory = function(frmid,cateid){
	var success	= function(t){othercategoryassigned(t,cateid);}
	var failure	= function(t){editFailed(t);}

	var pars = $(frmid).serialize();
	var url = 'index.cfm?do=cms.ActAssignCategoryItems2OtherCategory';
	var myAjax = new Ajax.Request(_noCache(url), {method:'get', parameters:pars, onSuccess:success, onFailure:failure});	
}

var othercategoryassigned = function(t,cateid){
	t.responseText.evalScripts();
	
	if(task == true){
		//now delete the user
		//deletecategory(cateid);
		deleteitem('category',cateid,'cate_'+cateid);
		Modalbox.hide();
	}
	//alert(task); alert(usrid);
}

var chkuserdelete = function(usrid){
	var success	= function(t){doesuserhavecontent(t,usrid);}
	var failure	= function(t){editFailed(t);}
	var url = 'index.cfm?do=cms.getUserContents&UserID='+usrid;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});
}

var doesuserhavecontent = function(t,usrid){
	t.responseText.evalScripts();
	if(reccount == 0){
		//alert('i am about to delete this user with ID : ' + usrid);
		deleteuser(usrid);
	}
	else{
		Modalbox.show('index.cfm?do=cms.AssignContent2OtherUser&userid='+usrid+'&simplelayout=1', {title:'Assign Content to Other User', width: 602, overlayClose: false });
	}
}

var assign2otherusr = function(frmid,usrid){
	var success	= function(t){contentassigned(t,usrid);}
	var failure	= function(t){editFailed(t);}

	var pars = $(frmid).serialize();
	var url = 'index.cfm?do=cms.ActAssignContent2User';
	var myAjax = new Ajax.Request(_noCache(url), {method:'get', parameters:pars, onSuccess:success, onFailure:failure});	
}

var contentassigned = function(t,usrid){
	t.responseText.evalScripts();
	
	if(task == true){
		//now delete the user
		deleteuser(usrid);
		Modalbox.hide();
	}
	//alert(task); alert(usrid);
}

var deleteuser = function(id){
	var success	= function(t){userremoved(t,id);}
	var failure	= function(t){editFailed(t);}
	var url = 'index.cfm?do=cms.UserAction&UserID='+id+'&Delete=yes';
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});	
}

var userremoved = function(t,id){
	t.responseText.evalScripts();
	
	if(task == true){
		new Effect.Fade('userblk_'+id, {afterFinish:function(){$('userblk_'+id).remove()} });
	}
}

var deleteitem = function(item2del,id,idcontainer){
	var success	= function(t){itemremoved(t,id,idcontainer);}
	var failure	= function(t){editFailed(t);}
	
	switch(item2del){
		case 'blocks' :{
			var url = 'index.cfm?do=cms.actblock&blockid='+id+'&action=delete';
			break;
		}
		case 'authors' :{
			var url = 'index.cfm?do=cms.deleteauthor&authorID='+id;
			break;
		}
		case 'bannercategory' :{
			var url = 'index.cfm?do=cms.actBannerCategory&BnrCatID='+id+'&Delete=1';
			break;
		}
		case 'banner' :{
			var url = 'index.cfm?do=cms.ActEditBanner&BnrID='+id+'&Delete=1';
			break;
		}
		case 'guestbook' :{
			var url = 'index.cfm?do=cms.ActGuestBook&GBID='+id+'&DelGB=yes';
			break;
		}
		case 'mailinglist' :{
			var url = 'index.cfm?do=cms.ActMailingList&mlID='+id+'&delete=yes';
			break;
		}
		case 'polls' :{
			var url = 'index.cfm?do=cms.deletepoll&pollid='+id;
			break;
		}	
		case 'researchers' :{
			var url = 'index.cfm?do=cms.deleteresearcher&id='+id;
			break;
		}
		case 'role' :{
			var url = 'index.cfm?do=cms.deleterole&roleid='+id;
			break;
		}		
		case 'category' :{
			var url = 'index.cfm?do=cms.deletecategory&categoryid='+id;
			break;
		}	
		case 'comments' :{
			var url = 'index.cfm?do=cms.ActContentComments&buttonclicked=singledelete&messageid='+id;
			break;
		}
		case 'media' :{
			var url = 'index.cfm?do=cms.deletemedia&id='+id;
			break;
		}		
	}
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});	
}

var itemremoved = function(t,id,idcontainer){
	t.responseText.evalScripts();
	if(task == true){ 
		sysmsgdisplay('sysnote',msg);
		new Effect.Fade(idcontainer, {afterFinish:function(){$(idcontainer).remove()} });
	}
	else{
		sysmsgdisplay('alertnote',msg);
	}
}
// ============================================================ //

var createRole = function(id, img, url){
	$('processbuttons').hide();
	$('processindicator').innerHTML	= '<img src='+img+' border="0" />';
	var success	= function(t){roleCreated(t);}
	var failure	= function(t){editFailed(t);}

	var pars = $(id).serialize();
	var url = 'index.cfm?do=cms.AddRole&roleid=0';
	var myAjax = new Ajax.Request(_noCache(url), {method:'post', parameters:pars, onSuccess:success, onFailure:failure});	
}

var roleCreated = function(t){
	t.responseText.evalScripts();

	if(!task){
		$('processbuttons').show();
		$('processindicator').innerHTML	= '';
		sysmsgdisplay('error',msg);
	}
	else{
		new Effect.BlindUp('addrole', {duration: 0.2});
		window.location.href='index.cfm?do=cms.EditRole&roleid='+newroleid;
	}
}



	var assigncap = function(frmhdnfld, roleid, capid){
		if($(frmhdnfld).value == 1)
			cbval = 0;
		else
			cbval = 1;
		var success	= function(t){capassigned(t,frmhdnfld,roleid,capid,cbval);}
		var failure	= function(t){editFailed(t);}

		var url = 'index.cfm?do=cms.UpdateRoleCap&roleid='+roleid+'&capid='+capid+'&cbval='+cbval;
		var myAjax = new Ajax.Request(_noCache(url), {method:'post', onSuccess:success, onFailure:failure});	
		
	}
	
	var capassigned = function(t,frmhdnfld,roleid,capid,cbval){
		t.responseText.evalScripts();

		if(task==true){
			// set the hidden fld value
			$(frmhdnfld).value = cbval;
			if(cbval==1){
				oldcls = 'capdisabled';
				newcls = 'capenabled';
				imgsrc = 'images/12-em-apply.png';
			}
			else {
				oldcls = 'capenabled';
				newcls = 'capdisabled';
				imgsrc = 'images/12-em-cross.png';
			}
			// update the cls n img
			$('capimg_'+roleid+'_'+capid).src = imgsrc;
			$('cap_'+roleid+'_'+capid).removeClassName(oldcls);
			$('cap_'+roleid+'_'+capid).addClassName(newcls);
			
		}
	}
	
	var eip_success = function(obj,eipid){
		if(typeof obj != 'undefined'){
			obj.responseText.evalScripts();
			$(eipid).innerHTML = fldval;
		}
	}



/* NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN  Tags  NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN */
var HIDDEN_TAG_LIST = 'hidden_tagsList';
var UL_CURRENT_TAGS = 'ul_currentTags';
var INPUT_TAGS = 'input_tags';

// appendTag: apeend the wrote tags into the hidden list and show it
var appendTag = function (tag)
	{
		if( tag == '' ) { alert('erro '); return;}
		showAndAppendTag(tag);

/* get list of tags in input_tags */
/*		$(INPUT_TAGS).value = $(INPUT_TAGS).value.replace(/،/g,',');
		var typedTags =  $(INPUT_TAGS).value.split(',');
		typedTags.each
			(
			function(v,k)
				{
				if(v.trim().length)
					{
					showAndAppendTag(v);
					}
				}
			);
		$(INPUT_TAGS).value = '';*/
	};

var showAndAppendTag = function(tag)
	{
	var tarr = $(HIDDEN_TAG_LIST).value.split(',');
	//alert(tarr.indexOf(v));
	if(tarr.indexOf(tag) == -1)
		{
		tarr.push(tag);
		$(HIDDEN_TAG_LIST).value = tarr;

		var tag_div_1 = document.createElement('div');
		tag_div_1.id = 'tag_current_'+tag;
		tag_div_1.className = 'file_box';
		
		var tag_div_2 = document.createElement('div');
		tag_div_2.className = 'fb_r';

		var tag_tagText = document.createTextNode(tag);
		
		var tag_a_href = document.createElement('a');
		tag_a_href.href = "javascript:void(0);";
		tag_a_href.onclick = function () {hideAndRemoveTag(tag,'tag_current_'+tag);};
		tag_a_href.innerHTML = '<img border="0" align="absbottom" src="images/Form_added_item_arc_left_ho.png"/>';

		$(tag_div_2).appendChild(tag_tagText);
		$(tag_div_2).appendChild(tag_a_href);
		$(tag_div_1).appendChild(tag_div_2);
		$(UL_CURRENT_TAGS).appendChild(tag_div_1);

		//var div = document.createElement("div");
/*		var a = document.createElement("a");
		a.href = "javascript:void(0);";
		a.onclick = function () {hideAndRemoveTag(v,a);};
		a.innerHTML = v;
		var li = document.createElement("li");
		li.appendChild(a);
		$(UL_CURRENT_TAGS).appendChild(li);*/
		}
	};

var hideAndRemoveTag = function(tag,tagElement)
	{
	var tarr = $(HIDDEN_TAG_LIST).value.split(',');
	var ridx = tarr.indexOf(tag)
	if(ridx != -1)
		{
		tarr.removeItem(ridx)
		$(HIDDEN_TAG_LIST).value = tarr;
		Element.remove(tagElement);
		};
	};
/* NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN  /Tags  NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN */

/* NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN  xx  NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN */

var modifyMedia = function(frmid,mediaid,mediaupdateorigin)
	{
		var success	= function(t){mediamodified(t,mediaid,mediaupdateorigin);}
		var failure	= function(t){editFailed(t);}
		
		var pars = $(frmid).serialize();
		var url = 'index.cfm?do=cms.ActEditMedia';
		var myAjax = new Ajax.Request(_noCache(url), {method:'get', parameters:pars, onSuccess:success, onFailure:failure});	
	}

var mediamodified = function(t,mediaid,mediaupdateorigin){
	t.responseText.evalScripts();
	if(task==true){
		if(mediaupdateorigin=='addmedia'){
			sysmsgdisplay('sysnote',msg);
			$('filename_'+mediaid).innerHTML = updtitle;
			new Effect.BlindUp('fileDetail_'+mediaid, {duration: 1.5});
			//$('fileDetail_'+mediaid).toggle();
		}
		else if(mediaupdateorigin=='editmedia'){
			window.location.href='index.cfm?do=cms.medialib';
		}
	}
	else{
		sysmsgdisplay('error',msg);		
	}
}

var addmiscimage = function(id,type){
	Modalbox.show('index.cfm?do=cms.browsenselect&id='+id+'&type='+type+'&simplelayout=1', {title:'مكتبة الوسائط', width: 980, height: 580, overlayClose: false });	
}

var filtermedia =function(pageurl,ftype,selval){alert(selval);
	if(ftype == 'type'){
		Modalbox.show(pageurl+'&type='+selval+'&simplelayout=1', {title:'مكتبة الوسائط', width: 980, height: 580, overlayClose: false });	
	}
	if(ftype == 'date'){
		Modalbox.show(pageurl+'&fdate='+selval+'&simplelayout=1', {title:'مكتبة الوسائط', width: 980, height: 580, overlayClose: false });	
	}	
}

var addmedia = function(id,addwhat,selmode,type,contenttype){
	//if(id != 0)
		Modalbox.show('index.cfm?do=cms.browsemedialib&id='+id+'&type='+type+'&contenttype='+contenttype+'&addwhat='+addwhat+'&selmode='+selmode+'&simplelayout=1', {title:'مكتبة الوسائط', width: 980, height: 580, overlayClose: false });	
	//else{
		//alert('Access denied');
	//}
}

var submitimg = function(imgid,filepath){
	var upfield = $('contentImage');
	var imgPlace = $('imagePlace');
	//alert(imgname); alert(count);alert(filepath)
	//if($('mlsel_'+count).checked == true){
		upfield.value = imgid;
	
		$('imagePlace').show();
		$('misc_img').src = filepath ;
		
		Modalbox.hide();
	//}
}

var submitmiscimg = function(imgname,filepath){
	var upfield = $('cImage');
	var imgPlace = $('imagePlace');
	//alert(imgname); alert(count);alert(filepath)
	//if($('mlsel_'+count).checked == true){
		upfield.value = imgname;
	

		$('misc_img').src = filepath + imgname;
		$('imagePlace').show();
		Modalbox.hide();
	//}
}

var submitMl = function(frmid){
		var success	= function(t){mlibsubmitsuccess(t);}
		var failure	= function(t){editFailed(t);}
		
		var pars = $(frmid).serialize();
		var url = 'index.cfm?do=cms.ActBrowseMediaLib';
		var myAjax = new Ajax.Request(_noCache(url), {method:'get', parameters:pars, onSuccess:success, onFailure:failure});	
}

var mlibsubmitsuccess = function(t){
	t.responseText.evalScripts();
	if(task==true){
		if(type=='image'){
			$('contentImage').value = imgid;
			$('imagePlace').innerHTML = filenames;
			//$('imageControl').show();
		}
		else {
			Insertion.Before('addattachmentshere',filenames);
		}
		Modalbox.hide();
		sysmsgdisplay('sysnote',msg);
	}
	else{
		sysmsgdisplay('error',msg);		
	}
}

var removeAttachment = function(contid,attachid){
	var success	= function(t){attahmentremoved(t,attachid);}
	var url = 'index.cfm?do=cms.removecontentattachment&contentid='+contid+'&attachmentid='+attachid;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post',onSuccess:success});
}

var attahmentremoved = function(t,attachid){
	t.responseText.evalScripts();
	if(task==true){
		new Effect.Fade('cntfile_'+attachid);
		$('cntfile_'+attachid).remove();
		sysmsgdisplay('sysnote',msg);
	}
}

var updmlcb = function(container,cateid,cbid){
	if($(container).checked){
			cbval = 1;
		}
	else{
		cbval = 0
	}
	var success	= function(t){cbjobdone(t);}
	var url = 'index.cfm?do=cms.updatebrowsemediacollection&categoryid='+cateid+'&cbval='+cbval+'&cbid='+cbid;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post',onSuccess:success});
}

var cbjobdone = function(t){
	t.responseText.evalScripts();
	if(task == false){
		 alert(msg);
		}
	else{
		sysmsgdisplay('alertnote',msg);
	}
}

var resizeimage = function(id,resizethis,resizeto){
	if(!isNaN(resizeto)){
		
		var success	= function(t){resizeimageSuccess(t,id);}
		var url = 'index.cfm?do=cms.resizeimage&id='+id+'&resizethis='+resizethis+'&resizeto='+resizeto;
		var myAjax = new Ajax.Request(_noCache(url), {method:'post',onSuccess:success});
	}	
	else{
		alert('Improper Value provided for Resize');
	}
}

var resizeMiscimage = function(imgpath,imgname,resizethis,resizeto){
	if(!isNaN(resizeto)){
		
		var success	= function(t){resizeimageSuccess(t,1);} // 1 is hardcoded
		var url = 'index.cfm?do=cms.resizeMiscimage&imgpath='+imgpath+'&imgname='+imgname+'&resizethis='+resizethis+'&resizeto='+resizeto;
		var myAjax = new Ajax.Request(_noCache(url), {method:'post',onSuccess:success});
	}	
	else{
		alert('Improper Value provided for Resize');
	}
}

var resizeimageSuccess = function(t,id){
	t.responseText.evalScripts();
	
	if(task == true){
		$('imgwh_input_'+id).hide();
		$('imgwh_text_'+id).show();		
		$('img_display_'+id).src = imgsrc;
		$('img_width_'+id).innerHTML = width;
		$('img_height_'+id).innerHTML = height;
		new Effect.Highlight('img_width_'+id,{duration:1.5});
		new Effect.Highlight('img_height_'+id,{duration:1.5});	
		sysmsgdisplay('sysnote',msg);
	}
	else{
		sysmsgdisplay('alertnote',msg);
	}
	
}

//// CROP IMAGE
var lastcrop = 0;
var loadcropimage = function(id){
	if(lastcrop){
		$('img_crop_'+lastcrop).innerHTML = '';
	}
	
	var success	= function(t){showimageforcrop(t,id);}
	var url = 'index.cfm?do=cms.cropimage&mediaid='+id;
	var myAjax = new Ajax.Request(_noCache(url), {method:'post',onSuccess:success});
	
}

var showimageforcrop = function(t,id){
	lastcrop = id;
	$('img_crop_area_'+id).show();
	$('img_crop_area_'+id).innerHTML = t.responseText;
	t.responseText.evalScripts();
	//$('img_crop_'+id).scrollTo();
}

// setup the callback function
var onEndCrop = function (coords, dimensions ) {
	$( 'img_crp_x1' ).value = coords.x1;
	$( 'img_crp_y1' ).value = coords.y1;
	$( 'img_crp_x2' ).value = coords.x2;
	$( 'img_crp_y2' ).value = coords.y2;
	$( 'img_crp_width' ).value = dimensions.width;
	$( 'img_crp_height' ).value = dimensions.height;
}

// crop action
var croptheimage = function(id,x1,y1,crpwidth,crpheight){
		//alert(x1);alert(y1); alert(crpwidth);
		//alert(crpheight);
		if(crpwidth != 0 && crpheight != 0){
			var success	= function(t){imagecropsuccess(t,id,crpwidth,crpheight);}
			var url = 'index.cfm?do=cms.ActImagecrop&id='+id+'&x1='+x1+'&y1='+y1+'&width='+crpwidth+'&height='+crpheight;
			var myAjax = new Ajax.Request(_noCache(url), {method:'post',onSuccess:success});
		}
		else{
			alert('You didn\'t select an area to Crop');
		}
}

var imagecropsuccess = function(t,id,crpwidth,crpheight){
	t.responseText.evalScripts();
	if(task==true){
		$('img_crop_input_'+id).hide();
		$('img_crop_'+id).show();
		$('img_width_'+id).innerHTML = crpwidth;
		$('img_height_'+id).innerHTML = crpheight;
		$('img_display_'+id).src = imgsrc;
		sysmsgdisplay('sysnote',msg);
	}
	else{
		sysmsgdisplay('alertnote',msg);
	}
}

var lastopenml = "";
var activatethis = function(id){ 
	if(lastopenml != ""){
		$(lastopenml).hide();
	}
	//update the tabs class
	$('mltabs').getElementsByClassName('mltabs_active')[0].className = 'mltabs';
	$(id).removeClassName('mltabs');
	$(id).addClassName('mltabs_active');
	$(id+'_blk').show();
	lastopenml = id+'_blk';
	if(id == 'upload2ml'){
		$('formbuttons').hide();	
	}
	else{
		$('formbuttons').show();	
	}
}
 

// *********************** AJAX UPLOAD ************************ //
	/*
		'uploaded':true,
		'id':fileID,
		'name':'file.ClientFile',
		'newName':'file.ServerFile',
		'size':file.fileSize, 
		'elementId':'attributes.elementId'
	*/
	var afterUpload = function (arg)
		{
			//alert('uploaded'  + arg);
			//alert('arg.elementId ' + arg.elementId);
			$('uploadContainer_' + arg.elementId).update('تح تحميل الملف');
			
//			alert(arg.addwhat);
//			if(arg.addwhat=='addcontentimage'){
//				$('imagePlace').innerHTML = arg.filenames;
//				$('imageControl').show();
//			}
//			else{
//				Insertion.Before('addattachmentshere',arg.filenames);
//			}
			
			loadEditMedia(arg.elementId,arg.id);
		}


	var uploadFrames = 1;

	var addUploadFrame = function(fileparams)
		{
		//alert(fileparams);
		//fileparams = (typeof fileparams == 'undefined')?'':fileparams;
		
		uploadFrames++;
		//container dic
		var uDivCo = document.createElement('div');
		uDivCo.id = 'uploadContainer_' + uploadFrames;

		// status dive
		var uDivSt = document.createElement('div');
		uDivSt.id = 'uploadStatus_' + uploadFrames;

		// upload form
		var uForm = document.createElement('form');
		uForm.id = 'uploadForm_' + uploadFrames;
		uForm.action = 'index.cfm?do=cms.ajaxUpload&elementId=' + uploadFrames;
		uForm.method = 'post';
		uForm.enctype = 'multipart/form-data';
		uForm.target = 'uploadFrame_' + uploadFrames;
		uForm.onsubmit = function(){alert('not working i dont know');};
		//uForm.onsubmit = function(){alert('fffff');startUpload(uploadFrames);};
		
		// file input field
		var uFileInput = document.createElement('input');
		uFileInput.type = 'file';
		uFileInput.name = 'filename';
		uFileInput.onchange = function () {uForm.submit()};
		
		var uFileParam = document.createElement('input');
		uFileParam.type = 'hidden';
		uFileParam.name = 'fileparams';
		uFileParam.value = fileparams;
		
		// the hidden upload frame
		var uFrame = document.createElement('iframe');
		uFrame.name = 'uploadFrame_'+uploadFrames;
		uFrame.id = 'uploadFrame_'+uploadFrames;
		uFrame.scrolling = "no";
		uFrame.src = 'about:blank';
		uFrame.className = 'fileuploadframe';
		uFrame.style.display = 'none';

		uForm.appendChild(uFileInput);			// add input to form
		uForm.appendChild(uFileParam);      // add file param to form
		uDivSt.appendChild(uForm);					// add form to status div
		uDivCo.appendChild(uDivSt);				// add status div to container div
		uDivCo.appendChild(uFrame);				// add frame to cintained div
		$('allUploads').appendChild(uDivCo);
		}
	
	var loadEditMedia = function (elmIdx,fid,origin,addwhat,thum_filename)
		{
			//alert(addwhat);//alert(filename);
			if(addwhat == 'addcontentimage'){
				$('imagePlace').innerHTML = '<img src="attach/files/'+thum_filename+'" border="0" />';
				//$('imageControl').show();	
			}
		var url = 'index.cfm?do=cms.editMedia&simplelayout=1&mediaID='+fid+'&origin='+origin;
		new Ajax.Request(url, 
					 {
						method: 'get',
						onSuccess: function (t)
							{
							$('uploadContainer_'+elmIdx).update(t.responseText);
							},
						onFailure: fail
						});
		
		}
	
	var loadMiscImage = function(origin,addwhat,thum_filename,filepath,uplddir){
		//alert(thum_filename); alert(filepath)
		var upfield = $('cImage');
		var imgPlace = $('imagePlace');
		upfield.value = thum_filename;
 		
		$('misc_img').src = filepath + thum_filename;
		//alert($('misc_img').src);
		$('imagePlace').show();		
		//Modalbox.hide();
		//$('imagePlace').innerHTML = '<img src="attach/files/'+thum_filename+'" border="0" />';

		var url = 'index.cfm?do=cms.editMiscImage&simplelayout=1&filename='+thum_filename+'&filepath='+uplddir+'&origin='+origin;
		new Ajax.Request(url, 
					 {
						method: 'get',
						onSuccess: function (t)
							{
							$('uploadContainer').update(t.responseText);
							},
						onFailure: fail
						});
		
		}

// *********************** AJAX UPLOAD ************************ //



// ***********************  Shadow Menu Script ************************ //
	var My_CURRENT_LINK = null;
	var My_CURRENT_MENU = null;
	var My_CURRENT_TIMER = null;
	var My_FADE_DURATION = 0.2;
	var My_HIDE_AFTER = 50; /* 500 ms = 0.5 sec */
	
	var My_initMenu = function(Link,Menu,Pos,Space, onEvent, offEvent)
		{
		Pos = (typeof Pos == 'undefined')?'bottom':Pos; /* top,right,bottom,left */
		Space = (typeof Space == 'undefined')?5:Space; /* space btwn link and menu in pixle */
		onEvent = (typeof onEvent == 'undefined')?'mouseover':onEvent;
		offEvent = (typeof offEvent == 'undefined')?'mouseout':offEvent;
		
		
		//loop over all child Elements and make it all shows the menu; to force the menu show
		Element.descendants(Menu).each(function(s) 
			{
			Event.observe(s, onEvent, function () {My_showMenu(Link,Menu,Pos,Space);});
			Event.observe(s, offEvent, function () {My_showMenu(Link,Menu,Pos,Space);});
			});
		//loop over all child Elements and make it all shows the menu; to force the menu show
		Element.childElements(Menu).each(function(s) 
			{
			Event.observe(s, onEvent, function () {My_showMenu(Link,Menu,Pos,Space);});
			Event.observe(s, offEvent, function () {My_showMenu(Link,Menu,Pos,Space);});
			});
		
		
		//Event.observe(Link, 'click', function () {My_showMenu(Link,Menu);});
		Event.observe(Link, onEvent, function () {My_showMenu(Link,Menu,Pos,Space);});
		Event.observe(Link, offEvent, function () {My_hideMenuTimer(Link,Menu);});
		Event.observe(Menu, onEvent, function () {My_showMenu(Link,Menu,Pos,Space);});
		Event.observe(Menu, offEvent, function () {My_hideMenuTimer(Link,Menu);});
		}
	
	var My_showMenu = function (Link,Menu,Pos,Space)
		{
		if(My_CURRENT_MENU != Menu && My_CURRENT_MENU != null){My_hideMenu(My_CURRENT_LINK,My_CURRENT_MENU);}
		clearTimeout(My_CURRENT_TIMER);
		
		M = $(Menu);
		M.show();
		setPosition (Link,Menu,Space,Pos)

//
//		L = $(Link);
//		M = $(Menu);
//		M.show();
//		Ld = L.getDimensions();
//		Md = M.getDimensions();
//		var ost=0;		/* offset top */
//		var osl=0;		/* offset left */
//
//		if(Pos == 'top')
//			{
//			ost=-(Md.height+Space);
//			osl=-(Md.width-Ld.width)/2;
//			}
//		else if(Pos == 'right')
//			{
//			ost=-(Md.height-Ld.height)/2;
//			osl=(Ld.width+Space);
//			}
//		else if(Pos == 'bottom')
//			{
//			ost=Ld.height+Space;
//			osl=-(Md.width-Ld.width)/2;
//			}
//		else if(Pos == 'left')
//			{
//			ost=-(Md.height-Ld.height)/2;
//			osl=-(Md.width+Space);
//			}
//		
//		Element.clonePosition(M,L, {setLeft:true,setTop:true,setWidth:false,setHeight:false,offsetLeft:osl,offsetTop:ost});

		My_CURRENT_LINK = Link;
		My_CURRENT_MENU = Menu;
		}

	var My_hideMenuTimer = function (Link,Menu)
		{
		L = $(Link);
		M = $(Menu);
		My_CURRENT_TIMER = setTimeout(function () 
			{
				My_hideMenu(Link,Menu);
			},My_HIDE_AFTER);
		}
	var My_hideMenu = function (Link,Menu)
		{
		L = $(Link);
		M = $(Menu);
		Effect.Fade(Menu,{duration:My_FADE_DURATION});
		/* either to use this or above effect */
		My_CURRENT_LINK = null;
		My_CURRENT_MENU = null;
		}
/************************ /Shadow Menu Script ************************/

			var setPosition = function (source,target,space,pos)
				{
				var s = $(source);
				var t = $(target);
				var sD = s.getDimensions();
				var tD = t.getDimensions();
				
				var topOffset =0;
				var leftOffset =0;
				if(pos == 'top')
					{
					topOffset=-(tD.height+space);
					leftOffset=-(tD.width-sD.width)/2;
					}
				else if(pos == 'right')
					{
					topOffset=-(tD.height-sD.height)/2;
					leftOffset=(sD.width+space);
					}
				else if(pos == 'bottom')
					{
					topOffset=sD.height+space;
					leftOffset=-(tD.width-sD.width)/2;
					}
				else if(pos == 'left')
					{
					topOffset =-(tD.height-sD.height)/2;
					leftOffset =-(tD.width+space);
					}

				new Element.clonePosition(t,s, {setLeft:true,setTop:true,setWidth:false,setHeight:false,offsetLeft:leftOffset,offsetTop:topOffset});
				}


/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                    POLL
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

var POLL_CONTAINER = 'poll_place';
var POLL_FORM = 'poll_form';

var poll_show = function ()
	{
		var url = 'index.cfm?do=cms.poll';
		new Ajax.Request(url, 
					 {
						method: 'get',
						parameters: {},
						onSuccess: function(t) 
												{
												$(POLL_CONTAINER).update(t.responseText);
												}
						});
	}

var poll_submit = function ()
	{
		var url = '';

		$(POLL_FORM).request(
			{
				onComplete: function(t)
					{ 
					/* do the job here */
					eval('res='+t.responseText);
 					if(res.SUCCESS)
						{
							poll_showResult(res.DATA.POLLID);
						}
					else
						{
 						}
					}
			})
	}
	
var poll_showResult = function(pollid)
	{
		var url = 'index.cfm?do=cms.pollresult';
		new Ajax.Request(url, 
					 {
						method: 'get',
						parameters: {pollid:pollid},
						onSuccess: function(t)
												{
												$(POLL_CONTAINER).update(t.responseText);
												}
						});
	}

/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                    /POLL
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/


/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                   CONTENT COMMENT
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

var comm_form = 'comment_form';
var comm_gmsg = 'comment_fail';
var comm_rmsg = 'comment_success';

var comm_submit = function ()
	{
		$(comm_gmsg).update();
		$(comm_rmsg).update();
		$(comm_form).request(
			{
				onComplete: function(t)
					{ 
					/* do the job here */
					eval('res='+t.responseText);
 					if(res.SUCCESS)
						{
							/* 
								show thanks message
								reset the form
								enable the form
							*/
						$(comm_form).reset();
						$(comm_gmsg).update(res.MESSAGE);
						}
					else
						{
							/* 
								show error message
								enable the form
							*/
						$(comm_rmsg).update(res.ERROR);
 						}
					getCaptch('commentCaptcha');
					}
			})
	}

var getCaptch = function (elmid)
	{
		var url='index.cfm?do=cms.getCaptchImage';
		new Ajax.Request(_noCache(url), 
						{
						method: 'get',
						onSuccess: function(t) {$(elmid).update(t.responseText)},
						onFailure: function(t) {$(elmid).update('حاول مجددا')},
						onComplete: function(t) {}
						});
	}
	
	
	/*
	@elmid	:	Element Id To place the comments
	@cid		:	contentid
	@p			:	page no;
	*/
	var getContentComments = function (elmid, cid, p)
		{
		var url='index.cfm?do=cms.getComments&contentid='+cid+'&page='+p;
		new Ajax.Request(_noCache(url), 
						{
						method: 'get',
						onSuccess: function(t) 
							{
								//alert('getting');
							eval('res='+t.responseText);
								//alert('got it');
							if(res.SUCCESS)
								{
								//alert('updating' + res.DATA);
								//$(elmid).innerHTML = 'sdvsdv';
								$(elmid).innerHTML = res.DATA;
								//alert('updated');
								if(p > 1)
									{
										Element.scrollTo('commtop');
									}
								}
							else
								{
									alert(res.ERROR);
								}
							},
						onFailure: function(t) {$(elmid).update('عفوا لا يمكن تحديث التعليقات الآن ... حاول مجددا في وقت لاحق')},
						onComplete: function(t) {}
						});
		}

/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                   /CONTENT COMMENT
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/





/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                    LOGIN
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

var LOGIN_CONTAINER = 'login_place';
var LOGIN_FORM = 'login_form';
var LOGIN_MSG = 'login_msg';
var LOGIN_ERR = 'login_err';

var login_submit = function ()
	{
		var url = '';

		$(LOGIN_MSG).update();
		$(LOGIN_ERR).update();
		
		$(LOGIN_FORM).request(
			{
				onComplete: function(t)
					{ 
					/* do the job here */
					eval('res='+t.responseText);
					if(res.SUCCESS)
						{
							/*  This version of the refresh function will cause a new
							 		entry in the visitor's history.  It is provided for
								  those browsers that only support JavaScript 1.0.
							*/
							/*window.location.href = unescape(window.location.pathname + window.location.search);*/
							$(comm_rmsg).update(res.MESSAGE);
 						}
					else
						{
							$(comm_rmsg).update(res.ERROR);
 						}
					}
			})
	}

var user_logout = function ()
	{
		var url = 'index.cfm?do=cms.ajuser';

		$(LOGIN_MSG).update();
		$(LOGIN_ERR).update();
		
		new Ajax.Request(url, 
						{
						method: 'get',
						parameters: {a:'logout'},
						onSuccess: function(t) 
							{
							/* do the job here */
							eval('res='+t.responseText);
							if(res.SUCCESS)
								{
									/*  This version of the refresh function will cause a new
									  	entry in the visitor's history.  It is provided for
									  	those browsers that only support JavaScript 1.0.
									*/
									window.location.href = unescape(window.location.pathname + window.location.search);
									/*poll_showResult(res.DATA.POLLID);*/
								}
							else
								{
									$(LOGIN_ERR).update(res.ERROR);
									/* if something wrong , fire some different action.*/
								}
							}
						});

	}
	

/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                    /LOGIN
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

var STARTS_PLACE = 'id_content_rate';

var rateContent = function (id,rate)
	{
		var url = 'index.cfm';
		new Ajax.Request(url, 
						{
						method: 'get',
						parameters: {contentid:id,rate:rate,'do':'cms.setstat'},
						onSuccess: function(t) 
							{
							/* do the job here */
							eval('res='+t.responseText);
							if(res.SUCCESS)
								{
									$(STARTS_PLACE).update(res.DATA);
								}
							else
								{
								}
							}
						});
	}



/*    AMEEN : 07/10/2009 : Swapping Titles  */
			var sw_init = function ()
				{
				Effect.Appear('sw_0');
				setInterval('sw_start()', sw_displayTime*1000);
				}
			
			var sw_start = function ()
				{
				Effect.Fade('sw_'+sw_currIdx, {duration:0.3});
				sw_currIdx = ++sw_currIdx % sw_maxRec;
				Effect.Appear('sw_'+sw_currIdx, {delay:0.4,duration:0.3});
				}
/*    /AMEEN : 07/10/2009 : Swapping Titles  */


function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}





	function my_scroll (_scrlElement, _scrlType, _stpCount)
		{
		
		if(typeof _scrlElement == "indefined") 
			{
			alert("Sorry ... but you have to pass at lest the ID of Element to scroll");
			return;
			}
		
		this.stepSize = 688;				/* in pixel */
		this.stepCount = _stpCount;				/* just a counter */
		this.stepCurrent = 1;
		this.stepLatest = 1;
		this.rejectIt = false;
		this.rotatorInterval = null;
		this.rotatorIntervalTime = 10000;
		this.scrollType = (typeof _scrlType == "undefined") ? 'h' : _scrlType ;    /*  this thould be either h or v  */
		this.scrollElement = _scrlElement;

		//theObject = this;
		// start the scroller
		//this.scroll_forward();
		//this.rotatorInterval = setInterval(this.scroll_forward, this.rotatorIntervalTime);
		
		}
		
	my_scroll.prototype.scroll_forward = function (_gotoStep)
		{

		if(this.rejectIt) return;
		this.rejectIt = true;
		clearInterval(this.rotatorInterval);
		var _scrollSize = 0;
		this.stepLatest = this.stepCurrent ;
		var _latestScrollSize = this.stepSize * (this.stepLatest-1);

		if(typeof _gotoStep != "undefined" && _gotoStep >= 1 && _gotoStep <= this.stepCount)
			{
			this.stepCurrent = _gotoStep;
			}
		else
			{
			this.stepCurrent = (this.stepCurrent >= this.stepCount) ? 1 : this.stepCurrent + 1 ;
			}

		var _currentScrollSize = this.stepSize * (this.stepCurrent-1);
		
		_scrollSize = _currentScrollSize - _latestScrollSize;
		var tempObject = this;
		new Effect.Move(this.scrollElement, { x: (this.scrollType == 'h')? _scrollSize : 0 , y: (this.scrollType == 'v')? _scrollSize : 0 , mode: 'relative' , duration:0.7 , afterFinish:function () {tempObject.rejectIt = false}});
		//alert(this.scroll_forward);
		
		//this.rotatorInterval = setInterval(this.scroll_forward, this.rotatorIntervalTime);


		};

	my_scroll.prototype.scroll_backward = function (_gotoStep)
		{

		if(this.rejectIt) return;
		this.rejectIt = true;

		clearInterval(this.rotatorInterval);
		var _scrollSize = 0;
		this.stepLatest = this.stepCurrent ;
		var _latestScrollSize = this.stepSize * (this.stepLatest-1);

		if(typeof _gotoStep != "undefined" && _gotoStep >= 1 && _gotoStep <= this.stepCount)
			{
			this.stepCurrent = _gotoStep;
			}
		else
			{
			this.stepCurrent = (this.stepCurrent <= 1) ? this.stepCount : this.stepCurrent - 1 ;
			}

		var _currentScrollSize = this.stepSize * (this.stepCurrent-1);
		
		_scrollSize = _currentScrollSize - _latestScrollSize;
		
		var tempObject = this;
		new Effect.Move(this.scrollElement , { x: (this.scrollType == 'h')? _scrollSize : 0 , y: (this.scrollType == 'v')? _scrollSize : 0 , mode: 'relative' , duration:0.7 , afterFinish:function () {tempObject.rejectIt = false}});

		//this.rotatorInterval = setInterval(this.scroll_forward, this.rotatorIntervalTime);
		};
