$(document).ready( function(){

	//hide the brand list to start
	$(".blue_header > ul").hide();

	//hide or show brand depending upon ul state
	$(".blue_header > a").click(function(){		
		var theul = $(this).parent().find('ul');
		if($(theul).css('display') == 'none'){
			$(theul).slideDown();
		}else{
			$(theul).slideUp();
		}
	});

	$("#home_promo_box").innerfade({
		speed	: 'slow',
		timeout	: 4000,
		type	: 'sequence',
		containerheight: '165px'
	});
});

// popup Call back form links
$(document).ready(function(){
    $('#cb1-link').click(function(){
            $(this).hide();
            $('#cb1-link-tab').show();
            $('#cb1-popup').toggle();
            return false;
        }
    );

    $('#cb1-link-tab').click(function(){
        $(this).hide();
        $('#cb1-link').show();
        $('#cb1-popup').toggle();
        return false;
    });
    
});

// call back form validation
function validate_cb1form(frm) {
    var errorString = '';
    var cb1Name = frm.cb1Name.value;
    var cb1Tel = frm.cb1Tel.value;
    var cb1Message = frm.cb1Message.value;

    if (cb1Name == '' || cb1Name == 'Name') {
        errorString += 'Please enter your Name.'+"\n";
    }

    if (cb1Tel == '' || cb1Tel == 'Contact Number') {
        errorString += 'Please enter your contact number.'+"\n";
    }

    if (cb1Message == '' || cb1Message == 'Message') {
        errorString += 'Please enter your message.'+"\n";
    }
    
    if (0 < errorString.length) {
        alert('The following error(s) occured;' + "\n" + errorString);
    } else {
        cb1form_submit();
    }
    return false;
}

function cb1form_submit() {
    $('#cb1form .result').hide();
    var data = $('#cb1form').serialize();
    $.post('/secure/callBack.php', data, function(data) {
        $('.result').html(data);
        $('#cb1form .result').show();
    });
}

function validate_cb2form(frm) {
    var errorString = '';
    var cbName = frm.cb2Name.value;
    var cbTel = frm.cb2Tel.value;
    var cbMessage = frm.cb2Message.value;

    if (cbName == '' || cbName == 'Name') {
        errorString += 'Please enter your Name.'+"\n";
    }

    if (cbTel == '' || cbTel == 'Contact Number') {
        errorString += 'Please enter your contact number.'+"\n";
    }

    if (cbMessage == '' || cbMessage == 'Message') {
        errorString += 'Please enter your message.'+"\n";
    }
    
    if (0 < errorString.length) {
        alert('The following error(s) occured;' + "\n" + errorString);
    } else {
        cb2form_submit();
    }
    return false;
}

function cb2form_submit() {
    $('#cb2form .result').hide();
    var data = $('#cb2form').serialize();
    $.post('/secure/callBack.php', data, function(data) {
        $('.result').html(data);
        $('#cb2form .result').show();
    });
}


