// SNF JAVASCRIPT utility_functions.js VERSION 1.0
// Function to jump to a URL in a <select> menu
//  In this case, the name of the array containing the URLs
//  is determined based on the name of the pulldown menu.
function jumpToURL(formName,menuName) {
 var obj = eval("document." + formName + "." + menuName);
 var index = obj.selectedIndex;
 var url = eval(menuName + "_URLs[" + index + "]");
 if (url != "") {
   location.href=url;
 }
}

//функция вызывает окно с предупреждение об уходе пользователя с сайта hp.ru

function link_out(file_name,url) {
	var open_file_name = (file_name == null) ? '/out/out.html':file_name
	window.open(open_file_name + '?goto=' + url,'_blank','width=460,height=220,location=no,menubar=no,resizeable=no,status=no,toolbar=no,scrollbars=no')
}

function openWin(uri,w,h) {
		var openParam = 'resizable=1,scrollbars=yes';
		if (w) openParam += ',width=' + w;
		if (h) openParam += ',height=' + h;
		window.open(uri,'_blank',openParam);
		return false;
}


// Functions and variables for form functionality


function formVarsInit() {
	ireq = new Image(); ireq.src = '/img/icons/required.gif';
	iblank = new Image(); iblank.src = '/img/d-t.gif';
	idisabled = new Image(); idisabled.src = '/img/icons/disabled-star.gif';
	formName = (document.forms[1])?1:0;
	formObj = document.forms[formName];
	is_initialized = true;
}

function imageChange(name,src) {
	if (document.images) document.images[name].src = src
}

function checkFilling(elem) {
	if (is_initialized) imageChange(elem.name + '_i',(elem.value)?iblank.src:ireq.src)
}

function checkFields() {
	if (is_initialized) {
		for(var i in reqFields) {
			if (!formObj.elements[reqFields[i][0]].value) {
				alert('Внимание: не заполненно об\язательное поле "'+reqFields[i][1]+'"!');
				formObj.elements[reqFields[i][0]].focus();
				return false;
			}
		}
		return true;
	} else return false
}

function blind() {
	if (is_initialized)
		for(var i in reqFields)
			if (formObj.elements[reqFields[i][0]].value) imageChange(reqFields[i][0] + '_i',iblank.src)
}


// ***** Functions moved from hpweb_utilities.js on January, 10.

function goTo(where) {
	document.location.replace(where);
	return false;
}

//функция вызывает окно с предупреждением о неправльно введенном адресе электронной почты
function check_email(email) {
	var email_pattern = new RegExp("(([a-zA-Z0-9]+|[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+)\.)*([a-zA-Z0-9]+|[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+)@(([a-zA-Z0-9]+|[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+)\.)*([a-zA-Z]{2,3})")
	if (email_pattern.test(email)) {
		return true
	} else {
		alert('Внимание: адрес электронной почты указан неправильно!')
		return false
	}
}
