function allInputsAreFilled(form) {
    var inputs = form.elements;
    for (var i=0;i<inputs.length;i++) {
	if (inputs[i].value == "" && inputs[i].type != "hidden") {
	    alert('You need to fill all fields!');
	    return false;
	}
    }
    return true;
}

function emailsAreMatching(form) {
    if (form.friend_email.value != form.friend_email_confirm.value) {
	alert("Emails don't match");
	return false;
    }
    return true;
}

function validateForm(form_name) {
    var form = document.getElementById(form_name);
    if (allInputsAreFilled(form) && emailsAreMatching(form)) {
        form.submit();
    } else {
        return false;
    }
}

function checkLoginForm(f) {
    var rxTrim = new RegExp("^\\s+|\\s+$", "g");
    if (f.user2.value.toString().replace(rxTrim, "").length < 1) {
        printAlert("Please enter your e-mail address.", f.name + "message");
        f.user2.focus();
        return false;
    }
    if (f.pass2.value.toString().replace(rxTrim, "").length < 1 && f.have_password[1].checked) {
        printAlert("Please enter your password.", f.name + "message");
        f.pass2.focus();
        return false;
    }
    return true;
}

function subjectDropdownChanged() {
    var subject = document.getElementById('subject');
    var reason = document.getElementById('reason_div');
    var subject_div = document.getElementById('subject_div');
    if (subject.selectedIndex=="2") {
        reason.style.display='';
        subject_div.style.display='block';
    } else {
        reason.style.display='none';
        subject_div.style.display='';
    }
}

function updateSizecharts(category_id,section_id){
    var brand_id = $F('brands');
    var sizechart = $('sizechart_content');
    if(brand_id){
	new Ajax.Updater('sizechart_content', '/ajax_requests/update_sizecharts.php?brand_id='+brand_id+'&cat_id='+category_id+'&section_id='+section_id);
	sizechart.show();
    } else {
	sizechart.hide();
    }
}

function initializeFlowPlayerForBehindTheBrandPopup(){
    playFlowPlayer($('btb-video-title').innerHTML,'Behind The Brand Video');
    $("btb-replay").onclick = replayFlowPlayer;

    myLightWindow.addOnDeactivateWindowAction(function(){
	flowplayer("player").stop();
    });
}

function playFlowPlayer(title,type){
    flowplayer("player", "/fp_content/swf/flowplayer/flowplayer.commercial-3.1.1.swf", {
	key: $("player").getAttribute('key'),
	clip: {
	    onFinish: function() {
		Omniture.finishWatchingVideo(title,type);
		showReplayVideoScreen();
	    }
        }
    });
    Omniture.startWatchingVideo(title,type);
}

function showReplayVideoScreen() {
    $('carousel').hide();
    $('btb-end-splash').show();
}

function replayFlowPlayer(){
    $('carousel').show();
    $('btb-end-splash').hide();

    playFlowPlayer($('btb-video-title').innerHTML, 'Behind The Brand Video');
}
