﻿jQuery.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};


var myui = {
	centerPopup: function(container) {
		var windowHeight = container.clientHeight;
	
		$("#popupContact").css({
			"position": "absolute",
			"top": windowHeight / 2 - $("#popupContact").height() / 2,
			"left": container.clientWidth / 2 - $("#popupContact").width() / 2
		});
		//only need force for IE6
	
		$("#backgroundPopup").css({
			"height": windowHeight
		});
	},

	pup: function(width, height, title, text, button1Source, button2Source, callback1, callback2, selectOptions) {
		$('#pupTtl').html(title);
		$('#pupCnt').html(text);

		if (selectOptions) {
			$('#pupSel').empty('options').show();
			for (var o in selectOptions) {
				var opt = document.createElement('option');
				opt.value = selectOptions[o];
				opt.appendChild(document.createTextNode(selectOptions[o]));
				$('#pupSel').append(opt);
			}
		}
		else $('#pupSel').hide();

		if (height) $('#popupContact').height(height);
		if (width) $('#popupContact').width(width);
		if (button1Source) $('#pupBtn1').attr('src', button1Source).show().unbind('click').click(callback1); else $('#pupBtn1').hide();
		if (button2Source) $('#pupBtn2').attr('src', button2Source).show().unbind('click').click(callback2); else $('#pupBtn2').hide();

		myui.centerPopup(document.documentElement);

		$('#killUI').css({ "opacity": "0.7" }).fadeIn('fast');
		$('#popupContact').fadeIn('fast');
	},
		
	disablePopup: function() {
		$('#killUI').fadeOut('fast');
		$('#popupContact').fadeOut('fast');
	},
		
	scrollWindow: function(endposition) {
		$.scrollTo( {top:'0px', left:endposition}, 800 );
	},
	
	resetMyForm: function() {
		var validator = $("#PageForm").validate();
		validator.resetForm();
	}


};