$(document).ready(function(){
	/* 
	 * Initializer Section
	 * */
	storeCommentValue();
	initializeInapp();
	clearJSessionValues();
	initializeDropWarning();

	/* 
	 * Listener Section
	 * */
	$('#drop_icon').click(function(){ showHideDropContent(); return false; });


});

function initializeDropWarning(){
	var stat = "open";

	if (null != $.session('dropStat') && $.session('dropStat') != '--') {
		stat = $.session('dropStat');
	}

	if (stat == 'close') {
		$('#drop_container').slideUp();
		$('#iconUpImg').attr('src',ctx+'/faces/images/icon_down.gif');
	}
}

function showHideDropContent(){
	var image = $('#iconUpImg').attr('src');

	if (image.indexOf('icon_up') != -1) {
		$('#drop_container').slideUp();
		$('#iconUpImg').attr('src',ctx+'/faces/images/icon_down.gif');
		$.session('dropStat','close');
	}else{
		$('#drop_container').slideDown();
		$('#iconUpImg').attr('src',ctx+'/faces/images/icon_up.png');
		$.session('dropStat','open');
	}
}

function clearJSessionValues(){
	$.session('SZoneCommentType','--');
	$.session('SZoneEdValue','--');
}

function storeCommentValue(){
	var comValue = $('input[name="comVal"]:checked');
	if (null != comValue.val()) {
		$.session('SZoneCommentType',comValue.val());
	}else{
		$('#sz_comment').val("");
		$('#sz_comment').attr('disabled','true');
	}

}

function initializeInapp(){
	var inappValue = $('#sz_inapp').attr('checked');

	if (!inappValue) {
		$('#sz_remarks').val("");
		$('#sz_remarks').attr('disabled','true');
	}
}

function setInappValueListener(id){
	var inappValue = $('#'+id).attr('checked');
	if (inappValue) {
		$('#sz_remarks').removeAttr('disabled');
	}else{
		$('#sz_remarks').val("");
		$('#sz_remarks').attr('disabled','true');
	}
}

function setEdValue(){
	var newEdValue = $('input[name="edValue"]:checked');

	if (null != $.session('SZoneEdValue') && "--" != $.session('SZoneEdValue')) {
		var oldEdValue = $.session('SZoneEdValue');

		if (newEdValue.val() == oldEdValue) {
			newEdValue.removeAttr('checked');
			$.session('SZoneEdValue','--');
		}else{
			$.session('SZoneEdValue',newEdValue.val());
			$('#noEd').removeAttr('checked');
		}
	}else{
		$.session('SZoneEdValue',newEdValue.val());
		$('#noEd').removeAttr('checked');
	}
}

function toggleEdValue(checkBox){
	if (checkBox) {
		var edValue = $('input[name="edValue"]:checked');
		edValue.removeAttr('checked');
		$.session('SZoneEdValue','--');
	}
}

function clearCommentType(id){
	var newComValue = $('input[name="comVal"]:checked');

	if (null != $.session('SZoneCommentType') && "--" != $.session('SZoneCommentType')) {
		var oldComValue = $.session('SZoneCommentType');

		if (newComValue.val() == oldComValue) {
			newComValue.removeAttr('checked');
			$.session('SZoneCommentType','--');
			$('#sz_comment').val("");
			$('#sz_comment').attr('disabled','true');
		}else{
			$.session('SZoneCommentType',newComValue.val());
			$('#sz_comment').removeAttr('disabled');
		}
	}else{
		$.session('SZoneCommentType',newComValue.val());
		$('#sz_comment').removeAttr('disabled');
	}
}

