$j('document').ready(function(){    
    $j('#video_tab').click(function(){
        gallery_tab.video()
    });
    $j('#photo_tab').click(function(){
        gallery_tab.photo()
    });
    $j('#news_back_button').click(function(){
        $j('.news_success_msg').hide('fast',$j('.news_request').show("fast"));
    });
});

function empty_qty(id)
{
    var qtyvalue=$j('#qty'+id).val();
    if(qtyvalue=='0')
        $j('#qty'+id).val('');
}
function reset_qty(id)
{
    var qtyvalue=$j('#qty'+id).val();
    if(qtyvalue==''){
        $j('#qty'+id).val('0');
    }
    else{
        $j('#qty'+id).val(qtyvalue);
    }
}
function empty_email_text()
{
    var emailvalue=$j('#email').val();
    if(emailvalue=='Enter Your Email Address')
        $j('#email').val('');
}
function reset_email_text()
{
    var emailvalue=$j('#email').val();
    if(emailvalue==''){
        $j('#email').val('Enter Your Email Address');
    }
    else{
        $j('#email').val(emailvalue);
    }
}
function count_top(count)
{
    var qtyvalue=parseInt($j('#qty'+count).val())+1;
    $j('#qty'+count).val(qtyvalue);
}
function count_bottom(count)
{
    var qtyvalue=parseInt($j('#qty'+count).val())-1;
    if(qtyvalue<0){
        alert('A Rquired Field is Negative');
        $j('#qty'+count).val(0);
    }else{
        $j('#qty'+count).val(qtyvalue);
    }
     
}
function getNewsLetter()
{
    var email=$j("#email").val();
    validator.setAlert(true);
    if(!validator.isEmail(email)){
        return false;
    }
    $j.ajax({
        type: "POST",
        url: base_url+"home/news_letter",
        data: {
            email: email
        },
        success: function(html){
            alert(html);
        }
    });
    return false;
}
function sendSellRequest(frm){
    validator.setAlert(true);

    if(validator.isNull(frm.first_name.value)){
        frm.first_name.focus();
        return false;
    }
    if(validator.isNull(frm.last_name.value))
    {
        frm.last_name.focus();
        return false;
    }
    if(validator.isNull(frm.company_name.value)){
        frm.company_name.focus();
        return false;
    }
    if(validator.isNull(frm.website.value))
    {
        frm.website.focus();
        return false;
    }
    if(!validator.isEmail(frm.email.value)){
        frm.email.focus();
        return false;
    }
    if(validator.isNull(frm.phone.value))
    {
        frm.phone.focus();
        return false;
    }
    if(validator.isNull(frm.city.value))
    {
        frm.city.focus();
        return false;
    }

    if(validator.isNull(frm.country.value)){
        frm.country.focus();
        return false;
    }
    if(validator.isNull(frm.company_des.value))
    {
        frm.company_des.focus();
        return false;
    }
    if(validator.isNull(frm.like_us.value))
    {
        frm.like_us.focus();
        return false;
    }
    $j("#loading_message").css({
        'background':'url('+base_url+'images/loading.gif) no-repeat',
        'width':'32px',
        'height':'32px'
    });
    $j("#loading_message").show("fast");
    $j.ajax({
        url: base_url+"product_sell/send_sell_request",
        type: "POST",
        data:{
            first_name:frm.first_name.value,
            last_name:frm.last_name.value,
            company_name:frm.company_name.value,
            website:frm.website.value,
            email:frm.email.value,
            phone:frm.phone.value,
            city:frm.city.value,
            country:frm.country.value,
            state:frm.state.value,
            company_des:frm.company_des.value,
            like_us:frm.like_us.value
        },
        success: function(html){
            $j(".success_msg").html(html);
            $j("#loading_message").hide("fast");
        }
    });
    
    return false;
}
function sendPriceQuoteRequest(frm){
    var first_name=frm.first_name.value;
    var last_name=frm.last_name.value;
    var company_name=frm.company_name.value;
    var phone_1=frm.phone_1.value;
    var phone_2=frm.phone_2.value;
    var email=frm.email.value;
    var city=frm.city.value;
    var des=frm.des.value;
    var country=frm.country.value;

    validator.setAlert(true);
    if(validator.isNull(first_name)){
        frm.first_name.focus();
        return false;
    }
    if(validator.isNull(last_name))
    {
        frm.last_name.focus();
        return false;
    }
    if(validator.isNull(company_name)){
        frm.company_name.focus();
        return false;
    }
    if(validator.isNull(phone_1))
    {
        frm.phone_1.focus();
        return false;
    }
    if(validator.isNull(phone_2))
    {
        frm.phone_2.focus();
        return false;
    }
    if(!validator.isEmail(email)){
        frm.email.focus();
        return false;
    }
    if(validator.isNull(city))
    {
        frm.city.focus();
        return false;
    }
    if(validator.isNull(country)){
        frm.country.focus();
        return false;
    }
    if(validator.isNull(des))
    {
        frm.des.focus();
        return false;
    }
    $j("#loading_message").css({
        'background':'url('+base_url+'images/loading.gif) no-repeat',
        'width':'32px',
        'height':'32px'
    });
    $j("#loading_message").show("fast");
    $j.ajax({
        url: base_url+"price_quote/price_quote_request",
        type: "POST",
        data:{
            first_name:first_name,
            last_name:last_name,
            company_name:company_name,
            phone_1:phone_1,
            phone_2:phone_2,
            email:email,
            city:city,
            country:country,
            des:des
        },
        success: function(html){
            $j(".success_msg").html(html);
            $j("#loading_message").hide("fast");
        }
    });
    return false;
}

