function anumtest(quant) {
	    var anum = /(^\d+$)/;
        if (!anum.test(quant)) {
            return -1;
        }
		return 1;
}

function trim(string) {
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

function qqq(numer, value) {
	document.notepadForm.action = document.notepadForm.action + '#start';
	document.notepadForm.goto.value = 'change';
	document.notepadForm.submit();
}


function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function notepad_add(url_action) {
	var url_action_ok = url_action;
	var req = getXmlHttp();
	req.open('GET', 'action.html?'+url_action_ok, true); 
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			//document.getElementById('vote_status').innerHTML = req.statusText
			if(req.status == 200) {
			   //alert("Ответ сервера: "+req.responseText);
			   alert(req.responseText);
			}
		}
    }
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
 	req.send(null); 
}

function notepad_check(url_action) {
	var url_action_ok = url_action;
	var req = getXmlHttp();
	req.open('GET', 'action.html?'+url_action_ok, true); 
	req.onreadystatechange = function() {
    }
  
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null); 
}


function vote() {
	var req = getXmlHttp()
	req.open('GET', '/img/vote.txt', true); 
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('vote_status').innerHTML = req.statusText
			if(req.status == 200) {
			   alert("Ответ сервера: "+req.responseText);
			}
		}
    }
  

	req.send(null); 
	document.getElementById('vote_status').innerHTML = 'Ожидаю ответа сервера...'
}


function mark(num, tnum, notecounter) {
	var num_name = num;
	var tnum_name = tnum;
	var re = /([^\d]+)/;
	var num_name = num_name.match(re);
	var tnum_name = tnum_name.match(re);

	for (i=1; i<=notecounter; i++)
	document.getElementById(num_name[0] + i).className="passive";
	document.getElementById(tnum_name[0] + 0).innerHTML=document.getElementById(tnum).innerHTML;
	document.getElementById(num).className="active";
}

function mark_num(num, tnum, notecounter) {
	var num_name = num;
	var tnum_name = tnum;
	var re = /([^\d]+)/;
	var num_name = num_name.match(re);
	var tnum_name = tnum_name.match(re);

	for (i=1; i<=notecounter; i++)
		document.getElementById(num_name[0] + i).className="passive";
	document.getElementById(tnum_name[0] + 0).innerHTML=document.getElementById(tnum).innerHTML;
	document.getElementById(num).className="active";
}




function PMA_markRowsInit() {
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}


function start_onload() {
	PMA_markRowsInit();
}


