function cleanInput(sel){
 var str = $(sel).val();
 $(sel).focus(function(){if (this.value == str) this.value=""}).blur(function(){ if ($.trim(this.value) == "") this.value = str});
}

/* number validation for calculator */
function isNumber(field)
{
 var re = /^[0-9]*$/;
 if (!re.test(field.value))
 {
 alert(document.getElementById('js_onlyNums').value);
 field.value = field.value.replace(/[^0-9]/g,"");
 }
}



$(function(){

 /* clean fields & validate number */
 if ($('#how').length) {
 cleanInput('#how');
 $('#how').keyup(function(){isNumber(this)});
 }
 if ($('#how2').length) {
 cleanInput('#how2');
 $('#how2').keyup(function(){isNumber(this)});
 }
 if ($('#curr_amt').length) {
 cleanInput('#curr_amt');
 $('#curr_amt').keyup(function(){isNumber(this)});
 }
 if ($('#metal_amt').length) {
 cleanInput('#metal_amt');
 $('#metal_amt').keyup(function(){isNumber(this)});
 }
 if ($('#long_months').length) {
 cleanInput('#long_months');
 $('#long_months').keyup(function(){isNumber(this)});
 }
 if ($('#long_years').length) {
 cleanInput('#long_years');
 $('#long_years').keyup(function(){isNumber(this)});
 }
 if ($('#what').length) {
 cleanInput('#what');
 }
 if ($('#name').length) {
 cleanInput('#name');
 }
 if ($('#email').length) {
 cleanInput('#email');
 }
 if ($('#body').length) {
 cleanInput('#body');
 }

 /* AddClass to body to adjust css to js.elements */
 $('body').addClass('js');

 /* smooth scroll */
 $('a[href*=#]:not([href=#])').click(function() {
 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
 var $target = $(this.hash);
 $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
 if ($target.length) {
 var targetOffset = $target.offset().top;
 $('html,body').animate({scrollTop: targetOffset}, 700);
 return false;
 }
 }
 });

 /* currency div */
 if($('.currency').length)
 {
 $('.currency').hide();
 $('.displaying a').bind("click", function(){
 $(this).parent().parent().parent().find('.currency').css({position:'absolute', top:$(this).position().top + 15, left:$(this).position().left - 1}).slideDown();
 $(this).parent().addClass('blanca');
 });

 $('.currency').bind("mouseleave", function(){$(this).slideUp(); $('.displaying').removeClass('blanca');});
 }

 /* preview div */
 if($('.preview').length)
 {
 $('.preview li > div').hide();
 $('.preview li > div').each(function(i) {
 $(this).append('<p class="align-c"><a href="' + $(this).parent().find('a').attr('href') + '">' + document.getElementById('js_download').value + '</a></p>');
 });
 $('.preview li > a').bind("mouseover", function(mouse){
 var elPrev = $(this).parent().find('div:hidden');
 elPrev.addClass('el-prev').css({position:'absolute', top: (mouse.pageY - (elPrev.height()/2)), left:(mouse.pageX - (elPrev.width()/2))}).fadeIn();
 });
 $('.preview li > div').bind("mouseleave", function(){$(this).fadeOut();});
 }

 /* bullets div */
 if($('ul.bullet').length)
 {
 //escondemos elemento y creamos el que cierra
 $('div.hide-me').hide().append('<a href="javascript:void(0);" class="slide-up">' + document.getElementById('js_hide').value + '</a>');
 //abre
 $('ul.bullet h5').wrapInner('<a href="javascript:void(0);" class="slide-down"></a>').find('a').bind("click", function(){$(this).removeClass('slide-down').parent().next('.hide-me').slideDown();});
 //cierra
 $('ul.bullet a.slide-up').bind("click", function(){$(this).parent().slideUp().parent().find('h5 a').addClass('slide-down');});
 }

 if($('.print-me').length)
 {
 $('div.print-me').append('<a href="javacript:document.print();">' + document.getElementById('js_printVersion').value + '</a>');
 }
 }

);