/**
 * Search minimal count characters
 * form 			: Form of the search function
 * min_char_count	: The minimal character count [integer]
 * alert_value		: Alert value
 */
function initSearch(form, min_char_count, alert_value, search_lbl){
	var textField = form.find("input[type='text']");
	
	// when submit search is clicked
	form.submit(function(){
		if (textField.val() == search_lbl){
			return false;
		}
		if ( textField.val().length < min_char_count ){
			alert(alert_value.replace(/[\d]/gi, min_char_count));
			textField.val(search_lbl);
			return false;
		}
		form.find("input[name='txt_search']").val( textField.val() );
		return true;
	});
	
	//onfocus / unfocus input text field (refill value)
	textField.focus(function(){
		
		$(this).css('color', '#353535');
		if ($(this).val() == search_lbl) 
			$(this).val('');
	});
	textField.blur(function(){
	   $(this).css('color', '#777777');
		if (this.value == '') 
			this.value = search_lbl;
	});
}

/**
 * Colorize on focus
 */
jQuery.fn.checkForValue = function(label){
	//on focus
	this.focus(function(){
		$(this).css('color', '#5D5D5D');
		if ($.trim($(this).val()) == label) $(this).val('');
		$(this)[0].select();
	});
	//on unfocus
	this.blur(function(){
		if ($(this).val() == '' || $.trim($(this).val()) == label) {
			$(this).val(label);
			$(this).css('color', '#959393');
		}
	});
}

/**
 * Generate popup Class
 */
 function Popup_window(){
	var popup_win;

	this.location;
	this.title;
	this.width;
	this.height;
	this.addressbar = true;
	this.statusbar = true;
	this.menubar = true;
	this.directories = true;
	this.toolbar = true;
	this.resizable = true;
	this.scrollbars = true;

	Popup_window.prototype.show = function() {
		var config;
		config = this.toolbar ? ' toolbar=1,' : ' toolbar=0,';
		config += this.addressbar ? ' location=1,' : ' location=0,';
		config += this.directories ? ' directories=1,' : ' directories=0,';
		config += this.statusbar ? ' status=1,' : ' status=0,';
		config += this.menubar ? ' menubar=1,' : ' menubar=0,';
		config += this.scrollbars ? ' scrollbars=1,' : ' scrollbars=0,';
		config += this.resizable ? ' resizable=1,' : ' resizable=0,';
		config += !empty(this.width) ? ' width=' + this.width + ',' : '';
		config += !empty(this.height) ? ' height=' + this.height : '';

		popup_win = window.open(this.location, this.title, config);
		if (window.focus) {popup_win.focus()}
		return false;
	}
 }