function addForOrder(count)
{
    var product_id=$j("#product"+count).val();
    var qty=$j("#qty"+count).val();
    
    validator.setAlert(true);
    if(validator.isNull(qty)){
        $j("#qty"+count).select();
        return false;
    }
    if(qty==0){
        alert("A Rquired Field is Null");
        $j("#qty"+count).select();
        return false;
    }
    $j("#message_"+count).css({
        'background':'url('+base_url+'images/loading.gif) no-repeat'
    });
    $j("#message_"+count).show("fast");

    $j.ajax({
        url:base_url+"product_catalog/order_form",
        type:"POST",
        data:{
            product_id:product_id,
            qty:qty
        },
        success: function(html){
            $j('#cart_value').text(html);
            $j("#message_"+count).html("Product Added!");
            $j("#message_"+count).fadeOut("slow");
        }
    });
    return false;
}
function addForWholesaleOrder(count)
{
    var product_id=$j("#product"+count).val();
    var qty=$j("#qty"+count).val();

    validator.setAlert(true);
    if(validator.isNull(qty)){
        $j("#qty"+count).select();
        return false;
    }
    if(qty==0){
        alert("A Rquired Field is Null");
        $j("#qty"+count).select();
        return false;
    }
    $j("#message_"+count).css({
        'background':'url('+base_url+'images/loading.gif) no-repeat'
    });
    $j("#message_"+count).show("fast");

    $j.ajax({
        url:base_url+"product_catalog/wholesale_order",
        type:"POST",
        data:{
            product_id:product_id,
            qty:qty
        },
        success: function(html){            
            $j('#cart_value').text(html);
            $j("#message_"+count).html("Product Added!");
            $j("#message_"+count).fadeOut("slow");
        }
    });
    return false;
}
function remove_from_cart(product_id,count)
{   
    $j(".loading"+count).css({
        'background':'url('+base_url+'images/loading.gif) no-repeat'
    });
    $j(".loading"+count).show("fast");
    $j.ajax({
        url: base_url+"product_catalog/delete_from_cart",
        type: "POST",
        data: {
            product_id:product_id
        },
        success: function(html){
            $j('#view_all_order').replaceWith(html);
            $j.get(base_url+"product_catalog/view_cart", function(data){
               $j('#cart_value').text(data);
            });
        },
        error:function(msg,error,status)
        {
            alert(msg+" "+error);
        }
    });
        
    return false;
}
function remove_from_wholesalecart(product_id,count)
{
    $j(".loading"+count).css({
        'background':'url('+base_url+'images/loading.gif) no-repeat'
    });
    $j(".loading"+count).show("fast");
    $j.ajax({
        url: base_url+"product_catalog/delete_from_wholesalecart",
        type: "POST",
        data: {
            product_id:product_id
        },
        success: function(html){
            $j.get(base_url+"product_catalog/whole_view_cart", function(data){
                    $j('#cart_value').text(data);
                });
            $j('#view_all_order').replaceWith(html);
        },
        error:function(msg,error,status)
        {
            alert(msg+" "+error);
        }
    });
    return false;
}
function sendContact(frm){
    for(var i=0;i<frm.feedback_regarding.length;i++){
        if(frm.feedback_regarding[i].checked){
            var feedback_regarding=frm.feedback_regarding[i].value;
        }
    }

    for(var j=0;j<frm.feedback_type.length;j++){
        if(frm.feedback_type[j].checked){
            var feedback_type=frm.feedback_type[j].value;
        }
    }

    $j('#contact_us_loading').css("display","block");
    $j.ajax({
        url: base_url+"contact/part2",
        type: "POST",
        data:{
            feedback_regarding:feedback_regarding,
            feedback_type:feedback_type
        },
        success: function(html){
            $j("#contact_form").html(html);
        }
    });
    return false;
}

