/**
 * KMP 2009 Frontend Categories Tools
*/
//*******************Subscribe Category******************************************
function subscribeToRubric(catId) {
    var content = '<div class="popup-data-holder"><form action='+base_href+'/subscribeRubric/'+catId+' name="categoryTools" id="categoryTools" method="post">'+
                    '<table class="act-mail"><tr><td>'+
                    '<span>'+i18n.lbl_email+'</span>'+
                        '<input type="text" id="email_category" name="rub_subscribe[email]" style="width:200px;"/>'+
                        '<input type="hidden" id="link" name="link" value=""/>'+ 
                    '</td></tr></table>';
                    
    content +=  '<div><input type="checkbox" id="rub_subscribe[mode][articleAdd]" name="rub_subscribe[mode][articleAdd]" checked="checked" value="Y" /><span>'+i18n.lbl_subscribe_add_article+'</span></div>'+
			'<div><input type="checkbox" id="rub_subscribe[mode][articleEdit]" name="rub_subscribe[mode][articleEdit]" checked="checked" value="Y" /><span>'+i18n.lbl_subscribe_edit_article+'</span></div>'+
			'<div><input type="checkbox" id="rub_subscribe[mode][articleComment]" name="rub_subscribe[mode][articleComment]" checked="checked" value="Y" /><span>'+i18n.lbl_subscribe_add_comment+'</span></div></form>';
      // button              
    content += '<table class="form-btn-1">'+
                      '<tbody>'+
                        '<tr>'+
                          '<td class="form-btn-l"><div></div></td>'+
                          '<td class="form-btn-c">'+
                              '<input type="button" value="'+i18n.lbl_subscribe+'" name="submit" onclick = "javascript:subscribe();" class="form-button"/>'+
                          '</td>'+
                          '<td class="form-btn-r"><div></div></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table>';
    
     content +=	'<table class="form-btn-1">'+
                      '<tbody>'+
                        '<tr>'+
                          '<td class="form-btn-l"><div></div></td>'+
                          '<td class="form-btn-c">'+
                              '<input type="button" value="'+i18n.lbl_cancel+'" name="submit" onclick = "javascript:cancel();" class="form-button"/>'+
                          '</td>'+
                          '<td class="form-btn-r"><div></div></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table></div>';
    
    var title = i18n.lbl_subscribe_to_category;                
    showDialog(content, title);
    document.getElementById('link').value = window.location.href;
    document.getElementById('email_category').value = email;
}
//****************Delete Category***********************************************
function deleteCategory(catId) {
    var content = '<div class="form-1 popup-data-holder mail-to-friend"><form action="'+base_href+'deleteCategory" name="deleteCategory" id="deleteCategory" method="post">'+
                    '<span>'+i18n.msg_delete_message+'</span>'+
                    '<input type="hidden" id="catId" name="catId" value="'+catId+'" />'+ 
                    '</form>';
      // button              
    content += '<table class="form-btn-1">'+
                      '<tbody>'+
                        '<tr>'+
                          '<td class="form-btn-l"><div></div></td>'+
                          '<td class="form-btn-c">'+
                              '<input type="button" value="'+i18n.lbl_delete+'" name="submit" onclick = "javascript:deleteCat();"class="form-button"/>'+
                          '</td>'+
                          '<td class="form-btn-r"><div></div></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table>';
    
    content +=	'<table class="form-btn-1">'+
                      '<tbody>'+
                        '<tr>'+
                          '<td class="form-btn-l"><div></div></td>'+
                          '<td class="form-btn-c">'+
                              '<input type="button" value="'+i18n.lbl_cancel+'" name="submit" onclick = "javascript:cancel();" class="form-button"/>'+
                          '</td>'+
                          '<td class="form-btn-r"><div></div></td>'+
                        '</tr>'+
                      '</tbody>'+
                    '</table>';
					
	content +="</div>";
    
    var title = i18n.msg_confirm_mes;                
    showDialog(content, title);
    
    
}
//**********delete****************************************************
function deleteCat() {
    document.getElementById('deleteCategory').submit();
    return true;   
}
//****************Dialog********************************************************
function showDialog(content, title){
    window.layer = new Layer({
        alignEl: 'tool-button-2',
        alignment: 'bottom',
        title: title,
        content: content,
        visible: true
    });
}
//******************************************************************************
function cancel(){
    window.layer.close();   
}
//**********subscribe****************************************************
function subscribe(){
    var email = document.getElementById('email_category').value;
    var message = i18n.msg_invalid_email;
    if (checkEmail(email)) {
        document.getElementById('categoryTools').submit();
        return true;
    } else {
        alert(message);
        return false;
    }
}
//**********email validation****************************************************
function checkEmail(email){
    var pattern = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i;    
    var valid = email.match(pattern);
    if (valid != null) return true
    return false   
}

