function chColor(sender,t)
{
	itm=document.getElementById(sender);
	
	if (itm!=null)
		{
			s=itm.style.color;
			if (t==0)
			{
				//s="#313031";
				s="#FF9A31";
			}
				else
			{
				//s="#FF9A31";
				s="#313031";
			}
			itm.style.color=s;
		}
		
}

function insVal(vl)
{
	itm=document.getElementById("ind");
	itm_=document.getElementById("tgt2");
	s=itm.innerHTML;
	n=itm_.innerHTML;
	if (itm!=null)
		{
			if (document.getElementById(vl)==null)
				{
				s=s.replace("&nbsp; ","<span id="+vl+" onClick='delVal(this.id);' style='cursor:hand' title='Исключить из мультизапроса!'>&nbsp;<u>"+vl+"</u></span>&nbsp; ");
				n=n.replace("&nbsp; ","<span id="+vl+"_ >"+vl+" : <текущее значение><br></span>&nbsp; ");
				itm.innerHTML=s;
				itm_.innerHTML=n;
				}
			else
				{
				itm=document.getElementById(vl);
				itm.innerHTML="&nbsp;<u>"+vl+"</u>";
				}
		}
	
	
}

function delVal(el)
{
itm=document.getElementById(el);
itm.innerHTML="";
itm_=document.getElementById(el+"_");
itm_.innerHTML="";
}


function sthmpage(th)
{ 
	if (navigator.appName == 'Microsoft Internet Explorer' && parseFloat(navigator.appVersion) >= 4.0){ 
		th.style.behavior='url(#default#homepage)';
		th.setHomePage('http://alerts.finam.ru/');
		event.returnValue = false;
	}
}

function OnIconHover(name, flag)
{
   var newImg, path, fileAdd, width, height, fname;
   path='/i/';

   fname = name

   if (name=="mail") {width=12; height=10;}
   else if (name=="home") {width=11; height=10;}
   else if (name.substring(0,3)=="arr") {fname="arr"; width=10; height=18;}
   else if (name.substring(0,3)=="but") {fname="but"; width=9; height=8;}
   else if (name=="ok") {width=9; height=8;}

   newImg=new Image(width, height);
   if (flag==true) fileAdd="02";
   else            fileAdd="01";

   newImg.src=path + fname + fileAdd + ".gif";
   document[name+"_icon"].src=newImg.src;
}

function OnSubmit(formName)
{
	form = document[formName];
	form.submit();
}

//Куранты	
function GetMoscowTime()
{
	var dDate, sDate, sVar
	dDate = new Date();

	sVar = '' + dDate.getDate();
	if (sVar.length==1) {sVar = '0' + sVar}
	sDate = sVar.substr(sVar.length-2,2) + '.';
	sVar = '0' + (dDate.getMonth()+1);
	sDate += sVar.substr(sVar.length-2,2) + '.';
	sDate += dDate.getFullYear() + ' ';
	sVar = '0' + (dDate.getHours());
	sDate += sVar.substr(sVar.length-2,2) + ':';
	sVar = '0' + dDate.getMinutes();
	sDate += sVar.substr(sVar.length-2,2) + ':';
	sVar = '0' + dDate.getSeconds();
	sDate += sVar.substr(sVar.length-2,2);
	document.getElementById("date_field").innerHTML = sDate;

	setTimeout("GetMoscowTime()",1000);
}

