﻿// 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 InitCustomersSlider()
{

}

function ValidateForm(Subject)
{
    if(!$('#divInputs').length)
        return;

    //validate
    var ErrorMessge = "";
    var valid = true;
    $('#divInputs input').each(function(){
        if($(this).parent().prev().prev().html() != null)
        {
            if($(this).parent().prev().prev().html().indexOf("*") >= 0 && trim($(this).attr('value')) == "")
            {
                ErrorMessge += $(this).parent().prev().html().replace(":","") + ",";
                valid = false;
                //$(this).focus();
            }
        }
    });
    $('#divInputs .validateMail').each(function(){
        if(trim($(this).attr('value')).length > 0 && trim($(this).attr('value')).indexOf('@') < 2)
        {
            ErrorMessge += "Invalid " + $(this).parent().prev().html().replace(":","") + ",";
            valid = false;
            $(this).focus();
        }
    });
    
    if(!valid)
    {
        alert("Requiered fields:" + ErrorMessge);
        return false;
    }
    else
    {
        $('#divInputs textarea').each(function(){
            Query += "General=" + $(this).attr('value') + "&";
        });
        $('#divInputs select').each(function(){
            Query += trim($(this).parent().prev().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).attr('value') + "&";
        });

        var Query = "";
        
        $('#divInputs input:text').each(function(){
            Query += trim($(this).parent().prev().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).attr('value') + "&";
        });
        
        $('#divInputs textarea').each(function(){
            Query += "Description=" + $(this).attr('value') + "&";
        });
        
        $('#divInputs select').each(function(){
            Query += trim($(this).parent().prev().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).attr('value') + "&";
        });
        
        //alert(Query);
        $.get("Send.aspx?Key=12985645&Subject=" + Subject + "&" + "FromMail=" + $('#divInputs .validateMail').attr('value') + "&" + Query, function(data){
            alert(data);
        });
        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 activateLoginFormOnEnter()
{
	var key = event.keyCode;
	if(key == 13)
	{
		document.LoginForm.submit();
	}
}

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 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 + "First Name is Required<br/>";
    
    if(trim(InputLastname) == "")
        Message = Message + "Last Name is Required<br/>";
    
    if(trim(InputEmail) == "")
        Message = Message + "Email is Required<br/>";
    
    if(trim(InputCompany) == "")
        Message = Message + "Company is Required<br/>";
    
    if(trim(InputPhone) == "")
        Message = Message + "Phone 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 + "Zip Code 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);
}

