﻿function ActionFormValidation()
{
    var errormsg = '';
    var invalidMsg = '';
    
    var firstname = $("#actionform-firstname").val()
    var lastname = $("#actionform-lastname").val()
    var state = $("#actionform-state").val()
    var email = $("#actionform-email").val()
    var phone = $("#actionform-phone").val()
    
    
    if (firstname == '') errormsg = constructErrorMsg(errormsg, 'First Name');
    if (lastname == '') errormsg = constructErrorMsg(errormsg, 'Last Name');
    if (state == '') errormsg = constructErrorMsg(errormsg, 'State or Province');
    
    if (email == '') errormsg = constructErrorMsg(errormsg, 'Email Address');
    else if (email.length <= 3) errormsg = constructErrorMsg(errormsg, 'Email Address');
    else if (!(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w{2,4}$/.test(email))) {
        invalidMsg += "The E-mail Address is incorrect\n";
    }

    if (errormsg != '') {
        showJsError(errormsg);
        return false;
    }
    else if (invalidMsg != '') {
        showJsErrorFinal(invalidMsg, '');
        return false;
    }
    else {
        return true;
    }
    
}

function showJsError(errormsg)
{
	if (errormsg !='') {
	    showJsErrorFinal(errormsg, 'The following fields cannot be left blank: ');
	}
}

function showJsErrorFinal(errormsg, msgStart) {
    if (errormsg != '') {
        $('.formerror').html(msgStart + errormsg);
    }
    $('#actionform-messaging').show().animate({ top: "0" }, { duration: 800, easing: 'easeOutExpo' }).animate({ top: "-50px" }, { duration: 300, easing: 'easeInExpo' });
    setTimeout('$("#actionform-messaging a.closeerror").fadeTo(800, 1.0);', 1200);
    $('#actionform-messaging a.closeerror').click(
			   function() {
			       $("#actionform-messaging a.closeerror").fadeTo(800, 0.0);
			       $('#actionform-messaging').animate({ top: "-300px" }, { duration: 800, easing: 'easeInExpo', compete: hideErrorMessaging });
			   }
		    );
    function hideErrorMessaging() {
        $('#actionform-messaging').hide();
    }
}


function showNetError()
{
    $('#actionform-messaging-net').show().animate({top:"0"}, {duration:800, easing: 'easeOutExpo'}).animate({top:"-50px"}, {duration:300, easing: 'easeInExpo'});
	setTimeout ('$("#actionform-messaging-net a.closeerror").fadeTo(800, 1.0);', 1200);
		$('#actionform-messaging-net a.closeerror').click(
			   function() {
					$("#actionform-messaging-net a.closeerror").fadeTo(800, 0.0);
			       	$('#actionform-messaging-net').animate({top:"-300px"}, {duration:800, easing: 'easeInExpo', compete:hideErrorMessaging});
		  	   }
		    );
		function hideErrorMessaging() {
		       $('#actionform-messaging-net').hide();
		}	
}

function constructErrorMsg(errormsg, addme)
{
    if (errormsg != '')
    {
        errormsg = errormsg + ', ';
    }
    errormsg = errormsg + addme;
    
    return errormsg;
}

function formSetup(itemid, productlabel, visistatdid, itemtype)
{
    $("#demoitemid").val(itemid);
    InsertExtraVisistat(visistatdid, 'Action Form For - ' + productlabel + ' - ' + itemtype);
}

function SetupActionForm(productlabel, visistatdid)
{
    $('#screen-white, #actionform').css({opacity: "0"});
    $('#boxform').hide();
	
	    $('.actions ul a').click(
		    function() {
		        ShowActionForm(productlabel, visistatdid, $(this).attr("rel"), $(this).attr("title"))
	  	    }
	    );

	    $('a.close').click(
		    function() {
		    	    $('#actionform, #screen-white').fadeTo(500, 0.0, hideBoxes);
		  	    }
		    );
			
	    function hideBoxes() {
		    $('#actionform, #screen-white, #boxform').css({display: "none"});
			$('#actionform-messaging, #actionform-messaging-net').animate({top:"-300px"}, {duration:800, easing: 'easeInExpo'});
	    }
}

function ShowActionForm(productlabel, visistatdid, itemid, itemtype)
{
    $('.formerror').html('');
    $('#screen-white').css({display: "block"}).fadeTo(500, 0.6);
    $('#boxform').show();				
    setTimeout ('$("#actionform").css({display: "block"}).fadeTo(600, 1.0);', 500); 
    formSetup(itemid, productlabel, visistatdid, itemtype);
}