//Новое устройство
function GetDeviceDataForm()
{
	var textNote="";
//	var deviceType=document.all["device_type"];
	var deviceType=document.device_form.device_type;
	//var nOptions=document.all["operators"].options.length;

	RemoveList(document.device_form.operators);

	if (deviceType[0].checked) {
		//CreateMobileList();
		//document.all.operators.style.display='block';
		//document.all.device_data_table.rows("data_row1").cells("data11").innerText = 'Оператор';
		document.device_form.operators.style.display='none';
//		document.all.device_data_table.rows("data_row1").cells("data11").innerText='';
		document.getElementById("data11").innerHTML='';
		if (document.device_form.client.value==1) {textNote = 'Номер/E-mail телефона<br>(Пример: 7095#######)';}else{textNote = 'E-mail телефона';}
	}
	if (deviceType[1].checked) {
		CreatePagerList();
		document.device_form.operators.style.display='block';
//		document.all.device_data_table.rows("data_row1").cells("data11").innerText='Оператор';
		document.getElementById("data11").innerHTML='Оператор'
		textNote='Номер/E-mail пейджера';
	}
	if (deviceType[2].checked) {
		document.device_form.operators.style.display='none';
//		document.all.device_data_table.rows("data_row1").cells("data11").innerText='';
		document.getElementById("data11").innerHTML='';
		textNote = 'Номер ICQ';
	}
	if (deviceType[3].checked) {
		document.device_form.operators.style.display='none';
//		document.all.device_data_table.rows("data_row1").cells("data11").innerText='';
		document.getElementById("data11").innerHTML='';
		textNote='E-mail';
	}

//	document.all.device_data_table.rows("data_row2").cells("data21").innerText=textNote;
	document.getElementById("data21").innerHTML=textNote;
	document.device_form.data2.style.display='block';
}

function CheckDeviceData(formName,fieldName)
{
	var deviceType=document.all["device_type"];
	var	oData=document.all.data2
	var iData=parseInt(oData.value)
	var formSubmit=true

	if (deviceType[0].checked){
		if (oData.value.indexOf('@')!=-1){
			if (!CheckEmail(formName,fieldName)){
				alert("Неверный e-mail телефона!");
				formSubmit=false;
			}
		}else{
			if ((oData.value.length!=11)||(oData.value.substr(0,1)!='7')||(parseInt(oData.value)!=oData.value)){
				alert("Неверный номер телефона!\nМобильный номер должен быть семизначным с префиксом,\nначинающимся с цифры '7' и состоять только из цифр.");
				formSubmit=false;
			}
		}
	}
	if (deviceType[1].checked){
		if (document.all.operators.options.selectedIndex==0){
			if (!CheckEmail(formName,fieldName)){
				alert("Неверный e-mail пейджера!");
				formSubmit=false;
			}
		}else{
			if (isNaN(parseInt(oData.value))||(oData.value<100)){
				alert("Неверный номер пейджера!");
				formSubmit=false;
			}
		}
	}
	if (deviceType[2].checked){
		if (isNaN(parseInt(oData.value))||(parseInt(oData.value)<10000)||(parseInt(oData.value)>2147483646)||(parseInt(oData.value)!=oData.value)){
			alert("Поле может содержать число из интервала (10000,2147483646)!");
			formSubmit=false;
		}
	}
	if (deviceType[3].checked){
		if (!CheckEmail(formName,fieldName)) {
			alert("Неверный e-mail адрес!");
			formSubmit=false;
		}
	}
	if (formSubmit){document.device_form.submit()}
}

