﻿// JScript File
function initMenu(openIndex) {
 return;
        $('#VMenu ul:not(.current)').hide();
        
        //$('#VMenu ul:first').show();
         
        $('#VMenu li a').click(
         
        function() {
            var checkElement = $(this).next();
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                $('#VMenu ul:visible').slideUp('normal');
                return false;
                }
         
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#VMenu ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
            return false;
            }
        }
    );
}

function InitTopMenu()
{
    $(document).ready(function(){   
  
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)   
  
    $("ul.topnav li span").click(function() { //When trigger is clicked...   
  
        //Following events are applied to the subnav itself (moving subnav up and down)   
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click   
  
        $(this).parent().hover(function() {   
        }, function(){   
            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up   
        });   
  
        //Following events are applied to the trigger (Hover events for the trigger)   
        }).hover(function() {   
            $(this).addClass("subhover"); //On hover over, add class "subhover"   
        }, function(){  //On Hover Out   
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"   
    });   
  
});  

}

function ValidateAskUs(form) {
var valid = true;
var msg; 

    if(form.txtName.value=="" && valid){
        msg="* Required field";
        form.txtName.focus();       
        valid=false;
    }    
    if((form.txtEmail.value=="" || !isValidEmail(form.txtEmail.value)) && valid){
        document.getElementById("msg").innerHTML='Invalid email address.';
        return false;
    }
//    if(form.txtPhone.value.trim()=="" && valid){
//        msg="* Required field";
//        form.txtPhone.focus();       
//        valid=false;
//    }    
    if(form.txtQ.value =="" && valid){
        msg="* Required field";
        form.txtQ.focus();       
        valid=false;
    }    
    if(valid){
        $.post('send.aspx?type=askus', {txtName : form.txtName.value, txtEmail : form.txtEmail.value, txtQ : form.txtQ.value, txtPhone : form.txtPhone.value}, function(){
            alert("Thank you for submitting your question, we will address it soon.");
            $('#divQPopUp *').val('');
            $('#divQPopUp').slideUp('normal');
        });
//        form.action = "send.aspx?type=askus";
//        form.submit();
//        location.href=location.href;
    }
    else{
        document.getElementById("msgAskus").innerHTML=msg;
    }

}

function isValidEmail(str) 
{
   return !(typeof(str) == 'undefined' || str == null) && ((str.indexOf(".") > 2) && (str.indexOf("@") > 0));
}

function ValidateForm(Subject, download)
{
    if(!$('#FormContainer').length)
        return;

    //validate
    var ErrorMessge = "";
    var valid = true;
    $('#FormContainer .must').each(function(){
    if(trim($(this).attr('value')) == "")
    {
        ErrorMessge += $(this).attr("title") + ",";
        valid = false;
        $(this).focus();
    }
    });
    $('#FormContainer .validateMail').each(function(){
        if(trim($(this).attr('value')).length > 0 && trim($(this).attr('value')).indexOf('@') < 2)
        {
            ErrorMessge += "Invalid " + $(this).attr("title") + ",";
            valid = false;
            $(this).focus();
        }
    });
    
    if(!valid)
    {
        alert("Requiered fields:" + ErrorMessge.substr(0,ErrorMessge.length -1));
        return false;
    }
    else
    {
    
        var Query = "";
        
        $('#FormContainer input:text').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });

	    $('#FormContainer input:checkbox').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });
                
        $('#FormContainer textarea').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });
        
        $('#FormContainer select').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });
        
            $.get("Send.aspx?Key=12985645&download=" + ((typeof(download) != "undefined" && download == true) ? "1" : "0") + "&Subject=" + Subject + "&FromMail=" + $('#FormContainer .validateMail').attr('value') + "&"+ "&FromName=" + $('#FormContainer .name').attr('value') + "&" + Query, function(data){
                    if(typeof(download) != "undefined" && download == true)
                        location.href = 'DownloadThankYou.html';
                    else
                        alert(data);
                    clearForm();
            });
        
        return true;
    }
}

function replaceSpace(str)
{
    while(str.indexOf(" ") > 0)
        str = str.replace(" ","_");
    return str;
}

function SearchKeyword()
{
    var searchKeyword = trim($('#txtSearch').attr('value'));
    if(searchKeyword != "")
        location.href = 'search_' + searchKeyword + '.html';
}

function Search() 
{
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) 
    {
        document.getElementById('SearchButton').click();
        return false;
    }
    return true;
}

