jQuery(document).ready(function(){
(function($){    
	
	$('.ajax-form').bind('submit',function(){
		var action = this.action;
		var self = this;
		if(this.stopOnErrors){if(this.hasErrors){ return false; }}
		$.ajax({
			url: action,
			data:$(self).serialize(),
			success:function(response){
				if(typeof self.success === 'function' ){ 
					self.success();
				}
			}
		});			
		return false;
	});
	
	$.ajaxSetup({
      type: "POST",   				//global method
      timeout: 35000, 				//timeout time 35 sec
      //function to handle ajax error
	  error:function(httpObj,errMsg,ex){
         		
		 		$(this.throbber).next(".div_throb").remove(); //remove the throbber
				 //call the error handler of the specific Object
				 if(typeof this.customError == 'function'){
				 	this.customError(httpObj,errMsg,ex); 
				 }
				 // check for an abort
				if(httpObj.isAbort != true){
				
				try{
					var data = new Array();
					for(item in this){
						try{
							if(typeof this[item] != 'function'){
								
								data.push("varType"+item+"="+typeof(this[item]) +"&"+item+"="+this[item]);
							}
						}
						catch(exception){
							data.push("exception"+item+"="+exception);
						}
					}
					for(item in httpObj){
						try{
							if(typeof httpObj[item] != 'function'){
								
								data.push("varType"+item+"="+typeof(httpObj[item]) +"&"+item+"="+httpObj[item]);
							}
						}
						catch(exception){
							data.push("exception"+item+"="+exception);
						}
					}      
					for(item in ex){
						try{
							if(typeof ex[item] != 'function'){
								
								data.push("varType"+item+"="+typeof(ex[item]) +"&"+item+"="+ex[item]);
							}
						}
						catch(exception){
							data.push("exception"+item+"="+exception);
						}
					}
					//get all information an send it to the error loger
					//location.href = '/errors/error500.php?'+data.join("&")+'&msg='+errMsg;
				}catch(exceptionFatal){
					//if big problem then try to log it
					var errorObj = new Array();
					for(item in exceptionFatal){
						try{
							if(typeof exceptionFatal[item] != 'function'){
								
								errorObj.push("varType"+item+"="+typeof(exceptionFatal[item]) +"&"+item+"="+exceptionFatal[item]);
							}
						}
						catch(exception){
							errorObj.push("exception"+item+"="+exception);
						}
					} 
					//location.href = '/errors/error500.php?'+errorObj.join("&")+'&msg='+errMsg;
				}}
		
			},
			//global complete handler
            complete:function(){
                // $(this.throbber).next(".div_throb").remove();
            },
			//global beforeSend handler
            beforeSend:function(xh){
               //$(".div_throb").click(); //remove previous calls
               xh.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
               //$(this.throbber).after("<img style=\"margin-left:5px; cursor:pointer\" class=\"div_throb\" src='/images/ajax-loader.gif' alt='loading'/>");
               //$(this.throbber).next(".div_throb").bind("click",function(){xh.isAbort = true; xh.abort(); return false;});
           }
    });


var errorMSG = {'v-numeric':'Please enter a valid number.','v-phone':'Please enter a valid fax number.','v-date':'Please enter a valid date.','v-email':'Please enter a valid email address.','v-postalCode':'Please enter a valid postal code.','v-min2':'This field is too short (2 characters minimum).','v-max150':'150 characteres maximum.','v-max255':'255 characteres maximum.'};
validateConfig['errorMSG'] = errorMSG;

})(jQuery);

;
        $(function(){
            $("a[@rel='external']").each(function(){
                this.target = "_blank";
            });

            /*  -------------------------------------------------------------------
                Toggle Content ---------------------------------------------------- */
            $("input:image")
                .bind('mouseover focus', function(){this.src = this.src.replace(/(?:_o)?\.([a-z]*)$/i,"_o.$1"); })
                .bind('mouseout blur',   function(){this.src = this.src.replace(/_o\./i,".");});
        });

;
 })
