function change_main_image(v) 
{
    posi = v.src.indexOf('_t_') 
    tail = v.src.lastIndexOf('.')
    url =v.src.substring(0, posi) + '_t300' + v.src.substr(tail)
    url_original = v.src.substring(0, posi) + v.src.substr(tail)
    image = dojo.byId("id_image_0");
    image.src = url;
    dojo.event.connect(image, "onclick", function(){
        window.open(url_original, 'Original_mage', 'width=500, height=500, status=no, resizable=yes, location=no, menubar=no, scrollbars=no, toolbar=no, left=200, top=200');}
        );
}

function displayAction(img_count){
    for(var i=0; i<= img_count; i++){
	var pane_id = "id_pane_" + i;
	var button_id = "id_button_" + i;
	//TODO 
	// comment this line because we cannot set the PopupMenu nicely currently
	// for the following reasons:
	//   1. the PopupMenu is postion=absolute
	//   2. the Button widget is dispalyed with fload=left
	//   3. so when we want to show a button with PopupMenu in the middle of line, it breaks
	// Will fix this later when we've full CSS support for CW2, as we said we should finish functions firstly
	//dojo.event.connect(dojo.byId(pane_id), "onmouseover", dojo.widget.byId(button_id), "show");
    }
}

function hideAction(img_count){
    for(i=0; i<= img_count; i++){
	var pane_id = "id_pane_" + i;
	var button_id = "id_button_" + i;
	//dojo.event.connect(dojo.byId(pane_id), "onmouseout", dojo.widget.byId(button_id), "hide");
    }
}

function initHide(img_count){
    for(i=0; i<= img_count; i++){
	//dojo.widget.byId("id_button_" + i).hide();
    }
}

function doDelete(image_id){
    //var confirm_msg = gettext("You really want to delete this booking?");
    var confirm_msg = "You really want to delete this image?";
    var url_ = "/ajax/image/delete/"+image_id;
    if (!confirm(confirm_msg)) {
	return;
    }

   var bindArgs = {
       mimetype: "text/plain",
       url: url_,
       handle: function(type, data, evt){
	   if(type=='error'){
	       alert("An error occurred when deleting images");
	   }
	   else if(type=='load'){
	       //alert(data);
	       // reload the page to get the change show
	       window.location.reload();
	   }
	   else if(type=='timeout'){
	       alert(data);
	   }
       }
   };
   dojo.io.bind(bindArgs);
}

function doApprove(image_id){
    var url_ = "/ajax/image/approve/"+image_id;
    
    var bindArgs = {
	mimetype: "text/plain",
	url: url_,
	handle: function(type, data, evt){
	    if(type=='error'){
		alert("An error occurred when approving images");
	    }
	    else if(type=='load'){
		//alert(data);
		// reload the page to get the change show
		window.location.reload();
	    }
	    else if(type=='timeout'){
		alert(data);
	    }
	}
    };
    dojo.io.bind(bindArgs);
}

function doMark(image_id){
    var url_ = "/ajax/image/mark-main/"+image_id;
    
    var bindArgs = {
	mimetype: "text/plain",
	url: url_,
	handle: function(type, data, evt){
	    if(type=='error'){
		alert("An error occurred when marking images");
	    }
	    else if(type=='load'){
		//alert(data);
		// reload the page to get the change show
		window.location.reload();
	    }
	    else if(type=='timeout'){
		alert(data);
	    }
	}
    };
    dojo.io.bind(bindArgs);
}