function CheckEmail(formName,fieldName)
{
	var j=0;
	var nDogQnty=0;
	var nDotQnty=0;
	var sSubAdr="";
	var oAddress=document[formName][fieldName];
	var reg = /[^.\s~!@#$%^&*()+=|\\{\[}\]:;"'<,>?/`]+/;

	for(i=0;i<oAddress.value.length;i++){
		if (oAddress.value.substr(i,1).charCodeAt(0) > 122){return false}
		if (oAddress.value.substr(i,1)=='@'){
			if (nDogQnty < 2){
				sSubAdr = oAddress.value.substring(j,i);
				if (reg.exec(sSubAdr)!=sSubAdr){return false}
				sSubAdr=""
				j=i+1;
				nDogQnty++;
			}else{return false}
		}
		if (oAddress.value.substr(i,1)=='.'){
			sSubAdr = oAddress.value.substring(j,i);
			if (reg.exec(sSubAdr)!=sSubAdr){return false}
			j=i+1;
			nDotQnty++;
		}
	}
	if ((nDogQnty==0)||(nDotQnty==0)){return false}

	sSubAdr = oAddress.value.substring(j,i);
	if (reg.exec(sSubAdr)!=sSubAdr){return false}

	return true;
}
function checkAmount()
{
	var oAmount=document.all.amount
	var rgSeparator=/,/g
	var fAmount=parseFloat(oAmount.value.replace(rgSeparator,'.'))

	if ((fAmount==oAmount.value.replace(rgSeparator,'.'))&&(fAmount<=100)&&(fAmount>=1)) return true

	alert("Введите числовое значение от 1 до 100!")
	return false
}
/*
function CreateMobileList() {
	for(i=0;i<aMobileIds.length;i++){
		oNewOption = new Option();
		oNewOption.text=aMobileNames[i];
		oNewOption.value=aMobileIds[i];
		document.all.operators.add(oNewOption, i);
	}
}
*/
function CreatePagerList() {
	for(i=0;i<aPagerIds.length;i++){
		oNewOption = new Option();
		oNewOption.text=aPagerNames[i];
		oNewOption.value=aPagerIds[i];
//		document.device_form.operators.add(oNewOption, i);
		document.device_form.operators.options[document.device_form.operators.options.length]=oNewOption;

	}
}
function RemoveList(sSelect) {
	var nOptions=sSelect.options.length;
	for(i=0;i<nOptions;i++){
		selected=sSelect.selectedIndex;
		sSelect.options[selected] = null;
	}
}

//Эмитенты
function showEmitents(alertID)
{
	if (document.all["emits_"+alertID]!=null){
		if (document.all["emits_"+alertID].style.display=='block'){
			document.all["emits_"+alertID].style.display='none';
			document.all["show_emits_"+alertID].src="/i/portf/closed.gif";
			document.all["show_emits_"+alertID].alt="Показать эмитентов";
		}else{
			document.all["emits_"+alertID].style.display='block';
			document.all["show_emits_"+alertID].src="/i/portf/opened.gif";
			document.all["show_emits_"+alertID].alt="Скрыть эмитентов";
		}
	}
}

function clearSelect(select)
{
	select.options.length=0
}

function buildEmitentList(select,market)
{
	selIndex=0
	for (i=0;i<aEmitentIds.length;i++)
		{
		if(aEmitentMarkets[i]==market){
			opt=new Option(aEmitentNames[i],aEmitentIds[i])
			select.options[select.options.length]=opt
			if((market==7)&&(aEmitentIds[i]==108)){selIndex=select.options.length-1}
			if((market==1)&&(aEmitentIds[i]==1)){selIndex=select.options.length-1}
			if((market==4)&&(aEmitentIds[i]==73)){selIndex=select.options.length-1}
			if((market==3)&&(aEmitentIds[i]==307)){selIndex=select.options.length-1}
		}
	}
	select.selectedIndex=selIndex
}
	
function rebuildEmitentList(select,market)
{
	clearSelect(select)
	buildEmitentList(select,market)
}

function selectEmitent(select,emitent)
{
	for(i=0;i<select.options.length;i++)
		if(select.options[i].value==emitent){select.selectedIndex=i}
}

function addEmitent(aid)
{
	document.EmitentsForm.iq.value=aid;
	document.all.new_emitent.title="Добавления эмитента в алерт '"+ document.all["alert_name"+aid].innerText+"'";
	document.all.new_emitent.style.left=getElementAbsX("chg"+aid)-710;
	document.all.new_emitent.style.top=getElementAbsY("chg"+aid)+10;
	document.all.new_emitent.style.display='block';
}

//Публикация
function showForm(formID)
{
	if (document.all["form_"+formID]!=null){
		if (document.all["form_"+formID].style.display=='block'){
			document.all["form_"+formID].style.display='none';
			document.all["show_form_"+formID].src="/i/portf/closed.gif";
			document.all["show_form_"+formID].alt="Показать форму";
		}else{
			document.all["form_"+formID].style.display='block';
			document.all["show_form_"+formID].src="/i/portf/opened.gif";
			document.all["show_form_"+formID].alt="Скрыть форму";
		}
	}
}

//Подписка
function chgSubscribe()
{
	if (document.all.chg_subscribe.style.display=='block'){
		document.all.chg_subscribe.style.display='none';
	}else{
		document.all.chg_subscribe.style.display='block';
	}
}

function showContent(sid)
{
	width=800
	height=600
	if (screen){
		aLeft=Math.floor((screen.width-width)/2)
		aTop=Math.floor((screen.height-height)/2)
	}else{
		aLeft=0
		aTop=0
	}
	str="win=window.open('SubscrContent.asp?sid='+parseInt(sid),'','resizable=0,scrollbars=1,left='+aLeft+'px,top='+aTop+'px,width='+width+'px,height='+height+'px')"
	eval(str)
	win.focus()
}

function showHoroContent(sid)
{
	width=800
	height=600
	if (screen){
		aLeft=Math.floor((screen.width-width)/2)
		aTop=Math.floor((screen.height-height)/2)
	}else{
		aLeft=0
		aTop=0
	}
	str="win=window.open('HoroContent.asp?sid='+parseInt(sid),'','resizable=0,scrollbars=1,left='+aLeft+'px,top='+aTop+'px,width='+width+'px,height='+height+'px')"
	eval(str)
	win.focus()
}

//Новая котировка
function GetQuotDataForm()
{
	var quotType = document.all["quot_type"].selectedIndex;
	if (quotType == 0) {
		document.all.price_data.style.display='none';
		document.all.period_data.style.display='block';
	}
	if (quotType == 1) {
		document.all.period_data.style.display='none';
		document.all.price_data.style.display='block';
	}
}

//Выбор устройства && количества 
function chgAlertsQnty(ID, deviceType){
	var tmp
	tmp = 'document.QuotForm.qnty'+ID+'.disabled'

	if (!isNaN(eval(tmp))){
		tmp = 'document.QuotForm.sender'+ID+'.checked'
		if (eval(tmp)){
			tmp = 'document.QuotForm.qnty'+ID+'.disabled = false'
			//if (deviceType==4){document.QuotForm.tbl.disabled = false}
		}else{
			tmp = 'document.QuotForm.qnty'+ID+'.disabled = true'
			//if (deviceType==4){
			//	document.QuotForm.tbl.checked = false;
			//	document.QuotForm.tbl.disabled = true;
			//}
		}
	}
	eval(tmp)
}

//Новая рассылка
function checkNewSubscribe() {
	var frm=document.SubscribeForm;

	if ((frm.theme.value=="") || (frm.describe.value=="") || (frm.content.value=="")){
		alert("Все поля обязательны для заполнения, кроме поля 'Сайт автора'!");
		return false;
	}
	if (frm.catalog.selectedIndex==0){
		alert("Выберите раздел каталога!");
		return false;
	}
	if (frm.period.selectedIndex==0){
		alert("Установите периодичность рассылки!");
		return false;
	}
	if (!CheckEmail('SubscribeForm','email')) {
		alert("Не верный e-mail адрес!");
		return false;
	}
	return true;
}

//Ввод рассылки
function checkAuthorWrite() {
	var frm=document.WriteForm;

	if ((frm.subject.value=="") || (frm.content.value=="")){
		alert("Все поля обязательны для заполнения!");
		return false;
	}
	if (frm.catalog.selectedIndex==0){
		alert("Выберите рассылку!");
		return false;
	}
	if (frm.subject.value.length>150){
		alert("Тема сообщения не должна превышать 150 символов!");
		return false;
	}
	return true;
}

//Задать вопрос
function checkQuestForm() {
	var frm=document.QuestForm;

	if ((frm.name.value=="")||(frm.email.value=="")||(frm.question.value=="")){
		alert("Все поля обязательны для заполнения!");
		return false;
	}else{
		if (!CheckEmail('QuestForm','email')){
			alert("Неверный e-mail адрес!");
		}else{
			frm.help.value="d";
			frm.submit()
		}
	}
}

//Вычисление координат элемента
function getElementAbsX(elementId){
	var oElement=document.all[elementId];
	var iX=0;
	while(oElement.tagName!="BODY"){
		iX+=oElement.offsetLeft;
		oElement=oElement.offsetParent;
	}
	return iX;
}

function getElementAbsY(elementId){
	var oElement=document.all[elementId]
	var iY=0;
	while(oElement.tagName!="BODY"){
		iY+=oElement.offsetTop;
		oElement=oElement.offsetParent;
	}
	return iY;
}

function Popup()
{
	var popup = window.open('adDevice.html','popup','fullscreen=1');
	popup.resizeTo(300, 200); 
	popup.moveTo(100, 100);
}
