$('#keyword').bind('focus', function() {
	if ($('#keyword').val() == this.defaultValue) {
		$('#keyword').val('');
	}
});

$('#keyword').bind('blur', function() {
	if ($('#keyword').val() == '') {
		$('#keyword').val(this.defaultValue);
	}
});

$('#newsletter').bind('focus', function() {
	if ($('#newsletter').val() == this.defaultValue) {
		$('#newsletter').val('');
	}
});

$('#newsletter').bind('blur', function() {
	if ($('#newsletter').val() == '') {
		$('#newsletter').val(this.defaultValue);
	}
});

/*
Open Centered Popup Window Script-(c) DHTMLShock (www.dhtmlshock.com)
To add more shock to your site, visit www.DHTMLShock.com
*/

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function goTo(index, url) {
	OpenBrWindow(url, 'pu' + index, 'resizable=1,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,titlebar=yes,location=yes','1010','650','true');
}

$('#fb-icon').bind('click', function() {
	goTo(this.id, 'http://www.facebook.com/pages/Marietta-GA/Gardner-Dermatology-Med-Spa/73076907394?ref=nf');
});

$('#twitter-icon').bind('click', function() {
	goTo(this.id, 'http://twitter.com/gardnerdermspa');
});

$('#dermalogo').bind('click', function() {
	goTo(this.id, 'http://www.gardnerdermatology.com/');
});

$('#photologo').bind('click', function() {
	goTo(this.id, 'http://www.alangardnerphotography.com/');
});

$('#footerGd').bind('click', function() {
	goTo(this.id, 'http://www.gardnerdermatology.com/');
});

$('#footerJwd').bind('click', function() {
	goTo(this.id, 'http://www.journeywebdevelopment.com/');
});

$('.selectall').bind('click', function() {
	this.select();
});

$('#stfMyName').bind('focus', function() {
	if ($('#stfMyName').val() == this.defaultValue) {
		$('#stfMyName').val('');
	}
});

$('#stfMyName').bind('blur', function() {
	if ($('#stfMyName').val() == '') {
		$('#stfMyName').val(this.defaultValue);
	}
});

$('#stfMyMail').bind('focus', function() {
	if ($('#stfMyMail').val() == this.defaultValue) {
		$('#stfMyMail').val('');
	}
});

$('#stfMyMail').bind('blur', function() {
	if ($('#stfMyMail').val() == '') {
		$('#stfMyMail').val(this.defaultValue);
	}
});

$('#stfYourName').bind('focus', function() {
	if ($('#stfYourName').val() == this.defaultValue) {
		$('#stfYourName').val('');
	}
});

$('#stfYourName').bind('blur', function() {
	if ($('#stfYourName').val() == '') {
		$('#stfYourName').val(this.defaultValue);
	}
});

$('#stfYourMail').bind('focus', function() {
	if ($('#stfYourMail').val() == this.defaultValue) {
		$('#stfYourMail').val('');
	}
});

$('#stfYourMail').bind('blur', function() {
	if ($('#stfYourMail').val() == '') {
		$('#stfYourMail').val(this.defaultValue);
	}
});

$('#stfSubmit').bind('click', function() {
	$("#stfContainer").hide();
	$("#stfSpinner").show();

	var dataString = 'stfMyName=' + URLEncode($('#stfMyName').val()) + '&stfMyMail=' + URLEncode($('#stfMyMail').val()) + '&stfYourName=' + URLEncode($('#stfYourName').val()) + '&stfYourMail=' + URLEncode($('#stfYourMail').val()) + '&stfIdVideo=' + URLEncode($('#stfIdVideo').val());

	$.ajax({
	type: "POST",
	url: "inc/stf.php",
	data: dataString,
	success: function(msg) {

		$("#stfSpinner").hide();
		if (msg == 'ok') {
			$("#stfSent").show();
		} else {
			$("#stfContainer").show();
			$('#stfResponse').html(msg);
		}
	}
	});
});

$('#newsletterSubmit').bind('click', function() {
	$("#newsletterContainer").hide();
	$("#newsletterSpinner").show();

	var dataString = 'newsletter=' + URLEncode($('#newsletter').val());

	$.ajax({
	type: "POST",
	url: "inc/newsletter.php",
	data: dataString,
	success: function(msg) {
		$("#newsletterSpinner").hide();
		if (msg == 'ok') {
			$("#newsletterSent").show();
		} else {
			$("#newsletterContainer").show();
			$('#newsletterResponse').html(msg);
		}
	}
	});
});

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}