 /*$('#logo').itonTooltip({innerHtml: 'Logotype'});*/
(function($) {
	$.fn.itonTooltip = function(params){
		return this.each(function(){
			//Initializing
			var defaults = { innerHtml:'' };
			var options;
			options = $.extend({}, defaults, options, params);

			var parentClass = $(this).attr('class');
			var parentElement = $(this);
			var tooltipClass = parentClass+'_tooltip';

			var theme_name = 'orange';
			var theme_path = '/images/jquerybubblepopup-theme/'+theme_name;
			var structure = '<table cellpadding="0" cellspacing="0">'+
			                '<tbody>'+
			                '<tr>'+
			                '	<td style="background-image:url('+theme_path+'/top-left.png);" class="jquerybubblepopup-top-left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>'+
			                '	<td style="background-image:url('+theme_path+'/top-middle.png);" class="jquerybubblepopup-top-middle"></td>'+
			                '	<td style="background-image:url('+theme_path+'/top-right.png);" class="jquerybubblepopup-top-right">&nbsp;&nbsp;&nbsp;</td>'+
			                '</tr>'+
			                '<tr>'+
			                '	<td style="background-image:url('+theme_path+'/middle-left.png);" class="jquerybubblepopup-middle-left"></td>'+
			                '	<td style="background:#fff;" class="jquerybubblepopup-innerHtml">'+options.innerHtml+'</td>'+
			                '	<td style="background-image:url('+theme_path+'/middle-right.png);" class="jquerybubblepopup-middle-right"></td>'+
			                '</tr>'+
			                '<tr>'+
			                '	<td style="background-image:url('+theme_path+'/bottom-left.png);" class="jquerybubblepopup-bottom-left"></td>'+
			                '	<td style="background-image: url('+theme_path+'/bottom-middle.png); text-align: center;" class="jquerybubblepopup-bottom-middle">'+
			                '		<img class="jquerybubblepopup-tail" alt="" src="'+theme_path+'/tail-bottom.png"/></td>'+
			                '	<td style="background-image:url('+theme_path+'/bottom-right.png);" class="jquerybubblepopup-bottom-right"></td>'+
			                '</tr>'+
			                '</tbody>'+
			                '</table>';
			var tooltipElem = $('<div/>')
				//.attr('id','idsdsd'+ (Math.floor(Math.random()*1000)))
					.attr('class','jquerybubblepopup')
					.css({display: 'none',position: 'absolute', zIndex: 99999})
					.html(structure)
					.appendTo('body');

			$(this).mouseenter(function(e){
				var absX = parseInt(parentElement.offset().left);
				var absY = parseInt(parentElement.offset().top);

				var posX = absX - Math.round((tooltipElem.width()/2) )+ Math.round(parentElement.width()/2);

				var posY = absY - Math.round(tooltipElem.height()+5);
				tooltipElem.css({

					                top: posY  + 'px',
					                left: posX + 'px'

				                });

			})
					.click(function(){
						       //alert('РџРѕР·РёС†РёСЏ СЌР»РµРјРµРЅС‚Р° РЅР° СЃС‚СЂР°РЅРёС†Рµ:' + offsetPosition(this)[0] +'x'+ offsetPosition(this)[1]);
						       tooltipElem.show();
					       })
					.hover(function(){
						       tooltipElem.show();
					       }, function(){
						       tooltipElem.hide();
					       });

		});
	};
})(jQuery);

jQuery.fn.itonsaveprevious = function(options) {
	var values = new Array();
	return this.each(function() {
		var obj = $(this);
		values[obj.attr('id')] = obj.val();
		obj.click(function(){

			if ($(this).val() == values[$(this).attr('id')]){
				$(this).val('');
			}
			if ($(this).attr('id')){
				//try show tooltip
				$('#tooltip_'+$(this).attr('id')).show();
			}

		});
		obj.blur(function(){
			if ($(this).val() == ''){
				$(this).val(values[$(this).attr('id')]);
				if ($(this).attr('id')){
					//try show tooltip
					$('#tooltip_'+$(this).attr('id')).hide();
				}
                $(this).parent().find('.prov').removeClass('good').addClass('bad');
			} else {
                $(this).parent().find('.prov').removeClass('bad').addClass('good');
            }
		});
	});
};

jQuery.fn.itonkeypress = function(options) {
	var options = jQuery.extend({
		                            type: 'numbers'
	                            },options);
	return this.each(function() {
		var obj = $(this);

		obj.keypress(function (e) {

			//Only numbers
			if (options.type == 'money'){

               if(!parseInt(obj.val())){
                   obj.val(0);
               } else {
                   obj.val(parseInt(obj.val()));
               }
				return !( e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57));
			}
            if (options.type == 'numbers'){
				return !( e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57));
			}
			//numbers + ()
			if (options.type == 'phone'){

				//43 +   40 (  41 )
				return !( e.which != 8 && e.which != 0 &&  e.which != 43  &&  e.which !=40 &&  e.which != 41 &&(e.which < 48 || e.which > 57));
			}
		});

	});
};


