/**
 * jelectbox
 *
 * @param
 * @author serdar ozturk
 * @url http://kokulusilgi.com/blog/30-jelectbox
 */
(function($j){
    $j.fn.extend({
        
        jelectbox: function(options){
        
            //jelectbox settings 
            var defaults = {
                selectbox_id: 'myjelectbox',
				width: 'auto',
				height: 'auto'
            };
            
            var options = $j.extend(defaults, options);
            
            return this.each(function(){
                var o = options;
                var obj = $j(this);
				var l_selected = '';
				var chk = 'chkit_'+o.selectbox_id;
				
				l_selected = $j('#'+o.selectbox_id+' option:selected').text();
                $j('#'+o.selectbox_id).after('<div class="jelectbox_main" style="position:relative; width:'+o.width+';"><div style="float:left;"><span class="jelectbox_text">'+l_selected+'</span></div><div id="'+chk+'" class="inite" style="float:right"></div><div style="clear:both;"></div><div class="jelectbox_options" style="position:absolute; display:none; width:'+o.width+'"><div class="jelectbox_ul_parent" style="height:'+o.height+'; overflow:auto; overflow-x:hidden;"><ul class="jelectbox_ul_selectbox"></ul></div> </div></div>');
 				$j('#'+o.selectbox_id).css('display','none');
				
				// create option list
				$j("#"+o.selectbox_id+" *").each(function (i) { 
					var current = $j(this); 
					clsg = '';
					if (i % 2 == 0) {
						clsg = ' class="g"';
					}
					$j('.jelectbox_ul_selectbox',obj).append('<li value="' + current.attr("value") + '"'+clsg+'>' + current.text() + '</li>');
				});
				
				// open - hide option list
                $j('.jelectbox_main', obj).click(function(){
					if ($j("#" + o.selectbox_id).get(0).disabled == false) {
						$j('.jelectbox_options', obj).slideToggle();
						// up down select image
						if ($j('.jelectbox_options', obj).css('height') != '1px')
						{
							$j(this).removeClass('up');
						} else {
							$j(this).addClass('up');
						}
					}
                });
				
				// change selected
                $j('ul.jelectbox_ul_selectbox li',obj).click(function(){
					var current_value = $j(this).attr("value");
					if($j('#'+chk).hasClass("inite")) $j('#'+chk).removeClass("inite");
					if(current_value != "0"){
						$j('#'+chk).removeClass("error");
					} else {
						if($j('#'+chk).hasClass("error") == false){
							$j('#'+chk).addClass("error");
						}
					}
                    $j('.jelectbox_text',obj).html($j(this).text());
					$j("#"+o.selectbox_id+" option:selected").attr("selected",false);
                    $j("#"+o.selectbox_id+" option[value='" + current_value + "']").attr("selected", "selected");
                    $j('.jelectbox_main a',obj).click();
					var domEl = $j("#"+o.selectbox_id).get(0);
      				$j(this).queue(domEl.onchange);
                });
                
            });
        }
    });
})(jQuery);


/**
 * Copyright (c) 2009 myPocket technologies (www.mypocket-technologies.com)
 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * View the GNU General Public License <http://www.gnu.org/licenses/>.

 * @author Darren Mason (djmason9@gmail.com)
 * @date 3/13/2009
 * @projectDescription	Replaces the standard HTML form checkbox or radio buttons. Allows for disable, and very customizable.
 * @version 1.0.3
 * 
 * @requires jquery.js (tested with 1.3.2)
 * 
 * @param disable_all:	false,
 * @param wrapperclass:	"group"
 */

