﻿// JScript File

function changeImg(objId,img)
{
    window.document.getElementById(objId).src="InnerData/images/" + img;
}

function initMenu(openIndex) {
 
        $('#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 InitManagment()
{
    if(!$('.TBLmanagment').length > 0)
        return;
        
    $('.managementItems tr td').hide();       
    $('.managementLinks a').each(function(){
        $(this).click(function(){
            $('.managementItems tr td').hide();
            $('.managementItems tr:eq(' + $('.managementLinks a').index(this) +') td').fadeIn("normal");
            return false;
        });
    });

}

function InitFAQ()
{
    if(!$('.faqItem').length > 0)
        return;
        
    $('.faqItem').css("cursor","pointer");
    
    $('.faqItem').each(function(){
        $(this).find('tr:eq(1) td').hide();
        $(this).click(function(){
        if($(this).find('tr:eq(1) td').css("display") == "none")
        {
            $('.faqItem').each(function(){
            $(this).find('tr:eq(1) td').hide();
        });

            $(this).find('tr:eq(1) td').show();
        }
        else
            $(this).find('tr:eq(1) td').hide();    
    });
    });
}

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 ValidateForm(Subject,reg)
{
    if(!$('#divInputs').length)
        return;

    //validate
    var ErrorMessge = "";
    var valid = true;
    $('#divInputs .must').each(function(){
    if(trim($(this).attr('value')) == "")
    {
        ErrorMessge += $(this).attr("title") + ",";
        valid = false;
        $(this).focus();
    }
    });
    $('#divInputs .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 = "";
        
        $('#divInputs input:text').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });

	    $('#divInputs input:checkbox').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });
                
        $('#divInputs textarea').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });
        
        $('#divInputs select').each(function(){
            Query += replaceSpace(trim($(this).attr('title'))) + "=" + $(this).attr('value') + "&";
        });
        
        $.get("Send.aspx?Key=12985645" + ((typeof(reg) != "undefined" && reg == true) ? "&Reg=1" : "") + "&Subject=" + Subject + "&" + "FromMail=" + $('#divInputs .validateMail').attr('value') + "&" + Query, function(data){
            alert(data);
            if(reg)
                location.href = 'ResourceCenter.html';
            else
                location.href = '/';
        });
        return true;
    }
}

function replaceSpace(str)
{
    while(str.indexOf(" ") > 0)
        str = str.replace(" ","_");
    return str;
}

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)
    {
          $('#divLogIn').hide();  
    }
    else
    {
        $('#divMsg').html('Invalid user information');
    }
    });
}

function InitLogin()
{
    if($('#divLogIn').length)
    {
        if($.cookie("GoNetUser") != '1')
            $('#divLogIn').show();
    }
}

function InitGallery()
{
    if($(".zoom").length > 0)
    {
        $(".zoom").attr("rel","prettyPhoto[gallery1]");
        $(".zoom[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
    }
}

function InitNewsTicker()
{
    if(!$("#NewsTicker").length > 0)
        return;
    
    $("#NewsTicker .NewsTickerItem").hide();
    $("#NewsTicker .NewsTickerItem:eq(0)").show();
        
    if($("#NewsTicker .NewsTickerItem:eq(1)").length > 0)
        setTimeout('ShowNextItem()',5000);
}

function ShowNextItem()
{
//    $("#NewsTicker .NewsTickerItem").hide();
    if($("#NewsTicker .NewsTickerItem:visible").next().length > 0)
	$("#NewsTicker .NewsTickerItem:visible").hide().next().fadeIn(1000)
    else
{
	$("#NewsTicker .NewsTickerItem:visible").hide();
        $("#NewsTicker .NewsTickerItem:eq(0)").fadeIn(1000);
}    
    setTimeout('ShowNextItem()',5000);
}

function SignNewsletter(email)
{
    if(trim(email).length > 5 && trim(email).indexOf('@') > 2)
    {
        $.get('SignNewsletter.aspx', {Email : email, Password : '1gonet2n'}, 
    function(data){
        alert(data);
    });
    }
    else
        alert("Email address is invalid");
}

