var LangIconEN;
var LangIconENon;
var LangIconRU;
var LangIconRUon;

var mailIcon = new Image();
mailIcon.src = "images/site/MailIcon.gif";
var mailIconOn = new Image();
mailIconOn.src = "images/site/MailIconOn.gif";
var searchButton = new Image();
searchButton.src = "images/site/SearchButton.gif";
var searchButtonOn = new Image();
searchButtonOn.src = "images/site/SearchButtonOn.gif";

function imgBrowse(name,w,h)
{
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 75;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes';
    var ow = w;
	var oh = h;
	if (w <= maxwidth && h <= maxheight) param += ',scrollbars=no';
	else { param += ',scrollbars=yes'; w += 20; h += 20; }
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open('../ViewImage.jsp?src='+name+'&width='+ow+'&height='+oh, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowse2(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 75;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/StampSeries.jsp?cmd=show_stamp&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}


function browseCatObj(id,w,h, page)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 75;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + page +'&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseSheet(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/StampSeries.jsp?cmd=show_sheet&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseSheetPromo(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/StampPromoSeries.jsp?cmd=show_sheet&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}


function imgBrowseStampPromo(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 75;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/StampPromoSeries.jsp?cmd=show_stamp&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}


function imgBrowsePostmark(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/PostMark.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseFDE(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/FDE.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseAME(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/Env.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseOSE(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/OSEnv.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseOSC(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/OSCard.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseC(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/Card.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseDC(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/DoubleCard.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseTF(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/Blank.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function imgBrowseEMF(id,w,h)
{
	w+=20; h+=100;
	var maxwidth = screen.width - 40;
	var maxheight = screen.height - 100;
	var top = Math.max(Math.floor((screen.height - h) / 2), 10);
	var left = Math.max(Math.floor((screen.width - w) / 2), 10);
	var param = 'toolbar=no,top=' + top + ',left=' + left + ',location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes';
	if(w > maxwidth) w = maxwidth; else w += 30;
	param  = param + ',width=' + w;
	if(h > maxheight) h = maxheight; else h += 75;
	param = param + ',height=' + h;
	objNewWindow = window.open(document.getElementsByTagName("base")[0].href + 'catalogs/BlankEMail.jsp?cmd=show_image&id='+id, "ViewImage", param);
	objNewWindow.opener = window;
	objNewWindow.resizeTo(w,h);
	objNewWindow.focus();
}

function CheckForm1()
{
	var errStr='';
	objForm = document.forms.registerForm1;
	var Email = new String(objForm.email.value);
	var Login = new String(objForm.login.value);
	if(Login == ''){
		errStr=USER_NAME_MISSING;
	}else if(!CheckEnglishName(Login)){
		errStr=LATIN_ONLY;
	}else if(BeginWithNumber(Login)){
		errStr=CHAR_FIRST_ONLY;
	}else if(Email == ''){
		errStr=EMAIL_MISSING;
	}else if(!isEmailValid(Email)){
		errStr=INVALID_EMAIL;
	}
	if(errStr=='') objForm.submit(); else alert(errStr);

}

function CheckForm2()
{
	var errStr='';
	objForm = document.forms.registerForm2;
	var Email = new String(objForm.email.value);
	if(objForm.login.value == ''){
		errStr='Не указано имя пользователя!';
	}else if(objForm.firmname.value == ''){
		errStr='Не указано название фирмы!';
	}else if(objForm.country.value == ''){
		errStr='Не указана страна!';
	}else if(objForm.zipcode.value == ''){
		errStr='Не указан почтовый индекс!';
	}else if(objForm.address.value == ''){
		errStr='Не указан почтовый адрес!';
	}else if(objForm.phone.value == ''){
		errStr='Не указан номер телефона!';
	}else if(objForm.fax.value == ''){
		errStr='Не указан номер факса!';
	}else if(objForm.inn.value == ''){
		errStr='Не указан ?НН!';
	}else if(objForm.bank.value == ''){
		errStr='Не указано наименование банка!';
	}else if(objForm.bik.value == ''){
		errStr='Не указан Б?К!';
	}else if(objForm.okonh.value == ''){
		errStr='Не указан ОКОНХ!';
	}else if(objForm.okpo.value == ''){
		errStr='Не указан ОКПО!';
	}else if(objForm.settleacct.value == ''){
		errStr='Не указан рассчетный счет!';
	}else if(objForm.corracct.value == ''){
		errStr='Не указан корреспондентский счет!';
	}else if(objForm.empperson.value == ''){
		errStr='Не указано доверенное лицо!';
	}else if(Email == ''){
		errStr='Не указан адрес электронной почты!';
	}else if(!isEmailValid(Email)){
		errStr='Неправильный адрес электронной почты!';
	}
	if(errStr=='') {
		objForm.submit();
	} else {
		alert(errStr);
	}
}

function CheckForm3()
{
	var errStr='';
	objForm = document.forms.loginForm;
	if(objForm.login.value == ''){
		errStr=USER_NAME_MISSING;
	}
	if(errStr=='') {
		objForm.submit();
	} else {
		alert(errStr);
	}
}

function CheckForm4()
{
	var errStr='';
	objForm = document.forms.getPassword;
	var Email = new String(objForm.email.value);
	if(Email == ''){
		errStr=EMAIL_MISSING;
	}else if(!isEmailValid(Email)){
		errStr=INVALID_EMAIL;
	}
	if(errStr=='') {
		objForm.submit();
	} else {
		alert(errStr);
	}
}

function CheckFormGB()
{
	var errStr='';
	objForm = document.forms.msg;
	var Email = new String(objForm.email.value);
	if(objForm.name.value == ''){
		errStr=USER_NAME_MISSING;
	}else if(Email == ''){
		errStr=EMAIL_MISSING;
	}else if(!isEmailValid(Email)){
		errStr=INVALID_EMAIL;
	}
	if(errStr=='') {
		objForm.submit();
	} else {
		alert(errStr);
	}
}

function CheckEMail(Email)
{
    errStr='';
	if(Email == ''){
		errStr=EMAIL_MISSING;
	}else if (!isEmailValid(Email)){
		errStr=INVALID_EMAIL;
	}
	if(errStr=='') {
        return true;
	}
	else {
        alert(errStr);
        return false;
	}
}

function isEmailValid(email) {
//	return ((email.length > 5)&&(email.indexOf('@')>=0)&&(email.indexOf('.')>=0)&&(email.indexOf(" ")<0));
	var s = "[\\w\\-]+(\\.[\\w\\-]+)*@((([a-zA-Z0-9]+)|([a-zA-Z0-9]+[\\w\\-]*))(\\.([\\w^_]+\\.\\2))?\\.)?[\\w\\-]{2,}\\.[a-zA-Z]{2,}";
	var re = new RegExp(s);
	return re.test(email);
}

function OrdersSelectAll()
{
  for (i = 0; i < document.forms.form1.order.length; i++)
   {
    var item = document.forms.form1.order[i];
	item.checked = true;
   }
}

function OrdersConfirm()
{
	document.forms.form1.submit();
}

function OrdersDelete()
{
	document.forms.form1.cmd.value='delete_order';
	document.forms.form1.submit();
}

function CheckJobName()
{
	var errStr='';
	objForm = document.forms.task;
	if(objForm.JobName.value == '')
		errStr='Введите название!';
	if(errStr=='') {
		objForm.submit()
	} else {
		alert(errStr)
	}
}

function CheckJobName2()
{
	var errStr='';
	objForm = document.forms.task;
	if(objForm.JobName.value == '')
		errStr='Введите название!';
	if(errStr!='') {
		alert(errStr)
	};
}

function CheckOrderValues(max)
{
	var errStr='';
	objForm = document.forms.form1;
	for (i = 0; i < objForm.count.length; i++)
	{
		var num = parseFloat(objForm.count[i].value,10);
		if(isNaN(num) || num<0 || num>max)
			errStr='Введенные Вами значения слишком велики!';
	}
	if(errStr=='') {
		objForm.submit()
	} else {
		alert(errStr);
	}
}

function CheckOrderValuesAndDescription(max)
{
	var errStr='';
	objForm = document.forms.form1;
	for (i = 0; i < objForm.count.length; i++)
	{
		var num = parseFloat(objForm.count[i].value,10);
		if(isNaN(num) || num<0 || num>max)
			errStr='Введенные Вами значения слишком велики!';
	}
	var count = 0;
	for (i = 0; i < objForm.description.length; i++)
	{
		var desc = objForm.description[i].value;
		if(desc != '') count=1;
	}
	if(count == 0) errStr='Введите название продукции!';
	if(errStr=='') {
		objForm.submit()
	} else {
		alert(errStr);
	}
}

function CheckEnglishName(name){
    var alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.";
    for(i=0;i<name.length;i++){
        c = name.charAt(i);
        if(alphabet.indexOf(c)==-1)
            return false;
    }
    return true;
}

function BeginWithNumber(name){
    var alphabet="0123456789";
	c=name.charAt(0);
    if(alphabet.indexOf(c)==1)
		return true;
    return false;
}

function preloadLangIcons_ru() {
	window.status = "Preloading language icons...";
	LangIconEN = new Image();
	LangIconENon = new Image();

	LangIconEN.src = "images/site/LangIconEN.gif";
	LangIconENon.src = "images/site/LangIconENon.gif";

	window.status = "Done";
}

function preloadLangIcons_en() {
	window.status = "Preloading language icons...";
	LangIconRU = new Image();
	LangIconRUon = new Image();

	LangIconRU.src = "images/site/LangIconRU.gif";
	LangIconRUon.src = "images/site/LangIconRUon.gif";

	window.status = "Done";
}

function clearEMailField() {
	if(document.forms.SubscribeNewsArea.modified.value==''){
		document.forms.SubscribeNewsArea.email.value='';
		document.forms.SubscribeNewsArea.modified.value='true'
	}
}

function enter2Tab() {
	if (event.keyCode == 13) {
		event.keyCode = 9;
	}
}

function subscribeNews() {
	if (CheckEMail(document.forms.SubscribeNewsArea.email.value)) {
		document.forms.SubscribeNewsArea.submit();
	}
}

function checkSurvey2() {
	if ((document.forms.survey.source[4].checked) && (document.forms.survey.srcAdv.value == '')) {
		alert("Пожалуйста, укажите источник.");
		document.forms.survey.srcAdv.focus();
		event.returnValue = false;
		return false;
	} else {
		return true;
	}
}

function checkSurvey3() {
	if ((document.forms.survey.themeOth.checked) && (document.forms.survey.themeAdv.value == '')) {
		alert("Пожалуйста, укажите тему.");
		document.forms.survey.themeAdv.focus();
		event.returnValue = false;
		return false;
	}
	if ((document.forms.survey.measureOth.checked) && (document.forms.survey.measureAdv.value == '')) {
		alert("Пожалуйста, напишите ваши предложения.");
		document.forms.survey.measureAdv.focus();
		event.returnValue = false;
		return false;
	}
	return true;
}

function searchPage(page) {
	document.forms.AdSearchAreaNew.page.value=page;
	document.forms.AdSearchAreaNew.submit();
}

function setModules(state) {
	var modules = document.forms.AdvSearch.module;
	for (var i = 0; i < modules.length; i++) {
		modules[i].checked = state;
	}
}

function test() {
	alert("IE rulez!");
}