function SetupActionFormShow(productlabel, visistatdid, itemid, itemtype)
{
    SetupActionForm(productlabel, visistatdid);
    ShowActionForm(productlabel, visistatdid, itemid, itemtype);
	showNetError();
}

function SetupActionSuccessForm(productlabel, visistatdid)
{
    $('#screen-white, #actionform').css({opacity: "0"});
    $('#boxform').hide();
	
	    $('#screen-white').css({display: "block"}).fadeTo(500, 0.6);
			    $('#boxform').show();				
			    setTimeout ('$("#actionform").css({display: "block"}).fadeTo(600, 1.0);', 500); 
		
	
	    $('#actionform').find('a.close').click(
		    function() {
		    	    $('#actionform, #screen-white').fadeTo(500, 0.0, hideBoxes);
		  	    }
		    );
	    
	    $('#actionform').find('a.continuevideo').click(
		    function() {
		    	    
		    	    ActionFormContinueDemoVideo(productlabel, visistatdid);
		  	    }
		    );
	    
	    $('#actionform').find('a.designgallery').click(
		    function() {
		    	    
		    	    ActionFormContinueDesignGallery(productlabel, visistatdid);
		  	    }
		    );
	    
	    $('#actionform').find('a.continuewebcast').click(
		    function() {
		    	    
		    	    ActionFormContinueDemoWebcast(productlabel, visistatdid);
		  	    }
		    );
			
	    function hideBoxes() {
		    $('#actionform, #screen-white, #boxform').css({display: "none"})
	    }
	    
	    InsertExtraVisistat(visistatdid, 'Action Form Success For - ' + productlabel);
}

function ActionFormContinueDemoVideo(productlabel, visistatdid)
{
    $('#actionform, #screen-white').fadeTo(500, 0.0, function(){
        $('#actionform, #screen-white, #boxform').css({display: "none"});
        setupDemoVideo(productlabel, visistatdid);
    });
}

function setupDemoVideo(productlabel, visistatdid)
{
	$('#screen-white').show().css({display: "block"}).animate({opacity: "0.6" }, {duration: 500, complete: function(){
	    $('#flvdemoplayer').show().css({display: "block"});	
		$('.flv-demoplayer').find('a.close').click(
            function() {
					if ($.browser.msie)
					{
						if ($.browser.version.substr(0,1) == '6' )
							history.go(0);
						else
							window.location = window.location;
					}
				else
			    	$('.flv-demoplayer, #screen-white').hide();
  	                    }
                )
	}});
	$('.flv-demoplayer').show();
    InsertExtraVisistat(visistatdid, 'Demo Video For - ' + productlabel);
}

function ActionFormContinueDesignGallery(productlabel, visistatdid)
{
    $('#actionform, #screen-white').fadeTo(500, 0.0, function(){
        $('#actionform, #screen-white, #boxform').css({display: "none"});
        setupDesignGallery(productlabel, visistatdid);
    });
}

function setupDesignGallery(productlabel, visistatdid)
{
	$('#screen-white').show().css({display: "block"}).animate({opacity: "0.6" }, {duration: 500, complete: function(){
	    $('.designgallery').show().css({display: "block"});	
		$('.designgallery').find('a.close').click(
            function() {
			    	$('.designgallery, #screen-white').hide();
  	                    }
                )
	}});
    InsertExtraVisistat(visistatdid, 'Design Gallery For - ' + productlabel);
}


function ActionFormContinueDemoWebcast(productlabel, visistatdid)
{
    $('#actionform, #screen-white').fadeTo(500, 0.0, function(){
        $('#actionform, #screen-white, #boxform').css({display: "none"});
        setupDemoWebcast(productlabel, visistatdid);
    });
}

function setupDemoWebcast(productlabel, visistatdid)
{
	$('#screen-white').show().css({display: "block"}).animate({opacity: "0.6" }, {duration: 500, complete: function(){
	    $('#flvwebcastplayer').show().css({display: "block"});	
		$('.flv-webcastplayer').find('a.close').click(
            function() {
					if ($.browser.msie)
					{
						if ($.browser.version.substr(0,1) == '6' )
							history.go(0);
						else
							window.location = window.location;
					}
				else
			    	$('.flv-webcastplayer, #screen-white').hide();
  	                    }
                )
	}});
	$('.flv-webcastplayer').show();
    InsertExtraVisistat(visistatdid, 'Demo Webcast For - ' + productlabel);
}
