var language = new Object;

function calcPrice(obj) {
	if(!isNaN(obj.value)) {
		$('sum_'+obj.id).innerHTML = ($('price_'+obj.id).innerHTML * obj.value).toString(10).replace(/\.(..).*/,'.$1');
		var sum = 0;
		jQuery('[id^=sum_]').each(function() {	sum += parseFloat(this.innerHTML);	});
		$('summa').innerHTML = sum.toString(10).replace(/\.(..).*/,'.$1');
	}
}

jQuery(document).ready(function(){
	jQuery('#submit_order_souvenir').click(function(){
		if ($('summa').innerHTML=='0') alert('Выберите хотя бы одну позицию');
		else if ($('Company').value=='') alert('Введите название организации');
		else if (!$('Email').value.match(/^[\w\-\.]+\@[\w\-\.]+\.[a-z]{2,5}$/i)) alert('Введите email');
		else {
			var str = '';
			jQuery('input.calcPrice').each(function(){
				if (this.value && this.value>0) str += '&'+this.id+'='+this.value
			});
			jQuery.ajax({
				type: "POST",
				url: "/_admincp/_sections/_modules/souvenir/files/_ajax/send_order.php",
				data: "ID_Dealer="+$('ID_Dealer').value+"&Company="+$('Company').value+"&Comment="+$('Comment').value+"&Email="+$('Email').value+str,
				success: function(msg){
					jQuery('form#order_souvenir').html('Ваш заказ успешно отправлен');
				}
			});
		}
	});
});

// перерисовка страницы - чтобы браузеры не перло при динамическом изменении контента

function reloadPage() {

	document.body.style.display="inline";

	document.body.style.display="block";

//	Object.style.zIndex=32;

}


jQuery(document).ready(function() {
  jQuery( "#slider" ).accessNews({
    speed : "normal",
    slideBy : 2
  });
}); 


jQuery(document).ready(function() {
  jQuery( "#tags-show" ).click(function() {
    if (jQuery(this).hasClass('opened')) {
      jQuery('.cloud .tag-hidden').hide();
      jQuery(this).text('Все темы');
    } else {
      jQuery('.cloud .tag-hidden').show();
      jQuery(this).text('Популярные темы');
    }
    jQuery(this).toggleClass('opened');
    return false;
  });
}); 

// выбор страниц для отображения

function selectPage(current) {

	if (current.parentNode.className!="active") {

		var pos = current.href.lastIndexOf("#");

		where=current.href.slice(pos+1);

		where = document.getElementById(where);



		var nav = current.parentNode.parentNode.getElementsByTagName('li');

		for(var i=0; i<nav.length; i++) nav[i].className="";

		current.parentNode.className="active";



		nav = document.getElementById("parameters").getElementsByTagName('div');

		for(var i=0; i<nav.length; i++) {

			var navClass=nav[i].className;

			if (nav[i]==where) where.className+=" on";

			if (navClass.indexOf("object-page")!=-1) if(navClass.indexOf("on")!=-1) nav[i].className=navClass.replace("on", "");

		}

		reloadPage();

	}

	return false;

}





// выбор страниц для отображения

function selectPage1(current) {

	if (current.parentNode.className!="active") {

		var pos = current.href.lastIndexOf("#");

		where=current.href.slice(pos+1);

		where = document.getElementById(where);



		var nav = current.parentNode.parentNode.getElementsByTagName('li');

		for(var i=0; i<nav.length; i++) nav[i].className="";

		current.parentNode.className="active";



		nav = document.getElementById("parameters-model").getElementsByTagName('div');

		for(var i=0; i<nav.length; i++) {

			var navClass=nav[i].className;

			if (nav[i]==where) where.className+=" on";

			if (navClass.indexOf("object-page")!=-1) if(navClass.indexOf("on")!=-1) nav[i].className=navClass.replace("on", "");

		}

		reloadPage();

	}

	return false;

}



function showPopup(id,class_name) {


    if (id==0) {var sec_id=$('r_op').value;}


	var req = new JsHttpRequest();

	req.open(null, '/js/_ajax/popup.php', true);

	data = { id: id, class_name: class_name, sec_id: sec_id }

	req.send(data);

	req.onreadystatechange = function() {

		if (req.readyState == 4) {
			opened = $('opened_popup');

			if (id>0)
			if (opened!=null && opened.value > 0) {

				$('showpopup_'+opened.value).style.display = 'none';

				$('showpopup_'+opened.value).innerHTML = '';

			}

			opened.value = id;

			$('showpopup'+(id>0 ? '_'+id : '')).innerHTML = req.responseJS.html;

			$('showpopup'+(id>0 ? '_'+id : '')).style.display = 'block';

			//$('opened_popup').value = id;

		}

	}







	/*

	var new_height = document.getElementById(who).offsetHeight;

	var new_width = document.getElementById(who).offsetWidth;

	var top = (document.body.scrollTop>0) ? document.body.scrollTop : document.documentElement.scrollTop;

	document.getElementById(who).style.top = (parseInt(top,10)+(document.body.clientHeight/2)-(new_height/2)-500)+'px';

   	document.getElementById(who).style.left = ((document.body.clientWidth/2)-(new_width/2)-400)+'px';

	document.getElementById(who).style.display = "block";



	return false;

	*/

}

/*

showPopup2 = function(who, id) {

	var new_height = document.getElementById(who).offsetHeight;

	var new_width = document.getElementById(who).offsetWidth;

	var top = (document.body.scrollTop>0) ? document.body.scrollTop : document.documentElement.scrollTop;

	document.getElementById(who).style.top = (parseInt(top,10)+(document.body.clientHeight/2)-(new_height/2)-500)+'px';

   	document.getElementById(who).style.left = ((document.body.clientWidth/2)-(new_width/2)-400)+'px';

	document.getElementById(who).style.display = "block";

	$('answer').value = id;

	return false;

}

*/

closePopup = function(who) {

	$(who).style.display = "none";

	return false;

}

function set_op(id) {
	$('r_op').value=id;
}


