function show_advance_search(){
	if ($('adv_search_div').style.height=='100px'){
		$('adv_search_div').style.height='65px';
		$('adv_search_a').style.visibility = 'visible';
	}
	else{
		$('adv_search_div').style.height='100px';
		$('adv_search_a').style.visibility = 'hidden';
	}
	
	return false;
}

function show_advance_search2(a){
	if ($('adv_search_div').style.height=='100px'){
		$('adv_search_div').style.height='60px';
		$('adv_search_a').style.visibility = 'visible';
	}
	else {
		$('adv_search_div').style.height='100px';
		$('adv_search_a').style.visibility = 'hidden';
	}
	
	return false;
}

function load_ch_section(section){
	id = section.options[section.selectedIndex].value;
	len = sections[id]['id'].length;
	ch_section_select = $('ch_section');
	while (ch_section_select.options[0]){
		ch_section_select.options[0] = null;
	}
	
	for (i=0;i<len;i++){
		insertOption(ch_section_select,sections[id]['id'][i],sections[id]['v'][i])
	}
	
}

function insertOption(section,value,title)
{
var option=document.createElement('option');
option.text=title;
option.value=value;
try
  {
  section.add(option,null); // standards compliant
  }
catch(ex)
  {
  section.add(option); // IE only
  }
}

function select_checkbox_ticket(ch){
if (ch.checked == true){
	count_selected_tickets++;
	$('count_selected').update(count_selected_tickets);
} else {
	count_selected_tickets--;
	if (count_selected_tickets<0) count_selected_tickets = 0;
	$('count_selected').update(count_selected_tickets);
}
}

function set_all_tickets(){
	i=1;
	count_selected_tickets=0;
	while($('select_ticket_'+i)){
		$('select_ticket_'+i).checked=true;
		count_selected_tickets++;
		i++;
	}
	$('count_selected').update(count_selected_tickets);
}

function clear_all_tickets(){
	i=1;
	count_selected_tickets=0;
	while($('select_ticket_'+i)){
		$('select_ticket_'+i).checked=false;
		i++;
	}
	$('count_selected').update(count_selected_tickets);
}

function update_view_tickets(){
	$('view_tickets_form').action = '/catalog/tickets/view_selected';
	$('view_tickets_form').submit();
}

function sort_form(field,dir){
	sort = field+','+dir;
	$('sort_input').value = sort;
	$('id_list_input').update('');
	$('view_tickets_form').action = '/catalog/tickets/view_selected';
	$('view_tickets_form').submit();
}

function show_adv_tickets(){
	$('adv_tickets_form').style.display = 'block';
	$('adv_firm_form').style.display = 'none';
}

function show_adv_firm(){
	$('adv_tickets_form').style.display = 'none';
	$('adv_firm_form').style.display = 'block';
}

function open_window(href,param){
if (param=="") param = 'width=990,height=590,top=10,left=10, resizable=no,scrollbars=no';
myWindow=window.open(href,'',param);
myWindow.focus();
return false;
}

function check_email(email){
 emailTest = "^[\\.0-9a-zA-Z_-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+\\.)+[a-zA-Z]{2,4}$"; 
   var regex = new RegExp(emailTest); 
  // email  = email.toLowerCase();
   if (regex.test(email)) {
      return true;
   } else {
      return false;
   }
}

//Добавить событие на onload
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
	    window.onload = func; 
	} else { 
		window.onload = function() { 
			if (oldonload) { 
				oldonload(); 
			} 
			func(); 
	    } 
	} 
}

function check_phone(phone){var r=/[0-9]{6,15}/;if(!r.test(phone))return false;return true;}

function ask_ticket_quest(){
	if (_trim($('text').value)=='') {
		$('text').focus();
		alert('Введите текст');
		return false;
	}	
	
	if (_trim($('name').value)=='') {
		$('name').focus();
		alert('Введите Ваше имя');
		return false;
	}

	if (!check_phone($('phone').value)) {
		$('phone').focus();
		alert('Введен некоректный телефон. Необходимо вводить только цифры, не менее 6 символов, без пробелов и черточек');
		return false;
	}
	
	if (!check_email($('email').value)) {
		$('email').focus();
		alert('Введен некоректный Email');
		return false;
	}
	return true;
}

function add_company_comment(){
	if (_trim($('text').value)=='') {
		$('text').focus();
		alert('Введите текст');
		return false;
	}	
	
	if (_trim($('name').value)=='') {
		$('name').focus();
		alert('Введите Ваше имя');
		return false;
	}

	if (!check_email($('email').value)) {
		$('email').focus();
		alert('Введен некоректный Email');
		return false;
	}
	return true;
}

