function ImgShw(ID, width, height, alt)
{
    var scroll = "no";
    var top=0, left=0;
    if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
    if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
    if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
    width = Math.min(width, screen.width-10);
    height = Math.min(height, screen.height-28);
    var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
    wnd.document.write("<html><head>\n");
    wnd.document.write("<"+"script language='JavaScript'>\n");
    wnd.document.write("<!--\n");
    wnd.document.write("function KeyPress()\n");
    wnd.document.write("{\n");
    wnd.document.write("     if(window.event.keyCode == 27)\n");
    wnd.document.write("          window.close();\n");
    wnd.document.write("}\n");
    wnd.document.write("//-->\n");
    wnd.document.write("</"+"script>\n");
    wnd.document.write("<title>"+(alt == ""? "Картинка":alt)+"</title></head>\n");
    wnd.document.write("<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">\n");
    wnd.document.write("<img src=\""+ID+"\" border=\"0\" alt=\""+alt+"\">");
    wnd.document.write("</body>");
    wnd.document.write("</html>");
    wnd.document.close();
}

function checkForm(id, alerting){
	
	var name = document.forms[id].name;
	var phone = document.forms[id].phone;
	var whence = document.forms[id].whence;
	var where = document.forms[id].where;
	var mail = document.forms[id].mail;
	
	var whence_oth = document.forms[id].whence_oth;
	var where_oth = document.forms[id].where_oth;
	
	var eM;
	if(!name.value) eM = 'Контактное лицо';
	if(!phone.value) eM = 'Телефон';
	if(!mail.value) eM = 'E-mail';
	if(!whence.value && !whence_oth.value && whence_oth.value!= 'Выберите город') eM = 'Откуда';
	if(!where.value && !where_oth.value && where_oth.value!= 'Выберите город') eM = 'Куда';

	
	
	if(eM){ 
		alert('Вы не заполнили все обязательные поля.\nПоля, обязательные для заполнения, помечены звёздочкой!');
		return false;
	}else if(!checkMail(mail.value)){
		alert('Неправильный E-mail');
		return false;
	}else{
		
		document.getElementById(id).submit();
		if(alerting) alert('Ваша заявка принята, спасибо! Наш диспетчер свяжеться с Вами.')
		return true;
		
	}
}

function checkMail(mail){
	
	if(/^[a-zA-Z0-9](([a-z0-9\-_\+\&]?)+[a-z0-9])?\@((\w([a-zA-Z0-9\-_]+\w)?\.[a-z]{2,4})|(([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d |2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5]))|(localhost))$/i.test(mail)){
		return true;
	}else{

		return false;
	}
}
