    $(document).ready(function() {
		addSubmitPostYourComment();
		addSubmitToEditPostYourComment()		
		addIsPalestinian();
		var tabs = $('#tabSet');
		if ( tabs.length > 0 ){
			tabs.tabs({onShow: function(){clearCachedDiv();}});
			addSubmitToEdit('Article');
			//addSubmitToEditMultiPart('Picture');
			addSubmitToEdit('Video');
			addSubmitToEdit('Link');
			addSubmitToEditAddDirectory();
			addSubmitToEditDeleteDirectory();
		}
		if ( $('#ActivityReportId').html() != null ){
			$('.activity').click(function(){
				var restful = $(this).attr('href');
				
				//alert(restful);
				$.get(restful,null,function(dataBack){
					if ( dataBack.indexOf('Delete') >=0 )
						$('#'+dataBack).html('Deleted');
					else
						$('#'+dataBack).html('Notified');
					});
				return false;
			   });
		}
 	});
	
	function addSubmitPostYourComment(){
		$('#PostYourComment').click(function(){
			$('#PostYourCommentForm').slideDown('slow');
				$(this).slideUp('slow');
			});
	}
	jQuery.extend({
	 	htmlUnicodeAndEscape: function (text){
			return escape(jQuery.htmlUnicode(text));
		},
	 	htmlUnicode: function (text){
		    var enc = "";
		    for(var pos=0; pos<text.length; pos++){
		        var c=text.charCodeAt(pos);
				if (c==60){
				    enc += "&lt;";
				}
				else if (c==62) {
				    enc += "&gt;";
				}
				else if (c==38) {
				    enc += "&amp;";
				}
				else if (c>=32 && c<128)
				{
				    enc += text.charAt(pos);
				}
				else
				{
				    enc += "&#"+c+";";
				}
		    }
		    return enc;
		},
	    param2: function( a ) {
			var s = [];

			// If an array was passed in, assume that it is an array
			// of form elements
			if ( a.constructor == Array || a.jquery )
				// Serialize the form elements
				jQuery.each( a, function(){
					s.push( encodeURIComponent(this.name) + "=" +  jQuery.htmlUnicodeAndEscape(this.value) );
				});

			// Otherwise, assume that it's an object of key/value pairs
			else
				// Serialize the key/values
				for ( var j in a )
					// If the value is an array then the key names need to be repeated
					if ( a[j] && a[j].constructor == Array )
						jQuery.each( a[j], function(){
							s.push( encodeURIComponent(j) + "=" + jQuery.htmlUnicodeAndEscape(this));
						});
					else
						s.push( encodeURIComponent(j) + "=" + jQuery.htmlUnicodeAndEscape(jQuery.isFunction(a[j]) ? a[j]() : a[j]));

			// Return the resulting serialization
			return s.join("&").replace(/%20/g, "+");
		}
	});	
	function addSubmitToAddType(objectType){
		addSubmitAjax('#Add'+objectType+'Form',objectType,
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#'+objectType+'Error').html(htmlData);
				else{						
					$('#Add'+objectType+'Data').html(htmlData);
					$('#Add'+objectType).show();
				}
			});
	}
	function addSubmitToAddMultiType(objectType){
		addSubmitAjaxMultiPart('#Add'+objectType+'Form',objectType,'#'+objectType+'Error',
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#'+objectType+'Error').html(htmlData);
				else{						
					$('#Add'+objectType+'Data').html(htmlData);
					$('#Add'+objectType).show();
				}
			});
	}
	function addSubmitAjax(formId,extraData,onComplete){
	   $(formId).submit(function(){
			var thisForm 	= $(this);
			var action 		= thisForm.attr('action');
			var formData 	= $.param2(thisForm.serializeArray());
			var thisExtraData 	= extraData;

			$("body").addClass("curWait");
			$.ajax({  
			   type: "POST",  
			   url: action,  
			   data: formData, 
			   //contentType: "application/x-www-form-urlencoded; charset=windows-1256",			   
			   success: function(htmlData){
						$("body").removeClass("curWait");
						onComplete(htmlData,thisForm,thisExtraData);					
				}
			 }); 			
			return false;
		});
	}
	function addSubmitAjaxMultiPart(formId,extraData,statusId,onComplete){
	   $(formId).submit(function(){
			var thisForm 	= $(this);
			var action 		= thisForm.attr('action');
			var thisExtraData 	= extraData;
			

			$("body").addClass("curWait");
	  	    $.ajaxFileUpload({
				url: action,
				secureuri:false,
				fileElementId:'file1',
				dataType: 'html',
				beforeSend:function(){
					if ( statusId != null )
						$(statusId).html("Upload file to server, please wait!");
				},
				complete:function(){
					if ( statusId != null )
						$(statusId).html("success");
				},
				success: function (data,status) {
					alert("success");
					$("body").removeClass("curWait");
					onComplete(data.msg,thisForm,thisExtraData);					
				},
				error: function (data, status, e){
					alert(e);
				}
			});
		});
		
		return false;
	}
	function addSubmitToEdit(objectType){
		addSubmitAjax('#Add'+objectType,objectType,
			function(htmlData,thisForm,objectType){
				$('#Add'+objectType+'Data').html(htmlData);
				thisForm.hide();
				addSubmitToEditRegisterNewUser(objectType);
				addSubmitToAddType(objectType);
			});
	}
	function addSubmitToEditMultiPart(objectType){
		addSubmitAjax('#Add'+objectType,objectType,
			function(htmlData,thisForm,objectType){
				$('#Add'+objectType+'Data').html(htmlData);
				thisForm.hide();
				addSubmitToEditRegisterNewUser(objectType);
				//addSubmitToAddMultiType(objectType);
			});
			
		return false;
	}
	function addSubmitToEditAddDirectory(){
		addSubmitAjax('#AddDirectory','Directory',
			function(htmlData,thisForm,objectType){
				$('#AddDirectoryData').html(htmlData);
				thisForm.hide();
				$('#DeleteDirectory').show();
				addSubmitToInsertDirectory();
				addSubmitToEditRegisterNewUserDS();
			});
	}
	function addSubmitToEditPostYourComment(){
		addSubmitAjax('#PostYourCommentForm2','YourComment',
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#CommentError').html(htmlData);
				else{
					$('#commentsTable').html(htmlData);
					thisForm.hide();
					//addSubmitPostYourComment();
				}
			});
	}
	function addSubmitToEditDeleteDirectory(){
		addSubmitAjax('#DeleteDirectory','Directory',
			function(htmlData,thisForm){
				$('#AddDirectoryData').html(htmlData);
				thisForm.hide();
				$('#AddDirectory').show();
				addSubmitToDeleteDirectory();					
			});
	}
	function addSubmitToInsertDirectory(){
		addSubmitAjax('#InsertDirectory','Directory',
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#dsError').html(htmlData);
				else{						
					$('#AddDirectoryData').html("");
					$('#tableDS').html(htmlData);
					$('#AddDirectory').show();
					$('#DeleteDirectory').show();					
				}
			});
	}
	function addSubmitToEditRegisterNewUser(objectType){
		addSubmitAjax('#EditContact',objectType,
			function(htmlData,thisForm,objectType){
				$('#Add'+objectType+'Data').html(htmlData);
				addSubmitToRegisterNewUser(objectType);
				addIsPalestinian();
			    $('#Add'+objectType).show();
			});
	}
	function addSubmitToEditRegisterNewUserDS(){
		addSubmitAjax('#EditContact','Directory',
			function(htmlData,thisForm,objectType){
				$('#AddDirectoryData').html(htmlData);
				addIsPalestinian();
				addSubmitToRegisterNewUserDS();
			    $('#Add'+objectType).show();
				$('#Delete'+objectType).show();
			});
	}		
	function addSubmitToRegisterNewUserDS(){
		addSubmitAjax('#RegisterNewUser','Directory',
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#RegistrationError').html(htmlData);
				else{						
					$('#AddDirectoryData').html("");
					$('#tableDS').html(htmlData);
					$('#AddDirectory').show();
					$('#DeleteDirectory').show();					
				}
			});
	}
	function addSubmitToRegisterNewUser(objectType){
		addSubmitAjax('#RegisterNewUser',objectType,
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#RegistrationError').html(htmlData);
				else{						
					$('#Add'+objectType +'Data').html(htmlData);
					$('#Add'+objectType).submit();			
				}
			});
	}
	function clearCachedDiv(){
		$('#AddDirectoryData').html("");
		$('#AddLinkData').html("");
		$('#AddVideoData').html("");
		$('#AddArticleData').html("");
		$('#AddPictureData').html("");

		$('#AddPicture').show();
		$('#AddArticle').show();
		$('#AddLink').show();
		$('#AddVideo').show();
		$('#AddDirectory').show();
		$('#DeleteDirectory').show();					
	}
	function addSubmitToDeleteDirectory(){
		addSubmitAjax('#DeleteDirectory','Directory',
			function(htmlData,thisForm,objectType){
				if ( isError(htmlData) )
					$('#dsError').html(htmlData);
				else{						
					$('#AddDirectoryData').html("");
					$('#tableDS').html(htmlData);
					$('#AddDirectory').show();
					$('#DeleteDirectory').show();					
				}
			});
	}
	function isError(content){
		if (content.indexOf('ErrorMessage') > 0 || content.indexOf('Apache Tomcat') > 0)
			return true;
		else
			return false;
	}
	function addIsPalestinian(){
		var isPal = $('#IsPalestinian');
		 isPal.click(function(){
			if ($(this).attr('checked'))
				$('#PalestinianInfo').slideDown('slow');
			else
				$('#PalestinianInfo').slideUp('slow');
		});
		
		if (isPal.attr('checked'))
			$('#PalestinianInfo').slideDown('slow');
	}
	function changeRowsColorEvenOdd(elementId){
	   var  tag = '#' + elementId + ' tr:even';
	   var  dsE = $(tag);
	   if ( dsE != null ){
			dsE.css({'background-color': '#D5E6E1'});
	   }
	   tag = '#' + elementId + ' tr:odd'
	   var dsO = $(tag);
	   if ( dsO != null ){
			dsO.css({'background-color': '#B7FFDB'});
	   }
	}
	var d = document;
	var agt = navigator.userAgent.toLowerCase();

	function reloadPage(init) {  //Reloads the window if Netscape 4.x resized
	  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
	  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
	}
	reloadPage(true);

	function holdW(where){
	  var mW = "";
	  if(agt.indexOf('opera') != -1) {
	     return mW;
	  }
	  else
	  if((!d.getElementById) || (d.getElementById('top').style.minWidth == undefined)){
		var mW = "<hr size=0 color=white class=" + where + ">";

		return mW;
	  }
	  else
	  return mW;
	}
	if ( top.location != self.location ){
	     top.location = self.location
	}
	function openNewWindow(strURLPage, strTitle){
	      window.open(strURLPage,strTitle);
	}
	function openNewWindowNoBar(strURLPage, strTitle){
	      window.open(strURLPage,strTitle,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=400');
	}
	function submitNakbaInHebrew(_spot){
	     document.mapForm.spot.value = _spot;
		   document.mapForm.submit();
	}
	function submitEmailContact(_ContactId){
	     document.emailContactForm.ContactId.value = _ContactId;
	     document.emailContactForm.MessageReplyId.value = -1;
		   document.emailContactForm.submit();
	}
	function submitEmailContact(_ContactId){
	     document.emailContactForm.ContactId.value = _ContactId;
	     document.emailContactForm.MessageReplyId.value = -1;
		   document.emailContactForm.submit();
	}
	function submitEmailActivityId(_ActivityId){
	     document.emailContactForm.ContactId.value = -1;
	     document.emailContactForm.MessageReplyId.value = -1;
	     document.emailContactForm.ActivityId.value = _ActivityId;
 	     document.emailContactForm.submit();
	}
	function submitEmailMessageReplyId(_MessageReplyId){
         document.emailContactForm.ContactId.value = -1;
         document.emailContactForm.MessageReplyId.value = _MessageReplyId;
	     document.emailContactForm.submit();
     }
	var now = new Date();
	var date2000 = new Date(2000,0,2);
	function formatNumber(expr){
		 var str = expr.toString();
		 if ( str.length > 3 )
			 return str.substring(0,2) + "," + str.substring(2,str.length);
		  else
			 return str;
	}
	function jumpPage(newLoc){
		newPage = newLoc.options[newLoc.selectedIndex].value;
		if ( newPage != "" )
			window.location.href = newPage;
	}
	function dayToDays(inTime){
		return Math.floor(inTime.getTime()/(1000*60*60*24));
	}
	function daysBetween(inTime){
		return dayToDays(now)-dayToDays(inTime);
	}
	