// JavaScript Document
$(document).ready(function(){
	$('form input[type=text]').focus(function(){
		if( $(this).val() == $(this).attr('alt') )  $(this).val(''); 								  
	});
    
	$('form input[type=text]').blur( function(){
		if( $.trim( $(this).val() ) == '' ) $(this).val($(this).attr('alt'));
	});
	
	/* Neem Contact Op */
	$(".contact form").find('input').each(function(){
		if( $(this).attr('type') == 'submit' ){ 
			$(this).addClass('call'); 
		}else { 
			$(this).attr('alt',$(this).val());
			if( $(this).attr('size') > 0 ){ $(this).addClass('required'); }
		}
	});
	
	$("form").submit(function(){
		var err = false;
		$(this).find('.required, td.required input').each(function(){
			if($(this).val() == $(this).attr('title')){
				$(this).addClass('error');
				err = true;
			}else if( $(this).hasClass('email') && validateEmail($(this).val())==false ) {
				$(this).addClass('error');
				err = true;
			}else{
				$(this).removeClass('error');
			}
		});
		
		if(err==true) return false;
   	});
	
	$('.option select').change(function(){
		$(this).prev().html($(this).find('option:selected').text());
	});
	
	/* end Neem Contact Op */
	
	/* newsletter */

	/* end newsletter */
	
	function validateEmail(val){
		var matchArray = val.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
		
		if (matchArray == null) {
			return false;
		} else {
			return true;
		}
	}
	
});


//extension methods
String.prototype.toCurrecyFormated = function(){

    amount = this;
    var i = parseFloat(amount);
    if(isNaN(i)) {
        i = 0.00;
    }
    var minus = '';
    if(i < 0) {
        minus = '-';
    }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) {
        s += '.00';
    }
    if(s.indexOf('.') == (s.length - 2)) {
        s += '0';
    }
    s = minus + s;

    amount = s;
    var delimiter = "."; // replace comma if desired
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if(isNaN(i)) {
        return '';
    }
    var minus = '';
    if(i < 0) {
        minus = '-';
    }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while(n.length > 3)
    {
        var nn = n.substr(n.length-3);
        a.unshift(nn);
        n = n.substr(0,n.length-3);
    }
    if(n.length > 0) {
        a.unshift(n);
    }
    n = a.join(delimiter);
    if(d.length < 1) {
        amount = n;
    }
    else {
        amount = n + ',-' ;
    }
    amount = minus + amount;
    return amount;
}

		
	function mouseOver(){
		document.getElementById("home").src="/bitrix/templates/index/components/bitrix/breadcrumb/dehypo.breadcrumb/images/2.png";
	}	
	
	function mouseOut(){
		document.getElementById("home").src="/bitrix/templates/index/components/bitrix/breadcrumb/dehypo.breadcrumb/images/1.png";
	}
		
