function toViewMode(divId){
$('<div name="flag"></div>').css("font-weight","bold").insertAfter($(":text,select", $("#"+divId)));
saveToViewMode(divId);
}
function saveToViewMode(divId){
$(":text", $("#"+divId)).each(
function(index){
$(this).hide();
$(this).siblings().hide();
$(this).siblings("[name='flag']").text($(this).val()).show();
}
);
$("select", $("#"+divId)).each(
function(index){
$(this).hide();
$(this).siblings().hide();
$(this).siblings("[name='flag']").text($("option[value='"+$(this).val()+"']", $(this)).text()).show();
}
);
$("[name='hideFlag']").hide();
}
$('#saveProductForm').ajaxForm(function() { });
$("#saveProductForm").validate();
function saveProduct(){
var cptyArray = new Array();
$("tbody>tr", $("#counterPartyTable")).each(
function(index){
var cpty = new Object();
var counterPartyId = $("td:eq(0)", $(this)).text().trim();
if(counterPartyId!=""){
cpty.cptyId = counterPartyId;
cpty.bestPrice = $(":checkbox[name='BEST_PRICE']", $(this)).val();
cpty.ibPrice = $(":input[name='ibPrice']", $(this)).val().trim();
cpty.status = $("TD[name='cptyStatusTD']", $(this)).text().trim();
cptyArray.push(cpty);
}
}
);
reqCounterparty = $.toJSON(cptyArray);
$("#saveProductForm").ajaxSubmit(
{
type:"post",
url:"<%=strUrl%>?actionMethod=saveProductAttrs&missingAttr="+missingAttr+"&underlyings="+underlyings+"&beUnderlyings="+beUnderlyings+"&buUnderlyings="+buUnderlyings+"&reqCounterparty="+reqCounterparty,
dataType:"json",
beforeSubmit:
function(formData,jqForm,options){
var ret = $("#saveProductForm").valid();
if (ret == false) {
alert("Please fill the form elements correctly!");
return false;
}
return true;
},
success:
function(data){
if(data.success=="NO"){
alert(data.message);
return false;
}
}
}
);
}
function toChangeMode(){
$("div[name='flag']").each(
function(index){
$(this).hide();
$(this).siblings().show();
}
);
$("[name='hideFlag']").show();
$(":checkbox").each(
function(){
$(this).removeAttr("disabled");
}
);
}