﻿jQ = jQuery.noConflict();

var form = 1;
var auth = 0;

jQ(function(){
	
	if(jQ(".services-slider").length != 0)
		jQ(".services-slider").scroller({autoplay:true,circular:true,interval: 4500});
	
	
	jQ('#register-type').change(function(){
		
		if(jQ(this).val() == "personal")
			showPersonal();
		else
			showCorporate();
	});
	
	jQ('#add-auth').change(function(){
		if(jQ('#add-auth').is(':checked'))
			showAuth();
		else
			hideAuth();
	});
	
	jQ('#rb_deliver').change(function(){
		if(jQ(this).is(':checked'))
			{
				jQ('#del-ins').attr("disabled",false);
				jQ('#add-credit-card-row').hide();
				jQ('#rb_DeliveryChargeAll').attr("disabled",true).attr("checked",false);
				jQ('#rb_PickUpChargeAll').attr("disabled",false).attr("checked",true);
				jQ('#rb_PickUpChargeFeeOnly').attr("disabled",false);
			}
	});
	
	jQ('#rb_deliver-home').change(function(){
		if(jQ(this).is(':checked'))
			{
				jQ('#del-ins').attr("disabled",true);
				jQ('#add-credit-card-row').show();
				jQ('#rb_DeliveryChargeAll').attr("disabled",false).attr("checked",true);
				jQ('#rb_PickUpChargeAll').attr("disabled",true);
				jQ('#rb_PickUpChargeFeeOnly').attr("disabled",true);
			}
	});
	
	jQ('#rb_pickup').change(function(){
		if(jQ(this).is(':checked'))
			{
				jQ('#del-ins').attr("disabled",true);
				jQ('#add-credit-card-row').show();
				jQ('#rb_DeliveryChargeAll').attr("disabled",false).attr("checked",true);
				jQ('#rb_PickUpChargeAll').attr("disabled",true);
				jQ('#rb_PickUpChargeFeeOnly').attr("disabled",true);
			}
	});
	
	jQ('#add-credit-card').change(function(){
		if(jQ(this).is(':checked'))
			{
				jQ('#card-type').attr("disabled",false);
				jQ('#card-number').attr("disabled",false);
				jQ('#card-exp-month').attr("disabled",false);
				jQ('#card-exp-year').attr("disabled",false);
				jQ('#card-name').attr("disabled",false);
				jQ('#card-security-number').attr("disabled",false);
			}
		else
			{
				jQ('#card-type').attr("disabled",true);
				jQ('#card-number').attr("disabled",true);
				jQ('#card-exp-month').attr("disabled",true);
				jQ('#card-exp-year').attr("disabled",true);
				jQ('#card-name').attr("disabled",true);
				jQ('#card-security-number').attr("disabled",true);
			}
	});
	
	jQ('#receive-mail').change(function(){
		if(jQ(this).is(':checked'))
			jQ('#receive-catalogs').attr("disabled",false);
		else
			jQ('#receive-catalogs').attr("disabled",true).attr("checked",false);
	});
	
	jQ('#reg-form').submit(checkForm);
});

function checkForm()
	{
		var isOk = true;
		
		if(form == 1)
			isOk = isOk && checkCorporate();
		else
			isOk = isOk && checkPersonal();
			
		isOk = isOk && jQ('#exact-address').val().length > 0;		
		isOk = isOk && jQ('#city').val().length > 0;		
		isOk = isOk && jQ('#email').val().length > 0;

		if(auth == 1)
			isOk = isOk && checkAuthorized();
			
		return isOk;
	}
	
function checkCorporate()
	{
		var isOK = true;
		
		isOK = isOK && jQ('#trade-name').val().length > 0;
		isOK = isOK && jQ('#representative-name').val().length > 0;
		isOK = isOK && jQ('#off-num').val().length > 0;
		
		return isOK;
	}
	
function checkPersonal()
	{
		var isOK = true;
		
		isOK = isOK && jQ('#first-name').val().length > 0;
		isOK = isOK && jQ('#last-name').val().length > 0;
		isOK = isOK && jQ('#home-num').val().length > 0;
		
		return isOK;
	}
	
function checkAuthorized()
	{
		var isOK = true;
		
		isOK = isOK && jQ('#aut-first-name').val().length > 0;
		isOK = isOK && jQ('#aut-last-name').val().length > 0;
		isOK = isOK && jQ('#aut-trn-number').val().length > 0;
		isOK = isOK && jQ('#aut-email').val().length > 0;
		
		return isOK;
	}

function hideAll()
	{
		hideAuth();
		
		jQ('#trade-name-row').hide();
		jQ('#first-name-row').hide();
		jQ('#last-name-row').hide();
		jQ('#rep-name-row').hide();
		jQ('#rep-trn-row').hide();
		jQ('#home-phone-row').hide();
	}
	
function hideAuth()
	{
		jQ('.aut-header-row').hide();
		jQ('.aut-first-name-row').hide();
		jQ('.aut-last-name-row').hide();
		jQ('.aut-trn-row').hide();
		jQ('.aut-email-row').hide();
		
		auth = 0;
	}
	
function showAuth()
	{
		jQ('.aut-header-row').show();
		jQ('.aut-first-name-row').show();
		jQ('.aut-last-name-row').show();
		jQ('.aut-trn-row').show();
		jQ('.aut-email-row').show();
		
		auth = 1;
	}

function showCorporate()
	{
		hideAll();
		
		form = 1;
		
		jQ('#heading1').html('Business Information');
		jQ('#trade-name-row').show();
		jQ('#trn').html('Company TRN#');
		jQ('#rep-name-row').show();
		jQ('#rep-trn-row').show();
		jQ('#exact-address-label').html('Exact Company Address *');
	}

function showPersonal()
	{
		hideAll();
		
		form = 2;
		
		jQ('#heading1').html('Personal Information');
		jQ('#first-name-row').show();
		jQ('#last-name-row').show();
		jQ('#trn').html('Customer\'s TRN #');
		jQ('#home-phone-row').show();
		jQ('#exact-address-label').html('Exact Home Address *');
	}
	