(function($j) {	
	$j.fn.custCheckBox = function(options){
		
		var defaults = {
				disable_all:	false,				//disables all the elements
				wrapperclass:	"group"
			};
		//override defaults
		var opts = $j.extend(defaults, options);
		
		return this.each(function() { 
	 		 var obj = $j(this);
	 		 
		$j.fn.buildbox = function(thisElm){

			var currElm = $j(thisElm);
			
			$j(currElm).css({display:"none"}).before("<span class=\"cust_checkbox\">&nbsp;&nbsp;&nbsp;&nbsp;</span>");
			
			var isChecked = $j(currElm).attr("checked");
			var boxtype = $j(currElm).attr("type");
			var disabled = $j(currElm).attr("disabled");
			
			if(boxtype === "checkbox")
			{
				$j(currElm).prev("span").addClass("checkbox");
				if(disabled || opts.disable_all){boxtype = "checkbox_disabled";}
			}
			else
			{
				$j(currElm).prev("span").addClass("radio");
				if(disabled || opts.disable_all){boxtype = "radio_disabled";}
			}
			
			if(isChecked)
				$j(currElm).prev("span").addClass("cust_"+boxtype+"_on");
			else
				$j(currElm).prev("span").addClass("cust_"+boxtype+"_off");
			
			if(opts.disable_all)
				$j(currElm).attr("disabled","disabled");
		};
		
		$j.fn.buildbox($j(obj));
		
		$j("."+ opts.wrapperclass+" label").unbind().click(function(){
			
			if(!opts.disable_all)
			{
				var custbox = $j(this).next("span");
				var boxtype = $j(custbox).next("input").attr("type");
				var disabled = $j(custbox).next("input").attr("disabled");
					
				if($j(custbox).hasClass("checkbox"))
				{
					if($j(custbox).hasClass("cust_"+boxtype+"_off") && !disabled)
						$j(custbox).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on"); //turn on
					else if(!disabled)
						$j(custbox).removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off"); //turn off
				}
				else if(!disabled)
				{
					$j(custbox).parent().find(".cust_checkbox").removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked");
					$j(custbox).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on"); //turn on
				}
			}
			
		});
		
		$j(".cust_checkbox").unbind().click(function(){
			
			if(!opts.disable_all)
			{
				var boxtype = $j(this).next("input").attr("type");
				var disabled = $j(this).next("input").attr("disabled");
					
				if($j(this).hasClass("checkbox"))
				{
					if($j(this).hasClass("cust_"+boxtype+"_off") && !disabled)
						$j(this).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on").next("input").attr("checked","checked"); //turn on
					else if(!disabled)
						$j(this).removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked"); //turn off
				}
				else if(!disabled)
				{
					$j(this).parent().find(".cust_checkbox").removeClass("cust_"+boxtype+"_on").addClass("cust_"+boxtype+"_off").next("input").removeAttr("checked");
					$j(this).removeClass("cust_"+boxtype+"_off").addClass("cust_"+boxtype+"_on").next("input").attr("checked","checked"); //turn on
				}
			}
		});
	}); 	
};
	
})(jQuery);



/* Input Focus & activates */
$j(document).ready(function() {  
	//activate checkboxes
	$j("input[type='checkbox']").custCheckBox();

	//activate jelectboxes
	$j('#select_budget').jelectbox({selectbox_id:'budget', width:'210px'});
	$j('#select_timeline').jelectbox({selectbox_id:'timeline', width:'210px'});

	//input & textarea focus
    $j('.chk').addClass("idleField");
	$j('.chk').focus(function() {
		$j(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $j('.chk').blur(function() {
    	$j(this).removeClass("focusField").addClass("idleField");
        if ($j.trim(this.value) == ''){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
});


$j('#cname').valid8();
$j('#cemail').valid8({
    regularExpressions: [
        { expression: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i}
    ]
});
$j('#project_details').valid8({
    regularExpressions: [
        { expression: /^[a-z0-9!@#$%&'";:<>*+/=?^_`{|}()~\-\s\\,.\w\xc0-\xff]+$/i}
    ]
});


function chkForm(theForm) {
	$j(".inite").addClass("error");
	$j('*').removeClass("inite");
	if($j('*').hasClass("error") || $j('*').hasClass("inite")){ return false; } else { $j("#private").attr("value","privatevar"); return true; }
}

