function OpenFileManager(id, x1, y1, x2, y2, format){
        if(format == "") bonus="";  else bonus="&format="+format;
        if(document.location.href.indexOf('dfoto') == '') xurl = "/user/file_manager/main.php?id="+id+"&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+bonus;
         else 
	 xurl = "/user/file_manager/main.php?from_dfoto=1&id="+id+"&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+bonus;
	params = "channelmode = no, directories = no, fullscreen = no, height = 500, ";
        params += "left = 50, menubar = no, resizable = no, scrollbars = yes	, status = yes,";
	params += "titlebar = no,  toolbar = no, top = 50, width = 550";

	winFMan = window.open(xurl, "winFMan", params);
	winFMan.focus();
}
function OpenFileManager2(id, x1, y1, x2, y2,s_id){
	xurl = "/user/file_manager/main.php"+s_id+"&id="+id+"&x1="+x1+"&y1="+y1+"&x2="+x2+"&y2="+y2+"";
	params = "channelmode = no, directories = no, fullscreen = no, height = 500, ";
        params += "left = 50, menubar = no, resizable = yes, scrollbars = yes	, status = yes,";
	params += "titlebar = no,  toolbar = no, top = 50, width = 550";
	
	winFMan = window.open(xurl, "winFMan", params);
	winFMan.focus();
}


function ApplyImg(){
	y = 0;
	for (i=0; i<document.fotos.length; i++){
		if (document.fotos.elements[i].type == "checkbox"){
			if (document.fotos.elements[i].name.indexOf("foto_") == 0){
				if (document.fotos.elements[i].checked == true){
					ind = i;
					y++;
				}
			}
		}
	}
	if (y == 0){
		alert("Выберите изображение");
	}
	else {
		img_id = document.all['id'].value;
		img_ind = document.fotos.elements[ind].name.substr(5);
		window.opener.document.all['img_'+img_id].src = document.all['img_'+img_ind].src;
		window.opener.document.all['img_'+img_id].width = document.all['img_'+img_ind].width;
		window.opener.document.all['img_'+img_id].height = document.all['img_'+img_ind].height;
		window.opener.document.all['foto_'+img_id].value = document.all['img_'+img_ind].img_name;
		//window.close();
	}
}

function xCalculate(type, s_id){
	d = document.fotos;
	xurl = "/print/"+type+"/calc/"+s_id+"&";
	xurl = xurl+"total="+d.all['total'].value+"&"+"format="+d.all['format'].value+"&";
	/*if (d.all['urgency'].checked == true){
		xurl = xurl+"urgency=on&";
	}
	xurl = xurl+"delivery="+d.all['delivery'].value+"&";
	*/
	params = "width=390,height=150,toolbar=no,titlebar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=50,left=50";
	winCalc = window.open(xurl, "winCalc", params);
	winCalc.focus();
}

function Disclamer(frm_name){
	var s;
	s=""; 
	if (typeof(frm_name) == "undefined"){
		frm_name = "form_01";
	}
	d = document.all[frm_name];

        img_fl1 = 0; img_fl2 = 0;
	for (i=0; i<document.fotos.length; i++)
        {
         if ( (document.fotos.elements[i].name.indexOf("imgName_") == 0) &  ( document.fotos.elements[i].value != "")  ) { img_fl1 = 1;}
         if ( (document.fotos.elements[i].name.indexOf("from_up_") == 0) &  ( document.fotos.elements[i].value != "")  ) { img_fl2 = 1;}

        }
   
	if (img_fl1 == 0 & img_fl2 == 0)
        {
		s = "Пожалуйста, выберите изображение.\n\n";
		alert(s); 
	}
	else {	
		d.submit();
	}
}


function ImgCheck(frm_name)
{
	var s;
	s="";        
	if (typeof(frm_name) == "undefined"){
		frm_name = "form_01";
	}
	d = document.all[frm_name];

        img_fl = 0;
	for (i=0; i<document.fotos.length; i++)
        {
    
        if ((document.fotos.elements[i].name.indexOf("foto_") == 0) & ( document.fotos.elements[i].name != "foto_bg") &  ( document.fotos.elements[i].value != ""))
         {
        
          img_fl = 1;
         } 
        if ((document.fotos.elements[i].name.indexOf("imgName_") == 0) & ( document.fotos.elements[i].value != ""))
         {
          img_fl = 1;
         } 

        }
   
	if (img_fl == 0)
        {
		s = "Пожалуйста, выберите изображение.\n\n";
		alert(s); 
	}
	else {	
		d.submit();
	}
}

function Disclamer_old(frm_name){
	var s;
	s="";
	if (typeof(frm_name) == "undefined"){
		frm_name = "form_01";
	}
	d = document.all[frm_name];
	//if (d.foto_1.value==""){
	if (d.imgName_1.value == ""){
		s = "Пожалуйста, выберите изображение.\n\n";
		alert(s);
	}
	else {	
		d.submit();
	}
}


function isEmail(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 r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
} 


function DisclamerReg(frm_name){
	var s, user_email, flgSub;
	if (typeof(frm_name) == "undefined"){
		frm_name = "fotos";
	}
	d = document.all[frm_name];
	s = "Пожалуйста, заполните следующие поля:\n\n";
	flgSub = true;
	user_email = d.user_email.value;
	if (d.user_fio.value == ""){
		s = s + "Ф.И.О\n";
		flgSub = false;
	}
	if (user_email == ""){
		s = s + "e-mail\n";
		flgSub = false;
	}
	if (d.user_phone.value == ""){
		s = s + "телефон\n";
		flgSub = false;
	}
	if (typeof(d.imgName_1) != "undefined"){
		if (d.imgName_1.value == ""){
			s = "Пожалуйста, загрузите файл для печати.\n\n";
			flgSub = false;
		}
	}
	if (user_email != ""){
		if (!isEmail(user_email)){
			s = "E-mail адрес некорректный!";
			flgSub = false;
		}
	}
	if (flgSub == false){
		alert(s);	
	}
	else {	
		d.submit();
	}
}

function _DisclamerReg(frm_name){
	var s, flgSub;
	if (typeof(frm_name) == "undefined"){
		frm_name = "fotos";
	}
	d = document.all[frm_name];
	s = "Пожалуйста, заполните следующие поля:\n\n";
	flgSub = true;
	user_email = d.user_email.value;
	if (d.user_login.value == ""){
		s = s + "Логин\n";
		flgSub = false;
	}
	if (d.user_password.value == ""){
		s = s + "Пароль\n";
		flgSub = false;
	}
	if (d.user_fio.value == ""){
		s = s + "Ф.И.О\n";
		flgSub = false;
	}
	if (user_email == ""){
		s = s + "e-mail\n";
		flgSub = false;
	}
	if (d.user_phone.value == ""){
		s = s + "телефон\n";
		flgSub = false;
	}
		if (user_email != ""){
		if (!isEmail(user_email)){
			s = "E-mail адрес некорректный!";
			flgSub = false;
		}
	}

	if (flgSub == false){
		alert(s);	
	}
	else {	
		d.submit();
	}
}


function checkMinVal(obj, minVal){
	if (typeof(minVal) == "undefined"){
		minVal = 50;
	}
	val = obj.value;
	if ( (val < 50) || (val == "NaN") ){
		val = minVal;
		obj.value = val;
		alert("Минимальный тираж "+minVal+" экз.");
	}
}
