/**
 *  PrintArea Version 2.1
 */
(function($){var counter=0;var modes={iframe:"iframe",popup:"popup"};var defaults={mode:modes.iframe,popHt:500,popWd:400,popX:200,popY:200,popTitle:"",popClose:false};var settings={};$.fn.printArea=function(options){$.extend(settings,defaults,options);counter++;var idPrefix="printArea_";$("[id^="+idPrefix+"]").remove();var ele=getFormData($(this));settings.id=idPrefix+counter;var writeDoc;var printWindow;switch(settings.mode){case modes.iframe:var f=new Iframe();writeDoc=f.doc;printWindow=f.contentWindow||f;break;case modes.popup:printWindow=new Popup();writeDoc=printWindow.doc}writeDoc.open();writeDoc.write(docType()+"<html>"+getHead()+getBody(ele)+"</html>");writeDoc.close();printWindow.focus();printWindow.print();if(settings.mode==modes.popup&&settings.popClose){printWindow.close()}};function docType(){if(settings.mode==modes.iframe||!settings.strict){return""}var standard=settings.strict==false?" Trasitional":"";var dtd=settings.strict==false?"loose":"strict";return'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01'+standard+'//EN" "http://www.w3.org/TR/html4/'+dtd+'.dtd">'}function getHead(){var head="<head><title>"+settings.popTitle+"</title>";$(document).find("link").filter(function(){return $(this).attr("rel").toLowerCase()=="stylesheet"}).filter(function(){var media=$(this).attr("media");return(media.toLowerCase()==""||media.toLowerCase()=="print")}).each(function(){head+='<link type="text/css" rel="stylesheet" href="'+$(this).attr("href")+'" >'});head+="</head>";return head}function getBody(printElement){return'<body><div class="'+$(printElement).attr("class")+'">'+$(printElement).html()+"</div></body>"}function getFormData(ele){$("input,select,textarea",ele).each(function(){var type=$(this).attr("type");if(type=="radio"||type=="checkbox"){if($(this).is(":not(:checked)")){this.removeAttribute("checked")}else{this.setAttribute("checked",true)}}else{if(type=="text"){this.setAttribute("value",$(this).val())}else{if(type=="select-multiple"||type=="select-one"){$(this).find("option").each(function(){if($(this).is(":not(:selected)")){this.removeAttribute("selected")}else{this.setAttribute("selected",true)}})}else{if(type=="textarea"){var v=$(this).attr("value");if($.browser.mozilla){if(this.firstChild){this.firstChild.textContent=v}else{this.textContent=v}}else{this.innerHTML=v}}}}}});return ele}function Iframe(){var frameId=settings.id;var iframeStyle="border:0;position:absolute;width:0px;height:0px;left:0px;top:0px;";var iframe;try{iframe=document.createElement("iframe");document.body.appendChild(iframe);$(iframe).attr({style:iframeStyle,id:frameId,src:""});iframe.doc=null;iframe.doc=iframe.contentDocument?iframe.contentDocument:(iframe.contentWindow?iframe.contentWindow.document:iframe.document)}catch(e){throw e+". iframes may not be supported in this browser."}if(iframe.doc==null){throw"Cannot find document."}return iframe}function Popup(){var windowAttr="location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";windowAttr+=",width="+settings.popWd+",height="+settings.popHt;windowAttr+=",resizable=yes,screenX="+settings.popX+",screenY="+settings.popY+",personalbar=no,scrollbars=no";var newWin=window.open("","_blank",windowAttr);newWin.doc=newWin.document;return newWin}})(jQuery);
/*----------*/
function orderSubmit() {
    var ordform = document.getElementById('ordform');
    if((trimStr(ordform.flh.value)=="")||(trimStr(ordform.fdh.value)=="")||(trimStr(ordform.human.value)=="")||(trimStr(ordform.firm.value)=="")||(trimStr(ordform.adr.value)=="")||(trimStr(ordform.cont.value)=="")||(trimStr(ordform.phone.value)=="")||(trimStr(ordform.mphone.value)=="")||(trimStr(ordform.mail.value)==""))
    {
        alert('Не все обязательные для заполнения поля заполнены!');
        return;
    }
	if (ordform.email.value!="")
	{
		return;
	}
    alert('Ваша заявка отправлена.')
    ordform.submit();
}
function orderSubmit2() {
    var ordform = document.getElementById('ordform');
    if((trimStr(ordform.flh.value)=="")||(trimStr(ordform.fdh.value)=="")||(trimStr(ordform.spl.value)=="")||(trimStr(ordform.spd.value)=="")||(trimStr(ordform.spw.value)=="")||(trimStr(ordform.pri.value)=="")||(trimStr(ordform.roz.value)=="")||(trimStr(ordform.firm.value)=="")||(trimStr(ordform.adr.value)=="")||(trimStr(ordform.cont.value)=="")||(trimStr(ordform.phone.value)=="")||(trimStr(ordform.mphone.value)=="")||(trimStr(ordform.mail.value)==""))
    {
        alert('Не все обязательные для заполнения поля заполнены!');
        return;
    }
	if (ordform.email.value!="")
	{
		return;
	}
    alert('Ваша заявка отправлена.')
    ordform.submit();
}

