$(document).ready(function() {
	$('.search_input input[type="text"]').focus(function() {fieldClear(this)});
    $('.search_input input[type="text"]').blur(function() {fieldClear(this)});

});
// clear field value function: removes the default value onfocus, and adds back if nothing entered 
function fieldClear(obj) {
	if(obj.Val) {
		if (obj.value == '') { 
			obj.value = obj.Val;
			obj.Val = null;
			obj.first = null;
		} 
		else {
			obj.Val = null;
		}
	} else if (!obj.first) { 
		obj.Val = obj.value;
		obj.value = ''; 
		obj.first = 'true';
	} 
}

function setKitBuyLink(kit) {
	var genre = document.getElementById('i_genre').value;
	if (genre == 'none') {
		alert('Please select a genre from the drop-down box.');
		return false;	
	}
	else if (genre == 'rock') {
		if (kit == 'beginners') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=BGNRROCK';
		}
		else if (kit == 'beginners-vi') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=BGNRROCKVI';
		}
		else if (kit == 'essentials') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=ESSNTLSROCK';
		}
	}
	else if (genre == 'country') {
		if (kit == 'beginners') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=BGNRCOUNTRY';
		}
		else if (kit == 'beginners-vi') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=BGNRCOUNTRYVI';
		}
		else if (kit == 'essentials') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=ESSNTLSCNTRY';
		}
	}
	else if (genre == 'christian') {
		if (kit == 'beginners') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=BGNRCHRISTIAN';
		}
		else if (kit == 'beginners-vi') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=BGNRCHRISTIANVI';
		}
		else if (kit == 'essentials') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=ESSNTLSCHRISTIAN';
		}
	}
	else if (genre == 'acoustic') {
		if (kit == 'essentials') {
			buyLink='http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=PINT&ADD=ESSNTLSACOUSTIC';
		}
	}
	document.getElementById('buy_link').href = buyLink;
}

//Validate functions for FREE DOWNLOAD form

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}


function validate_form(thisform, whichProcess)
{
if (whichProcess == 'dl_1') {
	with (thisform)
	  {
		  if (validate_required(i_fname,"Please enter your first name")==false)
		  {i_fname.focus();return false;}
		  if (validate_required(i_lname,"Please enter your last name")==false)
		  {i_lname.focus();return false;}
		  if (validate_required(i_email,"Please enter your email address")==false)
		  {i_email.focus();return false;}
		  if (validate_email(i_email,"Please make sure your email address is valid")==false)
		 {i_email.focus();return false;}
	  }
	}
else if (whichProcess == 'dl_2') {
	with (thisform)
	  {
		  if (validate_required(i_skill_level,"Please select your skill level")==false)
		  {i_skill_level.focus();return false;}
		  if (validate_required(i_fav_genre,"Please select your favorite genre")==false)
		  {i_fav_genre.focus();return false;}
		  if (validate_required(i_downloadchoice,"Please select your free download")==false)
		  {i_downloadchoice.focus();return false;}
		  
	  }
	}
}