function select_type_order(select){ 
$('photo_1').style.display = 'none';
$('photo_2').style.display = 'none';
$('photo_3').style.display = 'none';
$('id_youtube').style.display = 'none';
switch (select){
case '9': 
	$('div_format').update('** Если файлов много - поместите их в один архив. <br/>*** Формат файла: <b>*.xls,*.rar,*.zip</b>');
	$('select_file').style.display = 'table-row';
	break;
case '0': 
	$('div_format').update('** Формат файла: <b>*.jpg</b>');
	$('select_file').style.display = 'table-row';
	break;
case '1': 
	$('div_format').update('** Если файлов много - поместите их в один архив. <br/>*** Формат файла: <b>*.html,*.rar,*.zip,*.doc</b>');
	$('select_file').style.display = 'table-row';
	break;
case '2': 
	$('photo_1').style.display = 'table-row';
	$('photo_2').style.display = 'table-row';
	$('photo_3').style.display = 'table-row';
	$('select_file').style.display = 'none';
	break;
case '3': 
	$('id_youtube').style.display = 'table-row';
	$('select_file').style.display = 'none';
	break;
case '4': 
	$('div_format').update('** Формат файла: <b>*.xls,*.rar,*.zip,*.doc</b>');
	$('select_file').style.display = 'table-row';
	break;
default : $('div_format').update('Только *.xls,*.rar,*.zip,*.jpg,*.doc');
}
}

function check_mobile(m){var r=/^\+{1}[0-9]{11}/;if(!r.test(m))return false;return true;}
//function check_email(email){var r=/[0-9|a-z|_]+@{1}[0-9a-z_]+\.{1}[a-z]{2,3}/;if(!r.test(email))return false;return true;}
/*function check_email2(email){
 emailTest = "^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$"; 
   var regex = new RegExp(emailTest); 
   if (regex.test(email)) {
      return true;
   } else {
      return false;
   }
}*/
	function open_div(url,even){
		
		/*if(isIE){
			open_window(url+'&ie=1'+'&r='+parseInt(Math.random() * 99999999),"");
		} else {*/
			url = url+'&r='+parseInt(Math.random() * 99999999);

			$('change_content').style.display='block';

			show_content_for_hide('change_content');

			new Ajax.Updater('change_content',url, {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'change_content']});
		//}
	}
	
	function close_div(){
		$("change_content").update(""); 
		$("change_content").style.display="none";
		hide_content_for_hide("change_content");
	}
	
	function show_forgot(){
		if ($("forgot_password_div").style.display=='none')
			$("forgot_password_div").style.display='block';
		else
			$("forgot_password_div").style.display = 'none';
	}
	
	function check_forgot_password(){
		if (_trim($('company_name').value)=='') {
			$('company_name').focus(); alert('Введите название фирмы');return false;
		}		
		if (_trim($('contact_name').value)=='') {
			$('contact_name').focus(); alert('Введите Ваше имя');return false;
		}		
		if (!check_phone($('phone_forgot').value)) {
			$('phone_forgot').focus();
			alert('Введен некоректный телефон. Необходимо вводить только цифры, не менее 6 символов, без пробелов и черточек');
			return false;
		}
		if (!check_email($('email_forgot').value)) {
			$('email_forgot').focus();
			alert('Введен некоректный Email');
			return false;
		}
		return true;
	}
	
	function submit_forgot_password(ev,id_button){
		if (check_forgot_password()){
			if (!ev) var ev = window.event;
			new Ajax.Updater('forgot_password_div','/user/users/forgot_password', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'forgot_password_div']});
		}
	}	
	
	function submit_quest_form(ev,id_button){
		if (ask_ticket_quest()){
			if (!ev) var ev = window.event;
			new Ajax.Updater('change_content','/company/companies/ask_quest', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'change_content']});
		}
	}	
	
	function submit_ticket_quest_form(ev,id_button){
		if (ask_ticket_quest()){
			if (!ev) var ev = window.event;
			new Ajax.Updater('change_content','/company/companies/ask_ticket_quest', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'change_content']});
		}
	}	
	
	function submit_ticket_zakaz_form(ev,id_button){
		if (ask_ticket_quest()){
			if (!ev) var ev = window.event;
			new Ajax.Updater('change_content','/company/companies/zakaz_ticket_quest', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'change_content']});
		}
	}	
	
	function submit_comment_form(ev,id_button){
		if (add_company_comment()){
			if (!ev) var ev = window.event;
			new Ajax.Updater('change_content','/company/companies/add_comment', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'change_content']});
		}
	}
	
	function submit_login_form(ev,id_button){
		if (!ev) var ev = window.event;
		new Ajax.Updater('error_message_login','/user/users/login?ajax=1', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'error_message_login']});
		
	}	
	
	function submit_order_new_form(ev,id_button){
		if (!ev) var ev = window.event;
		new Ajax.Updater('change_content','/company/companies/order_new', {asynchronous:true, evalScripts:true, parameters:Form.serialize(Event.element(ev).form), requestHeaders:['X-Update', 'change_content']});
		
	}	
	
	function select_method_chat(){
		if ($('method_of_chat_1').checked==true) {
			sh_o=window.open;
			sh_o('https://siteheart.com/webconsultation/320333?', 'siteheart_sitewindow_320333', 'width=550,height=400,top=30,left=30,resizable=yes');
		}
		if ($('method_of_chat_2').checked==true) {
			window.location.href='skype:gorspravka077?chat';
		}
		if ($('method_of_chat_3').checked==true) {
			window.location.href='skype:gorspravka077?call';
		}
		close_div();
	}

	function animate(string_text){
	//alert('d');
		eadt = $('effect_add_to_cart');
		if (string_text!="")
			eadt.innerHTML = string_text;
			//eadt.update(string_text);
		//eadt.style.top=(defPosition(even).y-400)+"px";
		
		w=Math.max(eadt.offsetWidth,eadt.scrollWidth);
		h=Math.max(eadt.offsetHeight,eadt.scrollHeight);

		if(w==0)w=300;if(h==0)h=80;
		eadt.style.top=(((getViewportHeight()/2-h/2)>0)?(getViewportHeight()/2-h/2):0)+"px";
		
		Effect.toggle('effect_add_to_cart','appear');
		setTimeout("hide_animate()",2500);
	}
	function hide_animate(){
		Effect.toggle('effect_add_to_cart','appear');
	}


	function quick_search(value){
		new Ajax.Updater('pre_search_div','/catalog/tickets/pre_search_line?keyword='+Url.encode(value), {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'pre_search_div']});
	}
	
	function defPosition(event) {
    var x = y = 0;
    if (document.attachEvent != null) { // Internet Explorer & Opera
        x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    } else if (!document.attachEvent && document.addEventListener) { // Gecko
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    } else {
        // Do nothing
    }
    return {x:x, y:y};
	}
	
	
	

	
	