function orderSubmit3() {
    var ordform = document.getElementById('ordform');
    if((trimStr(ordform.dat.value)=="")||(trimStr(ordform.nza.value)=="")||(trimStr(ordform.nob.value)=="")||(trimStr(ordform.ndo.value)=="")||(trimStr(ordform.firm.value)=="")||(trimStr(ordform.adr.value)=="")||(trimStr(ordform.cont.value)=="")||(trimStr(ordform.phone.value)=="")||(trimStr(ordform.mphone.value)=="")||(trimStr(ordform.mail.value)==""))
    {
        alert('Не все обязательные для заполнения поля заполнены!');
        return;
    }
	if (ordform.email.value!="")
	{
		return;
	}
    alert('Ваша заявка отправлена.')
    ordform.submit();
    
}
function trimStr (s) {
	s = s.replace(/^\s+/, '');
	for (var i = s.length - 1; i >= 0; i--) {
		if (/\S/.test(s.charAt(i))) {
			s = s.substring(0, i + 1);
			break;
		}
	}
	return s;
}
/*----------*/

$(function(){
	var trig = $('<img/>').attr('src','/public/themes/normal/images/open.png').css('position','absolute').css('left','-18px').css('padding','0').css('margin','0').css('height','24px').css('width','12px').css('border','0');
	$('div.tmenu li.pmenu ul').hide().parent().prepend(trig);
	$('div.tmenu li.pmenu img').click(function(){
		__swap($(this));
		var exclude = $(this).parent().children('ul');
		var exclude2 = $(this).parent().children('img');
		exclude.slideToggle(500);//animate({height:'toggle'});
		$(this).parent().parent().children('.pmenu').children('ul').not(exclude).slideUp(800);
		$(this).parent().parent().children('.pmenu').children('img').not(exclude2).attr('src','/public/themes/normal/images/open.png');
	}); /**/
	var re = /^\//gi;
	var active = $('div.tmenu a[href="'+'/'+(document.location.search?document.location.search:document.location.pathname.replace(re,''))+'"]');
	active.addClass('b').parent().addClass('a');
	__close(active.parent('.pmenu').parent('ul').parent('.pmenu').parent('ul').parent('.pmenu').parent('ul').parent('.pmenu').children('ul').slideDown(0).parent().children('img'));
	__close(active.parent('.pmenu').parent('ul').parent('.pmenu').parent('ul').parent('.pmenu').children('ul').slideDown(0).parent().children('img'));
	__close(active.parent('.pmenu').parent('ul').parent('.pmenu').children('ul').slideDown(0).parent().children('img'));
	__close(active.parent('.pmenu').children('ul').slideDown(800).parent().children('img'));/**/
	$('#gallink').click(function(e){
		e.preventDefault();
		//$(this).parent().children('#galfolder').click();
		//hs.expand($(this).parent().children('#galfolder'),config1);
	});
	$('#gsel').change(function(e){
		e.preventDefault();
		$('#gcontent').html('');
		gRender();
	});
	$(window).scroll(function(e) {
		if (getBodyScrollTop_ff() > 360 ) $("table.brd").addClass("fixed");
		else $("table.brd").removeClass("fixed");
	});
	
	$('div#print_button').click(function(){ $('.contmain').printArea(); });
	
	$('table.extend').next().prepend('<a href="javascript:void(0)">Добавить</a>').click(function(){
		var n=$('table.extend tr').size();
		$('table.extend tr.clone').parent().append('<tr><td>'+n+'<input size="20" name="t['+n+'][1]" type="hidden" value="'+n+'" /></td><td><input size="20" name="t['+n+'][2]" type="text" /></td><td><input size="30" name="t['+n+'][3]" type="text" /></td><td><input size="10" name="t['+n+'][4]" type="text" /></td><td><input size="30" name="t['+n+'][5]" type="text" /></td></tr>');
	});
})

function __swap(obj) {
	if ($(obj).attr('src')=='/public/themes/normal/images/open.png') $(obj).attr('src','/public/themes/normal/images/close.png');
	else if ($(obj).attr('src')=='/public/themes/normal/images/close.png') $(obj).attr('src','/public/themes/normal/images/open.png');
}

function __open(obj) {
	if ($(obj).attr('src')=='/public/themes/normal/images/close.png') $(obj).attr('src','/public/themes/normal/images/open.png');
}

function __close(obj) {
	if ($(obj).attr('src')=='/public/themes/normal/images/open.png') $(obj).attr('src','/public/themes/normal/images/close.png');
}

function gRender() {
	var gCurr = document.getElementById('gsel').value;
	for (var key in gData) {
		var val = gData[key];
		test = '/'+gCurr.replace(/\//g,'\\\/')+'/';
		if (val.search(test) != -1) {
			var img='<table class="gimg"><tr><td><a href="'+val.replace(/\/m\//,'/b/')+'" title="Нажмите для увеличения" class="highslide tr" onclick="return hs.expand(this,config2)"><img class="td" src="/'+val+'" alt="" /></a></td></tr></table>';
			$('#gcontent').append(img);
		}
	}
}

function getBodyScrollTop_ff()  
{  
     return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);  
}

