function SfindObj(n, d) 
{	//v4.01
	var p, i, x;
	if (!d) 
		d = document; 
	if ((p = n.indexOf("?") ) > 0 && parent.frames.length) 
	{
		d = parent.frames [n.substring(p + 1)].document; 
		n = n.substring(0, p);
	}
	if (!(x = d [n]) && d.all) 
		x = d.all [n]; 
	for (i = 0; !x && i < d.forms.length; i ++) 
		x = d.forms [i] [n];
	for (i = 0; !x && d.layers && i < d.layers.length; i ++)
		x = SfindObj(n, d.layers [i].document);
	if(!x && d.getElementById) 
		x = d.getElementById(n);
	return x;
} 

function CenterLayer (layer,width,height,target) {
	if (!target)
		target=window.document;

	leftLayer = ((target.body.clientWidth - width)/2);
	topLayerABS = (target.body.clientHeight - height)/2;

	topLayer=target.body.scrollTop;
	
	newTop = topLayer + topLayerABS;
	if (newTop < 0)
		newTop=0;

	target.getElementById(layer).style.left = leftLayer;
	target.getElementById(layer).style.top=topLayer + topLayerABS;
}

function doleft(layer,target)
{
	if (!target) target=window.document;
	leftLayer = 200;
	target.getElementById(layer).style.left = leftLayer;
}

function ShowProd (wwidth,wheight,isrc,modelid) {
	obj1=SfindObj('preview');
	obj2=SfindObj('previewimg');
	obj3=SfindObj('previewtbl');
	if (modelid >=0 ) {
		objLoad=SfindObj("loaddata");
		objLoad.innerHTML='';
		objLoad.style.display='none';
	}
	obj2.src='/i/dot.gif';
	
	if (wheight > document.body.clientHeight) {
		wwidth = parseInt(wwidth) + 50;
		obj1.style.width=wwidth+'px';
		obj1.style.height=document.body.clientHeight - 50 +'px';
		obj1.style.overflow = 'auto';
		CenterLayer('preview',wwidth,document.body.clientHeight - 50,window.document);
	}
	else {
		wheight = parseInt(wheight) + 12;
		
		obj1.style.width=wwidth+'px';
		obj1.style.height=wheight+'px';
	
		obj3.style.width=wwidth+'px';
		obj3.style.height=wheight+'px';
		CenterLayer('preview',wwidth,wheight,window.document);
	}
	if(modelid != 1003)
		doleft('preview',window.document);
	obj1.style.visibility='visible';

	obj2.src=isrc;
}

function HideProd () {
	obj1=SfindObj('preview');
	obj2=SfindObj('previewimg');
	objLoad=SfindObj("loaddata");
	objLoad.innerHTML='';
	objLoad.style.display='none';
	obj2.src='/i/dot.gif';
	obj1.style.visibility='hidden';
}   

bDynamic = (document.all || document.layers) ? true : false;

function IsSpaces (sStr) {
	sStr = "" + sStr;
	for (i = 0; i < sStr.length; i ++)
		if (sStr.substring (i, i + 1) != " ")
			return false;
	return true;
}

function WithNumbers (sStr) {
	sStr = '' + sStr;
	for (i = 0; i < sStr.length; i ++)
	{
		ch = sStr.substring (i, i + 1); 
		if (ch >= '0' && ch <= '9')
			return true;
	}
	return false;
}

function ValidateSendForm () {
	f = document.forms['sendform'];
	
	strval = f.phone.value;
	if (strval == "" || IsSpaces (strval) ) {
		alert ("Не заполнено поле");
		if (bDynamic)
			f.phone.focus();
		return false;
	}

	strval = f.email.value;
	if (strval == "" || IsSpaces (strval) ) {
		alert ("Не заполнено поле");
		if (bDynamic)
			f.email.focus();
		return false;
	}
	if (strval.indexOf("@", 0) < 0) {
		alert ("Не правильно заполнено поле");
		if (bDynamic)
			f.email.focus();
		return false;
	}

	strval = f.mess.value;
	if (strval == "" || IsSpaces (strval) ) {
		alert ("Не заполнено поле");
		if (bDynamic)
			f.mess.focus();
		return false;
	}

	return true;
}

function topcount()
{
	var gid = $(this.itemArray[ this.itemCurrent ].orig).attr('gid'); if(!gid) return;
	$.get('/index.phtml?page=17&mode=ajax&gid='+gid);
}

$(function() 
{
	$("a.fotoimg").fancybox({ 'hideOnContentClick': true, 'overlayShow': false, 'zoomOpacity': true, 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, easingIn: 'easeOutBack', easingOut: 'easeInBack' , callbackOnShow: topcount}); 

	if (typeof(DD_belatedPNG) != 'undefined') DD_belatedPNG.fix('.png');
});