var opacity_element=1;function fading(id,delta_opacity,delta_time,after_fading){opacity_element-=delta_opacity;if(opacity_element>=0){setElementOpacity(document.getElementById(id),opacity_element);setTimeout(function(){fading(id,delta_opacity,delta_time,after_fading)},delta_time);}else{opacity_element=1;document.getElementById(id).style.display="none";setElementOpacity(document.getElementById(id),1);setTimeout(after_fading,0);}}
var opacity=0.7;var current_hide_element_id="";
function show_content_for_hide(hide_element_id){
	page_objects = document.getElementsByTagName("object");
	for (i = 0; i < page_objects.length; i++) {   
		page_objects[i].style.visibility='hidden';//visible
	}  
	current_hide_element_id=hide_element_id;
	if(document.body) document.body.scrollTop=0;
	if(document.documentElement) document.documentElement.scrollTop=0;
	opacity=0.7;
	document.getElementById("hide_body").style.display="block";
	if(isIE){if(document.getElementById("hide_frame")){document.getElementById("hide_frame").style.display="block";document.getElementById("hide_frame").style.height=getDocumentHeight()+"px";document.getElementById("hide_frame").style.width=getDocumentWidth()+"px";}}
	document.getElementById("hide_body").style.height=getDocumentHeight()+"px";
	document.getElementById("hide_body").style.width=getDocumentWidth()+"px";
	setElementOpacity(document.getElementById("hide_body"),opacity);
	document.getElementById(hide_element_id).style.display="block";
	w=Math.max(document.getElementById(hide_element_id).offsetWidth,document.getElementById(hide_element_id).scrollWidth);
	h=Math.max(document.getElementById(hide_element_id).offsetHeight,document.getElementById(hide_element_id).scrollHeight);

	if(w==0)w=800;if(h==0)h=400;
	if(isIE)
	document.getElementById(hide_element_id).style.top='100px';
	else
	document.getElementById(hide_element_id).style.top=(((getViewportHeight()/2-h/2)>0)?(getViewportHeight()/2-h/2):0)+"px";
	document.getElementById(hide_element_id).style.left=(((getViewportWidth()/2-w/2)>0)?(getViewportWidth()/2-w/2):0)+"px";setElementOpacity(document.getElementById(hide_element_id),1);
}