/*CHACKBOX*/
$(document).ready(function(){
     $(':checkbox').addClass('styled');
 })
/*

 CUSTOM FORM ELEMENTS

 Created by Ryan Fait
 www.ryanfait.com

 The only things you may need to change in this file are the following
 variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

 The numbers you set for checkboxHeight and radioHeight should be one quarter
 of the total height of the image want to use for checkboxes and radio
 buttons. Both images should contain the four stages of both inputs stacked
 on top of each other in this order: unchecked, unchecked-clicked,
 checked, checked-clicked.

 You may need to adjust your images a bit if there is a slight vertical
 movement during the different stages of the button activation.

 The value of selectWidth should be the width of your select list image.

 Visit http://ryanfait.com/ for more information.

 */

 var checkboxHeight = "18";
 var radioHeight = "22";
 var selectWidth = "190";


/* No need to change anything after this */


 document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');
 var custom_events_save = Object();
 var Custom = {
     init: function() {
         var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;

         for(a = 0; a < inputs.length; a++) {
             if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
                 if ($(inputs[a]).attr('id') != ''){
                     custom_events_save[$(inputs[a]).attr('id')] = {change:inputs[a].onchange, click:inputs[a].onclick};

                 }


                 span[a] = document.createElement("span");
                 span[a].className = inputs[a].type;

                 if(inputs[a].checked == true) {
                     if(inputs[a].type == "checkbox") {
                         position = "0 -" + (checkboxHeight*2) + "px";
                         span[a].style.backgroundPosition = position;
                     } else {
                         position = "0 -" + (radioHeight*2) + "px";
                         span[a].style.backgroundPosition = position;
                     }
                 }
                 inputs[a].parentNode.insertBefore(span[a], inputs[a]);
                 inputs[a].onchange = Custom.clear;
                 if(!inputs[a].getAttribute("disabled")) {
                     span[a].onmousedown = Custom.pushed;
                     span[a].onmouseup = Custom.check;
                 } else {
                     span[a].className = span[a].className += " disabled";
                 }
                 //inputs[a].click
             }

         }

         inputs = document.getElementsByTagName("select");
         for(a = 0; a < inputs.length; a++) {
             if(inputs[a].className == "styled") {
                 option = inputs[a].getElementsByTagName("option");
                 active = option[0].childNodes[0].nodeValue;
                 textnode = document.createTextNode(active);
                 for(b = 0; b < option.length; b++) {
                     if(option[b].selected == true) {
                         textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
                     }
                 }
                 span[a] = document.createElement("span");
                 span[a].className = "select";
                 span[a].id = "select" + inputs[a].name;
                 span[a].appendChild(textnode);
                 inputs[a].parentNode.insertBefore(span[a], inputs[a]);
                 if(!inputs[a].getAttribute("disabled")) {
                     inputs[a].onchange = Custom.choose;
                 } else {
                     inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
                 }
             }
         }
         document.onmouseup = Custom.clear;
     },
     pushed: function() {

         element = this.nextSibling;
         if(element.checked == true && element.type == "checkbox") {
             this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
         } else if(element.checked == true && element.type == "radio") {
             this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
         } else if(element.checked != true && element.type == "checkbox") {
             this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
         } else {
             this.style.backgroundPosition = "0 -" + radioHeight + "px";
         }
     },
     check: function() {

         element = this.nextSibling;

         if(element.checked == true && element.type == "checkbox") {
             this.style.backgroundPosition = "0 0";
            // element.checked = false;
             element.click();
         } else {
             if(element.type == "checkbox") {
                 this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
             } else {
                 this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
                 group = this.nextSibling.name;
                 inputs = document.getElementsByTagName("input");
                 for(a = 0; a < inputs.length; a++) {
                     if(inputs[a].name == group && inputs[a] != this.nextSibling) {
                         inputs[a].previousSibling.style.backgroundPosition = "0 0";
                     }
                 }
             }
             //element.checked = true;
             element.click();
         }
         if ($(element).attr('id') != ''){
             var func = custom_events_save[$(element).attr('id')];

             if (typeof(func.click) == 'function'){
                 try{
                     func.click();
                 }catch(e){

                 }
             }
             if (typeof(func.change) == 'function'){
                 try{
                     func.change();
                 }catch(e){

                 }
             }

         }
     },
     clear: function() {
         inputs = document.getElementsByTagName("input");
         for(var b = 0; b < inputs.length; b++) {
             try{
             if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
                 inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
             } else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
                 inputs[b].previousSibling.style.backgroundPosition = "0 0";
             } else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
                 inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
             } else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
                 inputs[b].previousSibling.style.backgroundPosition = "0 0";
             }
             }catch(e){}
         }
     },
     choose: function() {

         option = this.getElementsByTagName("option");
         for(d = 0; d < option.length; d++) {
             if(option[d].selected == true) {
                 document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
             }
         }
     }
 };
 window.onload = Custom.init;


