function popup_window( id, width, height ) {
	if (!width) width = 900;
	if (!height) height = 800;
	wnd = window.open( "/prod_popup.php?id=" + id, "_blank", "width="+width+",height="+height+",status=1,toolbar=0,resizable=1,scrollbars=1,menubar=1");
	wnd.focus();
}

function popup_delivery( id, width, height, obj ) {
	if (!width) width = 900;
	if (!height) height = 800;
	var c = absPosition(obj);
	wnd = window.open( "/delivery_cost/?id=" + id, "_blank", "width="+width+",height="+height+",left="+c.x+", top="+c.y+",status=0,toolbar=0,resizable=0,scrollbars=0,menubar=0");
	wnd.focus();
}

function arr_oo()
{
	var obj = $('#arr_cont');

	if ( obj.attr('class') == 'arr_off') 
	{
		obj.attr('class', 'arr_on');
	} else {
		obj.attr('class', 'arr_off');
	}	
}

function absPosition(obj) {
      var x = y = 0;
      do {
            x += obj.offsetLeft;
            y += obj.offsetTop;
			//alert(obj.offsetTop);
            obj = obj.offsetParent;
      } while(obj);
	  
      return {x:x, y:y};
} 

function open_poll( one )
{
	act = document.pollform.act.value;
	poll_id = document.pollform.poll_id.value;
	
	if( one == "1" ) { // radio
		q = "&q=" + get_radio_value( document.pollform.q );
	}
	
	if( one == "0" ) { // checkbox
		q = get_checkbox_values( document.pollform ); 
	}
	
	wnd = window.open( "/poll_action.php?act="+act+"&poll_id=" + poll_id + q, "_blank", "width=300,height=150,status=0,toolbar=0,resizable=0,scrollbars=0,menubar=0");
	wnd.focus();
}

var partners = new Array
(
	"http://www.7pd.ru",
	"http://www.enkatsu.ru",
	"http://www.ju-jutsu.ru",
	"http://www.mobiledart.ru",
	"http://www.kenkorussia.ru",
	"http://www.easycopy.ru",
	"http://www.greenquark.ru",
	"http://www.sandisk.ru",
	"http://www.sigmalens.ru",
	"http://www.slikrussia.ru",
	"http://www.tamracrussia.ru",
	"http://www.dvestnik.ru"
);

var clubs = new Array
(
	"http://club.foto.ru/info/articles/",
	"http://club.foto.ru/info/articles/",
	"http://club.foto.ru/school/",
	"http://club.foto.ru/guide/",
	"http://club.foto.ru/forum/",
	"http://club.foto.ru/camera/",
	"http://club.foto.ru/lab/",
	"http://club.foto.ru/studios/",
	"http://club.foto.ru/secondhand/"
);

var forums = new Array
(
	"http://club.foto.ru/forum/view_forum.php?f_id=11",
	"http://club.foto.ru/forum/view_forum.php?f_id=6",
	"http://club.foto.ru/forum/view_forum.php?f_id=5",
	"http://club.foto.ru/forum/view_forum.php?f_id=4",
	"http://club.foto.ru/forum/view_forum.php?f_id=3",
	"http://club.foto.ru/forum/view_forum.php?f_id=9",
	"http://club.foto.ru/forum/view_forum.php?f_id=10",
	"http://club.foto.ru/forum/view_forum.php?f_id=2"
)

function go_partner( id ) { window.location = partners[id]; }
function go_club( id ) { window.location = clubs[id]; }
function go_forum( id )	{ window.location = forums[id]; }
function go_mforum() { window.location = "http://club.foto.ru/forum/"; }

function open_claim(){
	name = document.claimform.name.value;
	email = document.claimform.email.value;
	phone = document.claimform.phone.value;
	comment = document.claimform.comment.value;
		
	wnd = window.open( "/claim_action.php?name="+name+"&email=" +email+"&phone=" +phone+"&comment=" +comment, "_blank", "width=300,height=150,status=0,toolbar=0,resizable=0,scrollbars=0,menubar=0");
	wnd.focus();
}

function get_radio_value( obj ) {
	var i=0; var q=0;
    while((i<obj.length)&&(obj[i].checked!=1)) {i++;}
   	if (i!=obj.length) q =obj[i].value;
	return q;
}

function get_checkbox_values( obj )
{
 	var ret="";

	for( i = 0; i < obj.elements.length; i++ )
	{
		var item=obj.elements[i];
		if( item.checked==true && item.value > 0 ) ret = ret + "&q[]=" + item.value;
	}
	return ret;
}

function open_compare(product_id) {
	wnd = window.open( '/compare.php?action=add&id=' + product_id,  '_compare' ); 
	wnd.focus();
}

var imgname = "";
var description = "";
var pwidth = 0;
var pheight = 0;

function start_window(img, desc, width, height)
{
	var x = width+20;
	var y = height+70;
	
	nw = window.open("/popup_map.html", "_blank", "width="+x+",height="+y+",status=no,toolbar=no,menubar=no");

    imgname=img;
    description=desc;
	pwidth=width;
	pheight=height;
}

//home page stuff
if( document.images ) { version = "n3"; } else { version = "x"; }

if( version == "n3" ) {
	p1on = new Image(92,92);
	p1on.src = "/images/cat_red.gif";
	p1off = new Image(92,92);
	p1off.src = "/images/cat_blue.gif";
}

