	function encode(str){
		
		if(str.indexOf('\\') != -1)
			str = str.replace(/\\/g, '\\\\');
			
		if(str.indexOf('\'') != -1)
			str = str.replace(/\'/g, '\\\'');

		if(str.indexOf('\"') != -1)
			str = str.replace(/\"/g, '\\\"');

		if(str.indexOf('\n') != -1){
			str = str.replace(/\n/g, '\\\n');
		}
		return str;
	}
	
	function changeSize(){
		size = document.getElementById("size");
		selected = size.selectedIndex;
		newSize = size.options[selected].text.split("x");
		width = newSize[0];
		height = newSize[1];
		img = document.getElementById("main");
		img.style.width = width + "px";
		img.style.height = height + "px";
	}
	
	function changeSpeed(){
		delay = document.getElementById("speed").selectedIndex + 1;
		SLIDES.timeout = delay * 1000;
	}

	function setOrderPlan(order){
		selector = document.getElementById("orderPlan");
		selector.selectedIndex = order;
	}
		
	function changeComment(){
		commentSelector = document.getElementById("commSelector");
		comment = document.getElementById("comment");

		if(commentSelector.selectedIndex == 0)
			comment.style.visibility = "hidden"
		else
			comment.style.visibility = "visible"
	}
	
	function savePick(){
	 	var file = document.getElementById('file').value;
	 	if(file == ''){
	 		alert('please select a file to upload...');
	 		return;
	 	}
	 	var index2 = file.lastIndexOf('.');
	 	var index1 = file.lastIndexOf('\\');
	 	
		
	 	var fileName = file.substring(index1+1, index2);
 		document.getElementById('fileName').value = fileName;
	 	document.getElementById('uploader').submit();
	}
		 	
	function uploader(imgpath){
	alert('second');
		var preview = document.getElementById('file').value;
		var index1 = preview.lastIndexOf(".");
		var index2 = preview.lastIndexOf("\\");
		var fileName = imgpath.substring(index2 + 1, index1);
		document.getElementById('fileName').value = fileName;
	}
	
	function doSubmit(action){
		var form =  document.getElementById('actions');
		var todoAction = document.getElementById('toDoAction');
		todoAction.value = action;
		form.submit();
	}
	
	function addPhoto(action){
		var form =  document.getElementById('actions');
		form.action = 'uploadphoto.jsp';
		var todoAction = document.getElementById('toDoAction');
		todoAction.value = action;
		form.submit();
	}
	
//	AJAX FUNCTIONS	

	function getAlbum(albumOrder) {
			var url = 'gallerycontroller';
			var params = 'albumorder=' + albumOrder;
			var ajax = new Ajax.Updater(
				{success: 'urlIncrement'},
				url,
				{
					method: 'post',
					parameters: params,
					onFailure: reportError
				}
			);
		}
	
	function displayPhoto(albumorder, photoposition){
		$('actions').action = 'displayphoto.jsp';
		$('albumorder').value = albumorder;
		$('position').value = photoposition;
		$('actions').submit();
	}
	
	function viewAlbums(albumorder, action){
		$('actions').action  = action;
		$('albumorder').value = albumorder;
		$('actions').submit();
	}
	
	function previewImage(path){
		var test = document.getElementById('test');
		var imgName = document.getElementById('imgName');
		imgName.value = path.substr(path.lastIndexOf('/'), path.lastIndexOf('.' ));
		path = path.replace("%5C", "/");
//		path = unescape(path);
//		test.innerHTML = "<img src=" + "\"file://" + path + "\" />";
		
		var elem = document.getElementById("tak");
		elem.src = ""  ;
		alert(elem.src);

	}

	function changePhoto(objectId,image){
			objectId.style.backgroundImage = image;
		}

	function reportError(request) {
			alert('Error : website hasnt added');
			$('error-area') = "Error";
	}
		
	function showDiv(divName){
		var div=document.getElementById(divName);
		if (div.style.display=="none"){
			div.style.display="block";
		}else{
			div.style.display="none";
		}
	}

	function Photo(id, name, url, thumbUrl, position, creationDate, comment, msg ){
		this.id = id;
		this.name = name
		this.creationDate = creationDate;
		this.comment = comment;
		this.position = position;
		this.url = url;
		this.thumbUrl = thumbUrl;
		this.msg = msg;
	}
	// upload page