/**
 * Скрипт для кмопоненты form_comment_post  
 */

/**
 * 
 * @return
 */

var ec = new evercookie();
var cbsf;

$(document).ready(function() {
	restoreAUID();	
	populateInputFromCookie("form_comment_post_unreg_name");
});

function restoreAUID() {
	auid = $.cookie("AUID");
	if(auid == null) {
		val = $.cookie("PHPSESSID");
		$.cookie("AUID", val, { expires: 9999, path: '/' } );
	}
}

function restoreAUIDec() {
	ec.get("AUID", function(value) {
		
		if(value == null || value == 'null') {
			value = $.cookie("PHPSESSID");
			$.cookie("AUID", value, { expires: 9999, path: '/' } );
			ec.set("AUID", value);
		} else {
			$.cookie("AUID", value, { expires: 9999, path: '/' } );
		}
		cbsf();
	});
	
}

function submitPollForm() {
	restoreAUID();
	document.getElementById('form-poll').submit();
/*	cbsf = function submitPoll_cb() {
	    document.getElementById('form-poll').submit();
	}
 
	restoreAUIDec();
*/	
}


function submitCommentForm() {
	saveInputInCookie("form_comment_post_unreg_name");
	
	restoreAUID();
	document.getElementById('form-comment-post').submit();

//	form = document.getElementById('form-comment-post');
/*	
	cbsf = function submitComment_cb() {
	    document.getElementById('form-comment-post').submit();
	}
 
	restoreAUIDec();
	
//	form.submit();
*/
}


function form_comment_post_show_reg_section() {
	document.getElementById("form_comment_post_unreg_section").style.display = "none";
	document.getElementById("form_comment_post_reg_section").style.display = "";
//	document.getElementById("form_comment_post_radio_reg").checked = true;
//	document.getElementById("form_comment_post_radio_unreg").checked = false;
}

function form_comment_post_show_unreg_section() {
	document.getElementById("form_comment_post_reg_section").style.display = "none";
	document.getElementById("form_comment_post_unreg_section").style.display = "";
//	document.getElementById("form_comment_post_radio_reg").checked = false;
//	document.getElementById("form_comment_post_radio_unreg").checked = true;
}

function form_comment_post_new() {
	document.getElementById("form_comment_post_title").innerHTML = "Ваш новый комментарий";
	document.getElementById("form_comment_post_replay_comment_text").innerHTML = "";
	document.getElementById("form_comment_post_comment_pid").value = "";
}

function form_comment_post_replay_to(id) {
	document.getElementById("form_comment_post_comment_pid").value = id;
	document.getElementById("form_comment_post_title").innerHTML = "Ваш ответ на комментарий";
	document.getElementById("form_comment_post_replay_comment_text").innerHTML 
		= document.getElementById("comment_text_"+id).innerHTML;
}

function populateInputFromCookie(input_name) {
	val = $.cookie(input_name);
	if(val != null) {
		$("#"+input_name).attr("value", val);
	}
}

function saveInputInCookie(input_name) {
	val = $("#"+input_name).attr("value");
	if(val != null) {
		$.cookie(input_name, val, { expires: 9999 });
	}
}



