$j(document).ready(function(){
    common.init();
    $j('ul.sf-menu').superfish();
    $j('#valid_form').validate();
    $j('#jvalid_form').validate();
    $j('#jvalid_email_us').validate();
});
var common={
    init:function(){
        $j('.jprint_page').click(function(){
            common.print_page();
            return false;
        });
        $j('.jsave_page').click(function(){
            common.go_saveas();
            return false;
        });
        $j('.jsend_to_friend').submit(function(){
            common.send_to_friend(this);
            return false;
        });
         $j('.jemail_us').submit(function(){
            common.email_us(this);
            return false;
        });
        $j('.subscribe').submit(function()
        {
            common.subscribe(this);
            return false
        });

    },
    print_page:function(){
        window.print();
    },
    go_saveas:function() {
        document.execCommand("SaveAs");
    },
    send_to_friend:function(frm){
        var fromName=frm.fromName.value;
        var fromEmail=frm.fromEmail.value;
        var friendEmail=frm.friendEmail.value;
        var msg=frm.msg.value;
        if(fromName=='' || fromEmail=='' || friendEmail==''){
            return false;
        }
        $j.ajax({
            type:'post',
            url:'index.php?c=AjaxCommonRequest&task=sendToFriend',
            data:{
                fromName:fromName,
                fromEmail:fromEmail,
                friendEmail:friendEmail,
                msg:msg
            },
            success:function(html){
                alert(html);
                tb_remove();
                return true;
            },
            error:function(e,m,s){
               
                tb_remove();
            }
        });
        return false;
    },
    subscribe:function(frm1){
     
        var name1 =frm1.name.value;
        var email1 = frm1.email.value;
     if(name1=='' || email1==''){
            return false;
        }
        $j.ajax({
            type:'post',
            url:'index.php?c=AjaxFrontRequest&task=newsSubScribe',
            data:{
                name:name1,
                email:email1
            },
            success:function(html){
                 frm1.name.value = "";
                    frm1.email.value = "";

                if(html=="Successfull")
                {
                    alert("Successfully Subscribed")
                   
                }
                else
                    alert("Failed!!!Already Exists")
         
                

                return true;
            },
            error:function(e,m,s){
                alert('Already Exists')
             
            }
        }); 
        return false;
    
     
     
    },
    email_us:function(frm){
        var senderName=frm.senderName.value;
        var senderEmail=frm.senderEmail.value;
        var question=frm.question.value;
        var comments=frm.comments.value;
        if(senderName=='' || senderEmail=='' || comments==''){
            return false;
        }
        $j.ajax({
            type:'post',
            url:'index.php?c=AjaxCommonRequest&task=emailUs',
            data:{
                senderName:senderName,
                senderEmail:senderEmail,
                question:question,
                comments:comments
            },
            success:function(html){
                $j('.jemail_us').replaceWith(html);
                setTimeout('tb_remove()',300);
                return true;
            },
            error:function(e,m,s){
                tb_remove();
            }
        });
        return false;
    }
}



