function sv_numbers(sv){
	ind=sv.value;
	simb=ind.charAt(ind.length-1);
	if(!/^\d+$/.test(simb)) {
		ind=ind.substring(0,ind.length-1);
		sv.value=ind;
	}
}

function subscribe_form(){
	sv=document.forms['sv_subscribe'];
	ind=sv.index.value;
	if (sv.name.value && sv.address.value){
		simb=document.forms['sv_subscribe'].index.value;
		fl = /^\d+$/.test(simb);
		if (!fl || simb<100000 ){
			alert('Неверный формат индекса');
			document.forms['sv_subscribe'].elements['index'].focus();
		}
		else{
			sv.submit();
		}
	}
	else{
		alert('Заполните обязательные поля');
	}
}

function go_wap(URL){
	if (navigator.appName == "Netscape") {
		open_popup_window("http://www.mobil.ru/wap/main_nn.php?ruri="+URL, 270, 232 );	
	}
	else{
		open_popup_window("http://www.mobil.ru/wap/main_ie.php?ruri="+URL, 300, 212 );	
	}
}

function open_popup_window(theURL, h, w)
{
	if( screen.availHeight < h ) {  h = screen.availHeight; }
	if( screen.availWidth < w ) { w = screen.availWidth; }
	t = ( screen.availHeight - h ) / 2 - 30;
	l = ( screen.availWidth - w ) / 2; 

	ch_win = window.open( theURL, 'WAP', 'width=' + w + ',height=' + h + ',left=' + l + ',top=' + t + ',scrollbars=1,status=0,resizable=0');
	ch_win.focus();
	if( ch_win.opener == null ) ch_win.opener = window;
}	

function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }
    var is_confirmed = confirm(confirmMsg + ' ' + theSqlQuery + '?');
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
}

function contest_pop_up(lotto_id, note_id){
	new_loto_win=window.open("/contest_pop_up.php?lotto_id="+lotto_id+"&note_id="+note_id,"голосование","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=200,top=150,left=150");
	new_loto_win.focus();
	//new_loto_win.location.reload();
}

function contest_pop_up2(lotto_id, nids){
	new_loto_win=window.open("/contest_pop_up.php?lotto_id="+lotto_id+"&note_vote_ids="+nids,"голосование","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=200,top=150,left=150");
	new_loto_win.focus();
	//new_loto_win.location.reload();
}

function opinion_pop_up(lotto_id, note_id, already_in_profile){
	addr = "/contest_opinion_pop_up.php?lotto_id="+lotto_id+"&note_id="+note_id;
	if(already_in_profile == 1) { addr += '&inp=1'; }
	new_loto_win=window.open(addr,"голосование","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=420,height=400,top=150,left=150");
	new_loto_win.focus();
	//new_loto_win.location.reload();
}

function rules_pop_up(){
	window.open("/templates/contest_rules_pop_up.html","правила","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=470,height=470,top=150,left=150");
}

function quiz_pop_up(){
	window.open("/templates/quiz_pop_up.html","Ответы","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=470,height=470,top=150,left=150");
}

function opinions(){
	var c1=document.forms['note'].name.value;
	var c2=document.forms['note'].elements['text'].value;
	var c3=false;
	for(i=0;i<5;i++){
		if(document.forms['note'].mark[i].checked){c3=true;}
	}
	if(c3){
	
	if(c1!=""){
		if(c2!=""){document.forms['note'].submit();}
		else{alert("Заполните обязательные поля!");}
	}
	else{alert("Заполните обязательные поля!");}	
	
	}
	else{alert("Заполните обязательные поля!");}

}

function asdf(winner, test_url, test_name){
	path="priz.php";
	window.open("/"+path+"?test_name="+test_name+"&test_url="+escape(test_url)+"&winner="+winner, "","toolbar=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, width=520, height=170, top=50, left=100");
}