function img_act(obj) {
	if( version == "n3" ) {
		obj.style.backgroundImage = eval("'url("+p1on.src+")'");
		obj.style.cursor = 'hand';
		obj.style.backgroundRepeat = "no-repeat"; 
	}
}

function img_inact(obj) {
	if( version == "n3" ) {
		obj.style.backgroundImage = eval("'url("+p1off.src+")'");
		obj.style.backgroundRepeat = "no-repeat"; 
	}
}


//Ї®Є § ў Їа ў®© Є®«®­ЄҐ бЇЁбЄ  в®зҐЄ, Ј¤Ґ в®ў а Ґбвм
function show_exist(city_id)
{
	s = document.getElementById('exist'+city_id).style;
	d = document.getElementById('n_exist'+city_id).style;

	if (s.display == 'none')
	{
		s.display = 'block';
		d.display = 'none';
	}
	else 
	{
		s.display = 'none';
		d.display = 'block';
	}
}

function close_all()
{
	s = document.getElementById('tenderf').style;
	s.display = 'none';
	s2 = document.getElementById('errorf').style;
	s2.display = 'none';
}

function show_div( id )
{
	close_all();

	s = document.getElementById(id).style;

	if (s.display == 'block')
	{
		s.display = 'none';
	}
	else 
	{
		s.display = 'block';
		document.location.replace( "#"+id );
		//scrollTo(id);
	}
}

function show_div3( id )
{
	s = document.getElementById(id).style;

	if (s.display == 'block')
	{
		s.display = 'none';
	}
	else 
	{
		s.display = 'block';
	}
}

function show_div2( id )
{
	s = document.getElementById(id).style;
	s.display = 'block';
}

function hide_div2( id )
{
	s = document.getElementById(id).style;
	s.display = 'none';
}

function hide_div3( id )
{
	s = document.getElementById(id).style;
	s.visibility = 'hidden';
}

function showicq($id)
{
	if( $('#'+$id).is(':visible') )
	{
		$('.icqrb').hide();
	}
	else
	{
		$('.icqrb').hide();
		show_div3( $id );
	}
}

function show_all($id)
{
	if( $('.'+$id).is(':visible') )
	{
		$('.'+$id).hide();
	}
	else
	{
		$('.'+$id).show();
	}
}

//Ўл«® ў html_page.inc
var src_st;
function header_over(c)
{
	src_st = c.style["backgroundColor"];
	c.style["backgroundColor"] = "#FF9900";
	c.style['cursor'] = 'pointer';
}

function header_out(c)
{
	c.style['cursor'] = 'inherit';
    if (src_st != null) c.style["backgroundColor"] = src_st;
}

function checkClaim() {
	var error = '';
	var obj = document.claimform;
	if ( obj.uname.value == '' ) error += __warning_empty( 'Ф.И.О.' );
	if ( obj.email.value == '' ) error += __warning_empty( 'E-mail' );
	if ( obj.comment.value == '' ) error += __warning_empty( 'Сообщение' );
	if ( obj.email_id.value == 0 ) error += __warning_empty( 'Причина обращения' );

	return __check( error, obj );
}

function checkTender() {
	var error = '';
	var obj = document.tenderform;
	if ( obj.ufirm.value == '' ) error += __warning_empty( 'Наименование фирмы(сайта)' );
	if ( obj.ucost.value == '' ) error += __warning_empty( 'Цена' );
	if ( obj.uname.value == '' ) error += __warning_empty( 'Ваше имя' );
	if ( obj.ucontact.value == '' ) error += __warning_empty( 'Контактная информация' );

	return __check( error, obj );
}

function checkCall() {
	var error = '';
	var obj = document.callform;
	if ( obj.uname.value == '' ) error += __warning_empty( 'Ваше имя' );
	if ( obj.ucontact.value == '' ) error += __warning_empty( 'Телефон' );
	return __check( error, obj );
}

function checkDmoroz()
{
	var error = '';
	var obj = document.dmorozform;
	if ( obj.uname.value == '' ) error += __warning_empty( 'Ваше имя' );
	if ( obj.utel.value == '' ) error += __warning_empty( 'Телефон' );
	if ( obj.uemail.value == '' ) error += __warning_empty( 'Email' );
	return __check( error, obj );
}

function check_email(str) {
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}

	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		
	//var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r1 = new RegExp("(@.*@)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
} 

function __warning_empty( name ) {
	return ' - Поле \'' + name + '\' не может быть пустым!\n';
}

function __warning_len( name, len ) {
	return ' - В поле \'' + name + '\' не может быть больше ' + len + ' символов!\n';
} 

function __check( error, object ) {
	if ( error != '' ) { alert( 'Внимание!\n\n' + error ); return false; } 
	else { return true; }
}

$(document).ready(function () 
{
	var prpic = $('.prpic');
	if (prpic.length > 0) {
		prpic.lightBox({
			fixedNavigation:true,
			overlayBgColor:'#000',
			overlayOpacity:0.6,
			imageLoading:'/images/lightbox/loading.gif',
			imageBtnClose:'/images/lightbox/close.gif',
			imageBtnPrev:'/images/x.gif',
			imageBtnNext:'/images/x.gif',
			containerResizeSpeed: 350
		});
	}
});