window.onresize=function(){if(document.getElementById("hide_body")){document.getElementById("hide_body").style.height=getDocumentHeight()+"px";document.getElementById("hide_body").style.width=getDocumentWidth()+"px";}
if(document.getElementById(current_hide_element_id)){w=Math.max(document.getElementById(current_hide_element_id).offsetWidth,document.getElementById(current_hide_element_id).scrollWidth);h=Math.max(document.getElementById(current_hide_element_id).offsetHeight,document.getElementById(current_hide_element_id).scrollHeight);if(w==0)w=800;if(h==0)h=400;document.getElementById(current_hide_element_id).style.top=(((getViewportHeight()/2-h/2)>0)?(getViewportHeight()/2-h/2):0)+"px";document.getElementById(current_hide_element_id).style.left=(((getViewportWidth()/2-w/2)>0)?(getViewportWidth()/2-w/2):0)+"px";}};function none(){}
function hide_content_for_hide(hide_element_id){
	page_objects = document.getElementsByTagName("object");
	for (i = 0; i < page_objects.length; i++) {   
		page_objects[i].style.visibility='visible';//hidden
	}  
setTimeout('none()',10);if(opacity>0){setElementOpacity(document.getElementById("hide_body"),opacity);setElementOpacity(document.getElementById(hide_element_id),opacity);opacity-=0.2;setTimeout('hide_content_for_hide("'+hide_element_id+'")',50);return;}else{if(isIE){if(document.getElementById("hide_frame")){document.getElementById("hide_frame").style.height="0px";document.getElementById("hide_frame").style.width="0px";document.getElementById("hide_frame").style.display="none";}}
document.getElementById("hide_body").style.display="none";document.getElementById(hide_element_id).style.display="none";return;}}

var ua=navigator.userAgent.toLowerCase();var isOpera=(ua.indexOf('opera')>-1);var isIE=(!isOpera&&ua.indexOf('msie')>-1);function getDocumentWidth(){return Math.max(document.compatMode!='CSS1Compat'?document.body.scrollWidth:document.documentElement.scrollWidth,getViewportWidth());}
function getViewportWidth(){return((document.compatMode||isIE)&&!isOpera)?(document.compatMode=='CSS1Compat')?document.documentElement.clientWidth:document.body.clientWidth:(document.parentWindow||document.defaultView).innerWidth;}
function getDocumentHeight(){return Math.max(document.compatMode!='CSS1Compat'?document.body.scrollHeight:document.documentElement.scrollHeight,getViewportHeight());}
function getViewportHeight(){return((document.compatMode||isIE)&&!isOpera)?(document.compatMode=='CSS1Compat')?document.documentElement.clientHeight:document.body.clientHeight:(document.parentWindow||document.defaultView).innerHeight;}
function setElementOpacity(sElemId,nOpacity)
{var opacityProp=getOpacityProperty();var elem=sElemId;if(!elem||!opacityProp)return;if(opacityProp=="filter")
{nOpacity*=100;var oAlpha=elem.filters['DXImageTransform.Microsoft.alpha']||elem.filters.alpha;if(oAlpha)oAlpha.opacity=nOpacity;else elem.style.filter+="progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";}
else
elem.style[opacityProp]=nOpacity;}
function getOpacityProperty(){
if(typeof document.body.style.opacity=='string')
return'opacity';else if(typeof document.body.style.MozOpacity=='string')
return'MozOpacity';else if(typeof document.body.style.KhtmlOpacity=='string')
return'KhtmlOpacity';else if(document.body.filters&&navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5)
return'filter';return false;}
	
if (typeof force == 'undefined'){
alert("g");
document.ondragstart = test;
document.onselectstart = test;
document.oncontextmenu = test;
document.body.oncontextmenu="notmenu();"
var mymessage = "-----";
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = rtclickcheck;
}
function test() {return false;}

function notmenu() { window.event.returnValue=false; }
 function rtclickcheck(keyp){
  if (document.layers && keyp.which != 1) {
    alert(mymessage);
    return false;
  }
  if (document.all && event.button != 1) { 
    alert(mymessage);
    return false;
  }
}
