function getEl(id){
    //return $(id);
    if(document.layers){
        return document.layers[id];
    }
    if(document.all && document.all.item){
        return document.all[id];
    }
    if(document.getElementById){
        return document.getElementById(id);
    }
}

function formatNumber (num, decplaces) {
    num = parseFloat(num);
    if (!isNaN(num)) {
        var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
        if (str.indexOf("e") != -1) {
            return "Out of Range";
        }
        while (str.length <= decplaces) {
            str = "0" + str;
        }
        var decpoint = str.length - decplaces;
        return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
    } else {
        return "NaN";
    }
}

var is;
var _url;
var _header;

function imShow(header, url, w, h){
	_url = url;
	_header = header;
	if((w == '')||(h == '')){
		return;
	}
	// is.focus( );
	// make sure it isn't already opened
    if (!is || is.closed) {
	    var left = parseInt((screen.availWidth/2) - (w/2));
	    var top = parseInt((screen.availHeight/2) - (h/2));
	    var windowFeatures = "width=" + w + ",height=" + h + 
	        ",left=" + left + ",top=" + top + 
	        ",screenX=" + left + ",screenY=" + top;
		is = window.open("", "imShow", windowFeatures);
        // newWindow = window.open("","sub","status,height=200,width=300");
        // delay writing until window exists in IE/Windows
        setTimeout("writeToWindow()", 50);
    } else if (is.focus) {
        // window is already open and focusable, so bring it to the front
        is.focus( );
    }
}

function writeToWindow() {
    // assemble content for new window
    var newContent = "";
    //alert (_header);
    newContent += "<html><head><title>"+_header+"</title>";
    newContent += "<style>body {border:0 solid; padding:0; margin:0; }</style></head>";
    newContent += "<body>";
    newContent += "<img src='"+_url+"' alt='"+_header+"' width='100%' hspace='0' vspace='0'/>";
    newContent += "</body></html>";
    // write HTML to new window document
    //is.document.body.style.border = "0";
   // is.document.body.style.padding = "0";
    //is.document.body.style.margin = "0";
    is.document.write(newContent);
    is.document.close( ); // close layout stream
}




function chcount(){
	src = getEl("textus");
	targ = getEl("charco");
	targ.value = 150-src.value.length;
	//alert("asdad");
}

function stcount(ob){
	v = setInterval(chcount, 500);
}

function cuc(){
	var fr = getEl("calcfrom");
	var to = getEl("calcto");
	var v1 = getEl("valu1");
	var v2 = getEl("valu2");
	var $to = fr.value.split(",").join(".");
	$to = Math.abs(parseFloat($to));
	if(isNaN($to)){
		to.value = "#.####";
		return;
	}
	to.value = formatNumber($to*curs[v2.value]/curs[v1.value], 2);
}

function init(){
}

function bea_set(el, large){
	// alert(el);
	$('bea_big').src = "beauty/"+large;
	get_ajx_Info();
}

function get_ajx_Info(){
	var src = $("bea_big").src.replace(/.*beauty\/large([0-9]+).+/g, '$1');
	// alert(src);
	var da = new Date();
	var url = '/extra/beauty/vote.'+src+".xml?ts="+da.valueOf( );
	new Ajax.Request(url,
  {
    method:'get',
    onSuccess: function(transport){
      parseSucc(transport);
    }
  });
}

function vf(vote){
	var src = $("bea_big").src.replace(/.*beauty\/large([0-9]+).+/g, '$1');
	var da = new Date();
	var url = '/extra/beauty/vote.'+src+".xml?ball="+vote+"&ts="+da.valueOf( );
	new Ajax.Request(url,
	{
		method:'POST',
		parameters: { ball: 'lalala' },
		onSuccess: function(transport){
	      parseSucc(transport);
	    },
	    onFailure: function(){ }
	}
	);
	return false;
}

function parseSucc(transport){
	var response = transport.responseText || "no response text";
      if(response.match(/err/)){
      	return;
      }
      var arr = response.split(/~/);
      $('vtrs_count').innerHTML = arr[1];
      $('vtrs_ball').innerHTML = formatNumber(arr[2], 2);
      $('avgball').innerHTML = formatNumber(arr[5], 2);
      // alert(arr[3]);
      max = parseInt(arr[3]);
      if(max != 0){
      	// alert(max);
  		// alert($('vf'+max).src);
      	for(i = 1; i <= max; i++){
      		// alert(i);
      		$('vf'+i).src = "/img/bea/eye_on.png";
      	}
      	for(i = max+1; i<11; i++){
      		$('vf'+i).src = "/img/bea/eye_off.png";
      	}
      } else {
      	for(i = 1; i <= 10; i++){
      		$('vf'+i).src = "/img/bea/eye_off.png";
      	}
      }
      
      // alert("Success! \n\n" + arr);
}