function sendContactPart2(frm){
    validator.setAlert(true);
    if(validator.isNull(frm.msg.value)){
        frm.msg.focus();
        return false;
    }

    if(validator.isNull(frm.first_name.value)){
        frm.first_name.focus();
        return false;
    }

    if(validator.isNull(frm.last_name.value)){
        frm.last_name.focus();
        return false;
    }

    if(validator.isNull(frm.address_1.value)){
        frm.address_1.focus();
        return false;
    }

    if(validator.isNull(frm.city.value)){
        frm.city.focus();
        return false;
    }

    if(validator.isNull(frm.zip.value)){
        frm.zip.focus();
        return false;
    }

    if(!validator.isEmail(frm.email.value)){
        frm.email.select();
        return false;
    }

    for(var i=0;i<frm.title.length;i++){
        if(frm.title[i].checked){
            var title=frm.title[i].value;
        }
    }

    $j('#contact_us_loading').css("display","block");
    $j.ajax({
        url: base_url+"contact/part3",
        type: "POST",
        data:{
            msg:frm.msg.value,
            title:title,
            first_name:frm.first_name.value,
            last_name:frm.last_name.value,
            address_1:frm.address_1.value,
            address_2:frm.address_2.value,
            city:frm.city.value,
            state:frm.state.value,
            zip:frm.zip.value,
            country:frm.country.value,
            email:frm.email.value,
            phone:frm.phone.value
        },
        success: function(html){
            $j("#contact_form").html(html);
        }
    });
    return false;
}

function goContactPageBack(){
    $j("#contact_form").load(base_url+"contact/part1");
}


function loadVideo(video_id){
    $j('#video_player').html("<h2>Loading...</h2>");    
    $j('#video_info').html($j('#vid_'+video_id).html());
    $j('#video_player').load(base_url+'gallery/loadPlayer',{
        video_id:video_id
    })
}

var gallery_tab={
    video:function(){
        this.reset_tab();
        $j('#video_tab').addClass("sel");
        $j('#video_pan').css("display","block");

    },
    photo:function(){
        this.reset_tab();
        $j('#photo_tab').addClass("sel");
        $j('#photo_pan').css("display","block");
    },
    reset_tab:function(){        
        $j('#video_tab').removeClass("sel");
        $j('#photo_tab').removeClass("sel");
        $j('#video_pan').css("display","none");
        $j('#photo_pan').css("display","none");
    }
}
var calendar_page={
    full_calendar:function(){
        $j('#calendar_loading').css("display","block");
        $j('#static_middle_section_left').load(base_url+"calendar/full_calendar");
    },
    by_day:function(){
        $j('#calendar_loading').css("display","block");
        $j('#static_middle_section_left').load(base_url+"calendar/by_day");
    },
    by_category:function(){
        $j('#calendar_loading').css("display","block");
        $j('#static_middle_section_left').load(base_url+"calendar/by_category");
    }
}