function ShowImg(pic,w,h){
	path=pic;
	newWin=window.open("/"+path,"","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+w+",height="+h+",top=50,left=100");
  	newWin.document.open();
	newWin.document.writeln('<html><head><title>Stereo.ru</title>');
	newWin.document.writeln('');
	newWin.document.writeln('</head><body bgcolor="white" onKeyDown="if(window.event.keyCode==27){window.close();};"><table align="center" valign="middle"><tr><td><img src="'+path+'" style="position:absolute; left:0; top:0"></td></tr></table></body></html>');
	newWin.document.close();
}

function ShowReklama(pic,w,h){
	path=pic;
	newWin=window.open("/"+path,"","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h+",top=50,left=100");
  	newWin.document.open();
	newWin.document.writeln('<html><head><title>Stereo.ru</title>');
	newWin.document.writeln('');
	newWin.document.writeln('</head><body bgcolor="white" onKeyDown="if(window.event.keyCode==27){window.close();};"  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table align="center" cellpadding="0" cellspacing="0" border="0"><tr><td><img src="'+path+'"></td></tr></table></body></html>');
	newWin.document.close();
}

function ShowImgScr(pic,w,h){
	path=pic;
	w=w+30;
	newWin=window.open(path,"","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h+",top=50,left=100");
  	newWin.document.open();
	newWin.document.writeln('<html><head><title>Stereo.ru</title>');
	newWin.document.writeln('');
	newWin.document.writeln('</head><body bgcolor="white" onKeyDown="if(window.event.keyCode==27){window.close();};"><table align="center" valign="middle"><tr><td><img src="'+path+'" style="position:absolute; left:0; top:0"></td></tr></table></body></html>');
	newWin.document.close();
}

function MM_jumpMenu(targ, selObj, restore){ //v3.0
	if(selObj.selectedIndex!=0){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; 	
	}
 
}

function ChooseInit(){
  if (navigator.appName == "Netscape") {
    layerStyleRef="layer.";
    layerRef="document.layers";
    styleSwitch="";
  }else{
    layerStyleRef="layer.style.";
    layerRef="document.all";
    styleSwitch=".style";
  }
}
function ChoseShowLayer(layerName){
  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
}

function ChooseHideLayer(layerName){
  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
}


function init(){


  if (navigator.appName == "Microsoft Internet Explorer") {
    layerStyleRef="layer.style.";
    layerRef="document.all[";
    styleSwitch="].style";
  }
  else{
	if(parseInt(navigator.appVersion)>=5){
	layerRef="document.getElementById("
	styleSwitch=").style";
	}
  	else{
	layerStyleRef="layer.";
    layerRef="document.layers[";
    styleSwitch="]";
	}
  }
}

function show(num){
  if (navigator.appName == "Microsoft Internet Explorer") {
    layerStyleRef="layer.style.";
    layerRef="document.all[";
    styleSwitch="].style";
  }
  else{
	if(parseInt(navigator.appVersion)>=5){
	layerRef="document.getElementById("
	styleSwitch=").style";
	}
  	else{
	layerStyleRef="layer.";
    layerRef="document.layers[";
    styleSwitch="]";
	}
  }
	//document.getElementById("sub"+num).style.visibility="visible";
	eval(layerRef+'"sub'+num+'"'+styleSwitch+'.visibility="visible"');
}

function hide(num){
  if (navigator.appName == "Microsoft Internet Explorer") {
    layerStyleRef="layer.style.";
    layerRef="document.all[";
    styleSwitch="].style";
  }
  else{
	if(parseInt(navigator.appVersion)>=5){
	layerRef="document.getElementById("
	styleSwitch=").style";
	}
  	else{
	layerStyleRef="layer.";
    layerRef="document.layers[";
    styleSwitch="]";
	}
  }
	//document.getElementById("sub"+num).style.visibility="hidden";
	eval(layerRef+'"sub'+num+'"'+styleSwitch+'.visibility="hidden"');
}

function all_checked(n){
	var k=document.forms[n].elements.length;
	for (i=0;i<k;i++){
		document.forms[n].elements[i].checked=true;
	}
}

function invert(){
	var k=document.forms[0].elements.length;
	var as=0;
	for (i=0;i<k;i++){
		if(document.forms[0].elements[i].checked){as++;}
	}
	if (as+3>k){
		alert("В сравнении должны участвовать как минимум две модели!");
	}
	else{
	for (i=0;i<k;i++){
		if(document.forms[0].elements[i].checked){
			document.forms[0].elements[i].checked=false;
		}
		else{document.forms[0].elements[i].checked=true;}
	}	
	document.forms[0].submit();	
	}

}

function countCheck(n){
	var k=document.forms[n].elements.length;
	var as=0;
	for (i=0;i<k;i++){
		if(document.forms[n].elements[i].checked){as++;}
	}
	if (as<2){
		alert("В сравнении должны участвовать как минимум две модели!");
	}
	else{
		if (as>20) {alert("В сравнении может участвовать не более 20 моделей!");}
		else{document.forms[n].submit();}
	}
}

function littleDict(theURL)
{window.open( theURL, 'd', 'width=420,height=180,left=0,top=0,scrollbars=1,status=0,resizable=0');}	

function confirm_del(url, text){
	if(confirm(text)){
		document.location=url;
	}
}

function confirm_del2(str)
{	
    c = confirm(str);
    if (c) {
       this.href = this.href + "&is_js_confirmed=1";
       return true;
    } else {
       return false;
    }
}

function award_descr(id, title)
{
	w = window.open("/award_pop_up.php?id="+id+"&title="+title, "award", "toolbar=no,directories=no,status=1, menubar=0, scrollbars=1, resizable=1, width=400, height=200, top=150, left=150")
	w.focus();
}

function isset(name)
{
    if (typeof(name) == "undefined") {
        return false;
    } else {
        return true;
    }
}

function checkField(field, deffield)
{
    if (!isset(deffield)) deffield = "Другая";

    if (!field.disabled && field.value == deffield) {
        field.value = "";
    }
    
    if (field.disabled && field.value == "") {
        field.value = deffield;
    }    
}