//------------------------------------
//------------------------------------
//------------------------------------
//-------CUSTOM TEMPLATE FUNCTIONS----
//------------------------------------
//------------------------------------
//------------------------------------

function initQuestions(){
	$('.start_link').click(function(){
		$('.main_mask').fadeIn(function(){
			$('.survey_text').hide();
			$('#question1').show();
			$('.questions').show();
			$('.main_mask').fadeOut();
		})
	})
}

function selectPrize(prize_name){
	collectAnswer('gift',prize_name);
	$('.main_mask').fadeIn(function(){
		$('.intro_text').hide();
		$('#'+prize_name).show();
		$('.main_mask').fadeOut();
	});
}
function nextQuestion(question_id,isloader){
	if (isloader!=undefined){
		setTimeout(function(){nextQuestion(question_id+1);},2000);
	}
	$('.main_mask').fadeIn(function(){
		$('#question'+(question_id -1)).hide();
		$('#question'+(question_id)).show();
		$('.main_mask').fadeOut();
	});
	//fadeTransition('#question'+(question_id -1),'#question'+question_id,400);
}

function isAnswered(question_id){
	if ($('#question'+(question_id)+' input:checked').length<1){
		alert('Please select an answer.');
		return false;
	}
	else{
		return true;
	}
}
//------------------------------------
//------------------------------------
//---------Common Functions-----------
//------------------------------------
//------------------------------------

function fadeTransition(from,target,time){
	$(from).fadeOut(time,function(){
		$(target).fadeIn(time);
	});
}
function uncheckRadios(){
	$('input:radio').each(function(){
		$(this).attr('checked', false);
	})
}
function checkRadio(obj){
	$(obj).parent().find('input').attr('checked', 'checked');
}

function collectAnswer(name,answer,formID){
	if(formID==undefined){
		formID='#form1';
	}
	$(formID).prepend('<input type="hidden" value="'+answer+'" name="'+name+'"/>');
}

//------------------------------------
//------------------------------------
//--------------MP3 CODE--------------
//------------------------------------
//------------------------------------

function mp3_play(mp3_path,delay)
{	
	setTimeout(function(){
			niftyplayer('niftyPlayer1').load(mp3_path);
			niftyplayer('niftyPlayer1').play();
			niftyplayer('niftyPlayer1').registerEvent('onSongOver', 'clearSong()');
	}, delay);

}
function clearSong(){
	niftyplayer('niftyPlayer1').stop();
	niftyplayer('niftyPlayer1').reset();
}

//------------------------------------
//------------------------------------
//----------CURRENT DATE CODE---------
//------------------------------------
//------------------------------------

function insertDate(div,language,format){


	var curDate = new Date();
	var year = curDate.getFullYear();
	var month = curDate.getMonth();
	var day = curDate.getDate();
	
	
	
	if (language == "ES"){
		months= new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
		if (format=='short'){
			$(div).html((month+1)+'/'+day+'/'+year);
		}
		else{
			$(div).html(day+' de '+months[month]+' '+year);
		}
	 	
	}
	else{
		months= new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
		if (format=='short'){
			$(div).html((month+1)+'/'+day+'/'+year);
		}
		else{
			$(div).html(months[month]+' '+day+', '+year);
		}
	}
}
//------------------------------------
//------------------------------------
//----------FORM FUNCTIONS------------
//------------------------------------
//------------------------------------

function moveFocus(item,next_name){
	if(item.value.length == item.maxLength){
		$('#'+next_name).focus();
	}
}

function numbersonly(myfield, e, dec){
		var key;
		var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	    (key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}

//------------------------------------
//------------------------------------
//----------VALIDATION CODE-----------
//------------------------------------
//------------------------------------

function final_validate(){
	if ($('#fname').val() == '' || $('#lname').val() == '')
		{alert('Please enter your name'); return false;}
	else if (validate_email($('#email').val()) == false)
		return false;
	else if ($('#cell1').val().length != 3 || $('#cell2').val().length != 3 || $('#cell3').val().length != 4)
		{alert('Please enter a valid cell number'); return false;}
	else
		$('#form1').submit();
}

function validate_email(email){
	if (email == "") { 
		alert("Please enter your email address."); return false; 
	} 
	else {
		var reg = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
		var address = email;
		if(reg.test(address) == false) {
			alert('Invalid Email Address'); return false;
		}
	}
}


1
