﻿function resetContactForm()
{
    $("#txt_name").attr("value", "");
    $("#txt_email").attr("value", "");
    $("#txt_phone").attr("value", "");
    $('textarea[name="txt_message"]').attr('value', '');
}

function setProductNav(page, product)
{
    if(page == "") page = "1";
    if(product == "") product = "1";
    
    $(".productNav").each(function(i)
    {
        $(this).bind("click", function(e)
        {
            processNav(this.id, "1");
        });
    });
    
    processNavState("pn" + page);
}

function setProducts(page, product)
{
    if(page == "") page = "1";
    if(product == "") product = "1";
    
    $(".product").each(function(i)
    {
        if(this.id == ("pn" + page + "_" + product))
            processProductState(this.id);
    });
}

function processNavState(p)
{
    $(".productNav").each(function(i)
    {
        //alert(this.id);
        if(this.id == p)
        {
            $(this).removeClass("pnOff");
            $(this).addClass("pnOn");
            $("#" + this.id + "_pr").removeClass("start");
        }
        else
        {
            $(this).removeClass("pnOn");
            $(this).addClass("pnOff");
            $("#" + this.id + "_pr").addClass("start");
        }
    });
}

function processProductState(obj)
{
    $("." + obj).toggle();
}

function processNav(p, pr)
{
    if(!($("#" +p).hasClass("pnOn")))
        processNavState(p);
}

function nextSSEle()
{
    $("#ss" + ss).fadeOut("slow", function()
    {
        ss = (ss < (ssT - 1)) ? ss + 1 : 0;
        
        $("#ss" + ss).fadeIn("fast");
    });
}

function dateToAge(time) 
{
   var month = 1000 * 60 * 60 * 24 * 30;
   var week = 1000 * 60 * 60 * 24 * 7;
   var day = 1000 * 60 * 60 * 24;
   var hour = 1000 * 60 * 60;
   var minute = 1000 * 60;
   var second = 1000;
   
   var now = new Date();
   var then = new Date();
   then.setTime(Date.parse(time));

   var diff = now - then;
   var text = "";
   var timeType = "";
   if (diff > month)  {
       text = Math.floor(diff / month);  
       textType = " month";
   }
   else if (diff > week)  {
       text = Math.floor(diff / week);
       textType = " week";
   }
   else if (diff > day)  {
       text = Math.floor(diff / day);
       textType = " day";
   }
   else if (diff > hour)  {
       text = Math.floor(diff / hour);
       textType = " hour";
   }
   else if (diff > minute)  {
       text = Math.floor(diff / minute);
       textType = " minute";
   }
   else  {
       text = Math.floor(diff / second);
       textType = " second";
   }

   text += textType += text == "1" ? "" : "s"; 
   text += " ago";
   
   return text;
}