if (document.location.pathname == "/print/dfoto/"){
	//alert()
	onload = InitFormat;
}
function InitFormat(){
	document.fotos.format.value = "1169x877";
	ChangeFormat();
}

function ChangeBGColor(x){
	document.all['bg'].value = "color";
	document.fotos.foto_bg.value = x;
	for (i=0; i<document.fotos.length; i++){
		if (document.fotos.elements[i].name.indexOf("ott_") == 0){
			id = document.fotos.elements[i].name.substring(4,10)
			document.all['foto_'+id].style.background = x;
		}
	}
}

function ChangeBG(bg){
	//url_img = "/img/background/" + document.all['foto_bg'].value;
	url_img = "/img/background/200_150/" + bg;
	document.all['bg'].value = "image";
	document.all['foto_bg'].value = bg;
	for (i=0; i<document.fotos.length; i++){
		if (document.fotos.elements[i].name.indexOf("ott_") == 0){
			id = document.fotos.elements[i].name.substring(4,10)
			document.all['foto_'+id].style.backgroundImage = "url("+url_img+")";
		}
	}
}

function ChangeFormat(){
	smallPageX = 200;
	
	arrFormat = document.fotos.format.value.split('x'); //Выбранный пользователем формат фотографии
	px = arrFormat[0]; //Выбранная пользователем реальная ширина фотографии
	py = arrFormat[1]; //Выбранная пользователем реальная высота фотографии
	k_out = px / py;
	
	document.fotos.currPageSizeX.value = px; //Установка новых значений
	document.fotos.currPageSizeY.value = py; //ширины и высоты фотографии
	
	for (i=0; i<document.images.length; i++){
		if (document.images.item(i).name.indexOf("img_") == 0){
			id = document.images.item(i).name.substring(4,10); //id изображения
			
			if (document.all['imgType_'+id].value == "jpeg"){
				size_0 = document.all['realSizeX_'+id].value;
				size_1 = document.all['realSizeY_'+id].value;
				k = size_0 / size_1;
				k_real = k;
				if (k < 1){
					size_temp = size_0;
					size_0 = size_1;
					size_1 = size_temp;
					k = 1 / k;
				}
				
				tVeiwSizeX = smallPageX;
				tVeiwSizeY = tVeiwSizeX / k_out;
			
				kProp = px / tVeiwSizeX;
				size_out_X = size_0 / kProp;
				size_out_Y = size_1 / kProp;
				
				if (size_out_X > tVeiwSizeX){
					size_out_X = tVeiwSizeX;
					size_out_Y = size_out_X / k;
					if (size_out_Y > tVeiwSizeY){
						size_out_Y = tVeiwSizeY;
						size_out_X = size_out_Y * k;
					}
				}
				else {
					if (size_out_Y > tVeiwSizeY){
						size_out_Y = tVeiwSizeY;
						size_out_X = size_out_Y * k;
						if (size_out_X > tVeiwSizeX){
							size_out_X = tVeiwSizeX;
							size_out_Y = size_out_X / k;
						}
					}
				}
				document.images.item(i).width = size_out_X;
				document.images.item(i).height = size_out_Y;
				document.images["p_height_"+id].height = tVeiwSizeY;
			}
		}
	}
}

function ShowFullSize(img_name, dir_name){
	arrFormat = document.fotos.format.value.split('x');
	//url = "/print/"+dir_name+"/prev/?";
	if (dir_name == "pfoto"){
		url = "/print/pfoto/prev/?";
	}
	else {
		url = "/print/lfoto/prev/?";
	}
	/*
	if (document.fotos.foto_bg.value == "0"){
		url += "bgcol="+document.fotos.colour.value+"&";
	}
	else {
		url += "bgd="+document.fotos.foto_bg.value+"&";
	}
	*/
	url += "bgd="+document.fotos.foto_bg.value+"&";
	url += "img="+img_name+"&px="+arrFormat[0]+"&py="+arrFormat[1]+"&";
	url += "f1="+document.fotos.filter_1.value+"&";

	params = "channelmode = no, directories = no, fullscreen = no, height = 330, ";
  params += "left = 50, menubar = no, resizable = no, scrollbars = no	, status = no,";
	params += "titlebar = no,  toolbar = no, top = 50, width = 440";
	
	winFSize = window.open(url, "winFSize", params);
	winFSize.focus();
}

function ApplyFilter(x){
	for (i=0; i<document.images.length; i++){
		if (document.images.item(i).name.indexOf("img_") == 0){
			if (x==1) { 
				document.images.item(i).style.filter+="gray()"; 
				document.fotos.filter_2.value = "yes";
				document.fotos.filter_1.value = "no";
			}
			if (x==2) { 
				document.images.item(i).style.filter=""; 
				document.fotos.filter_1.value = "yes";
				document.fotos.filter_2.value = "no";
			}
		}
	}
}

function toDigit(obj){
	if (obj.value){
		obj.value = parseInt(obj.value)
	}
	else {
		obj.value = 0;
	}
}

function OpenHelp(x, width, height){
	//width = 260;
	//height = 300;
	url = "/help/?x="+x;
	params = "width="+width+",height="+height+",titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=200,left=50";
	winHelp = window.open(url, "winHelp", params);
	winHelp.focus();
}
