
var tf_popup;
var th_popup;
var ph_popup;
var dir_popup;
var metro_popup;
var org_popup;
var user_popup;

function urlenc(s) {
    var r,c,i,l;
    r=''; l=s.length;
    for (i=0; i<l; i++) {
        c=s.substr(i,1);
        if (c=='%') c='%25';
        if (c=='+') c='%2B';
        if (c=='=') c='%3D';
        if (c=='&') c='%26';
        if (c==' ') c='%20';
        r=r.concat(c);
    }
    return r;
}

function zoom_photo(id,h,w) {
    if (ph_popup) ph_popup.close();
    ph_popup=window.open('http://www.otdohnuli.ru/zoom/'+id,'oruphz','width='+(w+30)+', height='+(h+80)+', scrollbars=yes, resizable=yes');
    ph_popup.focus();
}

function zoom_photo_hotels(id,h,w) {
    if (ph_popup) ph_popup.close();
    ph_popup=window.open('/hotels/zoom/'+id,'oruphz','width='+(w+30)+', height='+(h+80)+', scrollbars=yes, resizable=yes');
    ph_popup.focus();
}

function prview(id) {
    window.open('/print/stories/'+id,'prview',
		'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');    
}

function hprview(id) {
    window.open('/print/hotels/'+id,'hprview',
    'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');
}

function addfavorites(id) {
    window.open('/add_favorites.php?story_id='+id,'addfavorites',
		'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=0,top=0,width=1,height=1');
}

function addfavorites_hotels(id) {
    window.open('/add_favorites_hotels?hotel_id='+id,'addfavorites_hotels',
    'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=0,top=0,width=1,height=1');
}

function tf_select() {
    var tfid=urlenc(document.all.tfid.value);
    var tfname=urlenc(document.all.tfname.value);
    var tfcity=urlenc(document.all.tfcity.value);
//    if (tf_popup) tf_popup.close();
    tf_popup=window.open('/select_tf.php?tourfirm_id='+tfid+'&tourfirm_name='+tfname+'&tourfirm_city='+tfcity,'tf_popup',
		'width=500,height=500,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');
    tf_popup.focus();
}

function tf_return(tfid) {
    self.opener.document.all.tfid.value=tfid;
    window.close();
}

function th_select(otruedir,odir,oth) {
    var truedir, dir, th;
    th=urlenc(_getvalue(oth));
    if (odir) {
	dir=urlenc(_getvalue(odir));
    } else {
	dir=0;
    }
    if (otruedir) {
	truedir=urlenc(_getvalue(otruedir));
    } else {
	truedir=0;
    }
//    if (th_popup) th_popup.close();
    th_popup=window.open('/select_th?travel_hotel_id='+th+'&direction_id='+dir+'&otruedir='+otruedir+'&odir='+odir+'&oth='+oth,'th_popup',
		'width=500,height=500,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');    
    th_popup.focus();
}

function th_return(oth,th,otruedir,truedir,odir,dir) {
    _setvalue(oth,th);
    if (otruedir) {
	_setvalue(otruedir,truedir);
    }
    if (odir) {
	_setvalue(odir,dir);
    }
    window.close();
}

function metro_select(id) {
//    if (metro_popup) metro_popup.close();
    metro_popup=window.open('/select_metro?ometroid='+id,'metro_popup',
		'width=500,height=500,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');
    metro_popup.focus();
}

function metro_return(id,value) {
    var o;
    o=opener.document.getElementById(id);
    o.value=value;
    window.close();
}

function org_select(id) {
//    if (org_popup) org_popup.close();
    org_popup=window.open('/select_org?oorg='+id,'org_popup',
		'width=500,height=500,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');
    org_popup.focus();
}

function org_return(id,value) {
    var o;
    o=opener.document.getElementById(id);
    o.value=value;
    window.close();
}

function user_select(id,org_id) {
//    if (user_popup) user_popup.close();
    user_popup=window.open('/select_user?ouser='+id+'&org_id='+org_id,'user_popup',
		'width=500,height=500,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');
    user_popup.focus();
}

function user_return(id,value) {
    var o;
    o=opener.document.getElementById(id);
    o.value=value;
    window.close();
}

function dir_select(otruedir,odir,oth) {
    var thid=urlenc(_getvalue(oth));
    var direction_id=urlenc(_getvalue(odir));
//    if (dir_popup) dir_popup.close();
    dir_popup=window.open('/select_dir?travel_hotel_id='+thid+'&parent_id='+direction_id+'&otruedir='+otruedir+'&odir='+odir+'&oth='+oth,'dir_popup',
		'width=500,height=500,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');
    dir_popup.focus();
}

function dir_return(otruedir,truedir,odir,dir,oth,skip_th) {
    if (otruedir!='') {
	_setvalue(otruedir,truedir);
	_setvalue(odir,dir);
    } else {
	_setvalue(odir,truedir);    
    }
    if (oth!='' && skip_th) {
        _setvalue(oth,'');
    }
    window.close();
}

function _getvalue(id) {
    var o,v;
    if (id=='') return '';
    o=document.getElementById(id);
    v=o.value;
    return v;
}

function _setvalue(id,val) {
    var o;
    o=opener.document.getElementById(id);
    o.value=val;
}

function htreplace(t,id) {
    document.getElementById(id).focus();
    document.selection.createRange().text = t;
    document.getElementById(id).focus();
}

function htenclose(b,e,id) {
    var o=document.getElementById(id);
    o.focus();
    var t=document.selection.createRange().text;
    if (t.substr(0,b.length)==b && t.substr(t.length-e.length)==e) {
        document.selection.createRange().text = t.substr(b.length,t.length-e.length-b.length);
    } else {
        document.selection.createRange().text = b+t+e;
    }
    o.focus();
}


function show_example(id) {
    window.open('/export/examples/'+id+'.html','show_example',
		'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=0,top=0');    
}

function zakaz_submitbutton() {
var form = document.zakaz;
if (form.doctor.value == "0") {
alert( "Выберите страну" );
} else if (form.name.value == "" || form.name.value.length < 4) {
alert( "Неверно заполнено поле 'Ваше имя'!" );
} else if (form.phone.value == "" || form.phone.value.length < 5) {
alert( "Неверно заполнено поле 'Телефон'!" );
} else if (form.phoneprefix.value == "" || form.phoneprefix.value.length < 3) {
alert( "Неверно заполнено поле 'Код города'!" );
} else if (form.comment.value == "" || form.comment.value.length < 5) {
alert( "Напишите пожалуйста Ваши пожелания" );
} else if (form.city.value == "" || form.city.value.length < 3) {
alert( "Неверно заполнено поле 'Город'!" );
} else {
form.phone.value = form.phoneprefix.value+' - '+form.phone.value;
form.submit();
}
}