function trim(strText) 
{    
while('' + strText.charAt(0) == ' ') 
{        strText = strText.substring(1, strText.length);    }    
while('' + strText.charAt(strText.length-1)==' ') {        
strText = strText.substring(0, strText.length-1);    }   
return strText;
}


function InitGallery()
{
    if($(".smallToLarge").length > 0)
    {
        $(".smallToLarge").attr("rel","prettyPhoto[gallery1]");
        $(".smallToLarge[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
    }
}

function InitOpenMore()
{
    if($('.aMore').length <= 0)
        return;
        
    $('.aMore').each(function(){
        $(this).click(function(){
            if($(this).html() == "More ...")
                $(this).html("Less ...");
            else
                $(this).html("More ...");
                
            $(this).closest('table').find('.OpenTD:visible').fadeOut("normal");
            $(this).closest('table').find('.OpenTD:hidden').fadeIn("normal");
            return false;
        });
    });
}

function Register()
{
    var Message = "";

    var InputName = $('#InputName').attr('value');
    var InputFax = $('#InputFax').attr('value');
    var InputLastname = $('#InputLastname').attr('value');
    var InputWebsite = $('#InputWebsite').attr('value');
    var InputTitle = $('#InputTitle').attr('value');
    var InputAddress = $('#InputAddress').attr('value');
    var InputCity = $('#InputCity').attr('value');
    var InputCompany = $('#InputCompany').attr('value');
    var InputEmail = $('#InputEmail').attr('value');
    var InputPhone = $('#InputPhone').attr('value');
    var InputZipCode = $('#InputZipCode').attr('value');
    var DDlCountry = $('#DDlCountry').attr('value');
    var DDlState = $('#DDlState').attr('value');
    var DDlIndustry = $('#DDlIndustry').attr('value');
    var chkRecieveInfo = $('#chkRecieveInfo').attr('checked');
    
    if(trim(InputName) == "")
        Message = Message + "<span class='red'>First Name</span> is Required<br/>";
    
    if(trim(InputLastname) == "")
        Message = Message + "<span class='red'>Last Name</span> is Required<br/>";
    
    if(trim(InputEmail) == "")
        Message = Message + "<span class='red'>Email</span> is Required<br/>";
    
    if(trim(InputCompany) == "")
        Message = Message + "<span class='red'>Company</span> is Required<br/>";
    
    if(trim(InputPhone) == "")
        Message = Message + "<span class='red'>Phone</span> is Required<br/>";
    
//    if(trim(DDlCountry) == "")
//    {
//        Message = Message + "Country is Required<br/>";
//    }
//    else
//    {
//        if(trim(DDlState) == "")
//        Message = Message + "State is Required<br/>";
//    }
//    
//    if(trim(DDlIndustry) == "")
//        Message = Message + "Industry is Required<br/>";
//    
    if(trim(InputZipCode) == "")
        Message = Message + "<span class='red'>Zip Code</span> is Required<br/>";
    if(Message != "")
    {
        $('#divMessage').html(Message);
    }
    else
    {
        $.post('Register.aspx',{InputName : InputName, InputFax : InputFax, InputLastname : InputLastname, InputWebsite : InputWebsite, 
        InputTitle : InputTitle, InputAddress : InputAddress, InputCompany : InputCompany, InputEmail : InputEmail, DDlCountry : DDlCountry, 
        InputPhone : InputPhone, DDlIndustry : DDlIndustry, InputCity : InputCity, DDlState : DDlState, chkRecieveInfo : chkRecieveInfo},
        
        function(data){
            $('#divMessage').html(data);
            //location.href = 'userArea.html';
        });
    }
}

function openWindow(theURL,winName,features) { 
    if(features=="")
        features = "scrollbars=0, menubars=0, toolbars=0, location=0, directories=0, status=0, width=330, height=150, top=200, left=300, resizable=0";    
  
    window.open(theURL,winName,features);
}

function Login()
{
    var User = $('#InputEmail').attr('value');
    var Password = $('#InputPassword').attr('value');
    var chkRemember = $('#chkRemember').attr('checked');
    if(trim(User) == "" || trim(Password) == "")
    {
        $('#divMsg').html('Please type email and password');
        return;
    }
    
    $.post('Module_CheckLogin.aspx', {email : User, password : Password, remember : chkRemember}, function(data){
    if(data.length > 0)
    {
          location.href = 'userArea.html';  
    }
    else
    {
        $('#divMsg').html('Invalid user information');
    }
    });
}

function clearForm()
{
    $('#FormContainer textarea').attr('value','');
    $('#FormContainer input').attr('value','');
    $('#FormContainer input').attr('checked',false);
}