﻿
//Для капчи переводим в заглавные буквы
function setUppercase(){
    var input = document.getElementById('inputcode_secondaryid');
    input.value = input.value.toUpperCase();
    return  true;
}


// view div
function show(div) {
	el = document.getElementById(div);
	if (el)
	{
	if (el.style.display == "block")
		el.style.display = "none";
	else
		el.style.display = "block";
	}
}

// проверка паролей
function  checkpass(obj)
{
	if (!obj || obj.registration_pass.value !=obj.registration_confirmpass.value)
	{
		alert("Пароли не совпадают!");
		return false;
	 }
	return true;
}

//корректность почты
function validateemail(form)
{
    var email=form.registration_postaddr;
	email_val = email.value;
    var reg=new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,4}", 'i');
    if (!reg.test(email_val))
	{
		show("winalert");
		email.focus();
		return false;
    }
	return true;
}

function checkRegForm(form)
{
	if (validateemail(form) && checkpass(form))
	return true;
return false;
}

//
function  validate(obj){
	return true;
}

// change bg
function ChangeBGColor(ID, BG, COLOR) {
	document.getElementById(ID).style.background=BG;   
	(COLOR) ? document.getElementById(ID).style.color=COLOR:document.getElementById(ID).style.color='#ffffff';
}

// подсветка
 var tmp;
 function heightLightTR(obj)
 {
  if(tmp)tmp.style.backgroundColor='#ffffff';
  obj.style.backgroundColor='#e6e6e6';
  tmp=obj; 
 }

// newwindow

function OpenWindowImage (url,alt,width,height) {
	wnd1 = null;
	var url = url || '';
	var alt = alt || '';
	var width = width || 556;
	var height = height-19 || 800;
	var size = 'width='+width+',height='+height;
	wnd1 = window.open(url,'wfloat1',size+'toolbar=no,menubar=yes,scrollbars=yes,status=no,resizable=yes');
	wnd1.document.open();
	wnd1.document.write("<html><head><script>function resize(){");
	wnd1.document.write("self.resizeTo (photo.width+30,photo.height+52); } onload=resize;");
	wnd1.document.write("</script><title>Увеличенное изображение — Строительный Торговый Дом «Петрович»</title></head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src='"+url+"' alt='"+alt+"' border='0' vspace='0' hspace='0' id='photo'/><body></html>");
  wnd1.document.close();
}

function wfloat5 (url,target,size) {
var wWidth=860;
var wHeight=642;
var cWidth=window.screen.width;
var cHeight=window.screen.height;
if(cHeight && cWidth){
	var leftOffset=Math.ceil((cWidth-wWidth)/2);
	var topOffset=Math.ceil((cHeight-wHeight)/2);
	var size = size || 'width=860,height=642';
	var target = target || 'wfloat5';
	openwnd = window.open(url,target,'width='+wWidth+',height='+wHeight+'location=no,toolbar=no,resizable=no,menubar=no,status=no,scrollbars=no,top='+topOffset+',left='+leftOffset);
	openwnd.document.open();

 }
return false;
}

//случайный bg
function GetImg()
{
var trow;
var dice;
var dd;
var way = "../images/bg/";
for (trow=0; trow <1; trow++)
	{
		dice = (Math.floor(Math.random()*4)+1);
		dd = ("bg" + dice);
		//alert(dd);
	}
return dd;
}
	
// смена картинки
function ChangeImg()
   {
    if(document.images)
      {
       
eval("document."+ChangeImg.arguments[0]+
".src=('"+ChangeImg.arguments[1]+"')");
      }
    }
	
// перенаправление
function bodyOnLoad() 
	{
	window.setTimeout(goToCustomer, 15000); 
	}
function goToCustomer() 
	{
window.location.href = "/customer.xml"; 
	}
	














	
	
//
function OpenWindowImage2 (url,alt,width,height) {
	wnd1 = null;
	var url = url || '';
	var alt = alt || '';
	var width = width || 850;
	var height = height-19 || 300;
	var size = 'width='+width+',height='+height;
	wnd1 = window.open(url,'wfloat1',size+'toolbar=no,menubar=yes,scrollbars=yes,status=no,resizable=yes');
	wnd1.document.open();
	wnd1.document.write("<html><head><script>function resize(){");
	wnd1.document.write("self.resizeTo (photo.width+30,photo.height+52); } onload=resize;");
	wnd1.document.write("</script><title>Год с Петровичем — Строительный Торговый Дом «Петрович»</title></head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 ><img src='"+url+"' alt='"+alt+"' border='0' vspace='0' hspace='0' id='photo'/><body></html>");
  wnd1.document.close();
}

function OpenWindowImage3 (url,alt,width,height) {
	wnd1 = null;
	var url = url || '';
	var alt = alt || '';
	var width = width || 300;
	var height = height-19 || 300;
	var size = 'width='+width+',height='+height;
	wnd1 = window.open(url,'wfloat1',size+'toolbar=no,menubar=yes,scrollbars=yes,status=no,resizable=yes');
	wnd1.document.open();
	wnd1.document.write("<html><head><script>function resize(){");
	wnd1.document.write("self.resizeTo (photo.width+30,photo.height+52); } onload=resize;");
	wnd1.document.write("</script><title>Комиксы — Строительный Торговый Дом «Петрович»</title></head><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src='"+url+"' alt='"+alt+"' border='0' vspace='0' hspace='0' id='photo'/><body></html>");
  wnd1.document.close();
}


function thumsImage(obj, stat){
    var divList = obj.getElementsByTagName('div');
    var div;
    for (i=0;i<divList.length;i++)
        if(divList[i].className=='image')
            div = divList[i];
    if (div)
        div.style.display = stat;
    
}

$(document).ready(function(){

	$('.gmaps a').click(function(){
	
		$tid = $(this).attr('id').substr(1);
		$x = $(this).attr('x');
		$y = $(this).attr('y');
		load($x,$y);
		$('.print-map').attr('href', $(this).attr('href'));
		return false;	
	
	});
	
	$('.print-map').click(function(){
		window.open($(this).attr('href'),'wfloat1','width=800, height=600,'+'toolbar=no,menubar=yes,scrollbars=yes,status=no,resizable=yes');
		return false;
	})
	
	$('#city_chooser a').click(function(){
		$cid = $(this).attr('id').substr(1);
		$('#city_chooser li').removeClass('active');
		$(this).parent().addClass('active');
		$('#city_catalogs > div').addClass('off');
		$('#city'+$cid).removeClass('off');
		return false;
	});
	
	$('.opentraining').click(function(){
		$(this).parent().children('.trainings').toggleClass('off');
		return false;
	})
	
});

