// <![CDATA[
var req = null;
var d = document;
var cob = new Array();
var c = 0;
var chil = isIE(true) ? 'children' : 'childNodes';

function setbg(care, bgu, repeat) {
    if(!repeat) repeat = 'no-repeat';
    $(care).style.background = 'url('+tpl+'images/'+bgu+') '+repeat;
}

function setOpacity(care, cat) {
	if(isIE(true)) 
		care.style.filter = 'alpha(opacity='+cat*100+')';
	else
		care.style.opacity=cat;
}

function email_valid(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var rdot=str.substring(str.indexOf(dot)+1).length
	if(rdot > 3) {
		alert("Invalid E-mail")
		return false
	}
	if (lat==-1){
		alert("Invalid E-mail")
		return false
	}
	if (lat==-1 || lat==0 || lat==lstr){
		alert("Invalid E-mail")
		return false
	}
	if (ldot==-1 || ldot==0 || ldot==lstr){
		alert("Invalid E-mail")
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail")
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail")
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail")
		return false
	}
	if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail")
		return false
	}
	return true					
}

function debug(el, onlyone) {
    if(onlyone)
        $('debug').innerHTML = el.toString();
    else {
        if(!el) el = '&nbsp;';
        if($('debug').innerHTML) $('debug').innerHTML += '; ';
        $('debug').innerHTML += el.toString();
    }
}

function sendReq(getline) {
    if(!req) {
        InitXMLHttpRequest();
        req.open("GET", 'req/'+getline, false);
        req.send(null);
        var response = req.responseText;
        req = null;
        return response;
   }
}

function phpSend() {
    var getline = '';
    for(i=0;i<arguments.length;i++)
        getline += (i>0 ? '/':'') + arguments[i];
    var response = 'none';
    while (response == 'none')
        response = sendReq(getline);
    //debug(response);
    return response;
}

String.prototype.reverse = function(){
    splitext = this.split("");
    revertext = splitext.reverse();
    reversed = revertext.join("");
    return reversed;
}
Number.prototype.toPrice = function(d){
    d = d ? d : '.';
    nv = Math.round(this);
    nv = nv.toString();
    nv = nv.reverse();
    res = nv.substring(0,3);
    for(i=3;i<nv.length;i++)
        if(!(i % 3))
            res = res+d+nv.substring(i,i+3);
    nv = res.reverse();
    return nv;
}

function isIE(incl7) {
   if (navigator.appName == 'Microsoft Internet Explorer') {
       var arVersion = navigator.appVersion.split("MSIE");
       var version = parseFloat(arVersion[1]);
       if(incl7 && version) return true;
       if (version < 7)
            return true;
       else
            return false;
   } else 
        return false;
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   if (isIE()) {
      for(var i=0; i<document.images.length; i++) {
         var img = document.images[i];
         var imgName = img.src.toUpperCase();
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            var imgID = (img.id) ? 'id="' + img.id + '" ' : '';
            var imgClass = (img.className) ? 'class="' + img.className + '" ' : '';
            var imgTitle = (img.title) ? 'title="' + img.title + '" ' : '';
            var imgonclick = (img.onclick) ? img.onclick.toString().substring(22,(img.onclick.toString().length-2)) : '';
            var imgClick = (imgonclick) ? 'onclick="'+ imgonclick + '" ' : '';
            var imgonmouseover = (img.onmouseover) ? img.onmouseover.toString().substring(22,(img.onmouseover.toString().length-2)) : '';
            var imgMouseOver = (imgonmouseover) ? 'onmouseover="'+ imgonmouseover + '" ' : '';
            var imgonmouseout = (img.onmouseout) ? img.onmouseout.toString().substring(22,(img.onmouseout.toString().length-2)) : '';
            var imgMouseOut = (imgonmouseout) ? 'onmouseout="'+ imgonmouseout + '" ' : '';
            var imgStyle = 'display:inline-block;' + img.style.cssText;
            if (img.align == "left") imgStyle = 'float:left;' + imgStyle;
            if (img.align == "right") imgStyle = 'float:right;' + imgStyle;
            if (img.parentElement.href) imgStyle = 'cursor:hand;' + imgStyle;
            img.outerHTML = '<span ' + imgID + imgClass + imgTitle + imgClick + imgMouseOver + imgMouseOut
            + ' style="width:' + img.width + 'px; height:' + img.height + 'px;' + imgStyle + ';filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img.src + '\', sizingMethod=\'scale\');"></span>';
            i = i-1;
         }
      }
   }
}

d.onmousemove = getMouseXY;
function getMouseXY(e) {
  if(isIE(true)) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + d.documentElement.scrollLeft;
    tempY = event.clientY + d.documentElement.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  mpos = new Array(tempX,tempY);
  return true;
}
function readacp(tex) {
    $('read').innerHTML = tex;
    $('read').style.display = 'block';
    $('read').style.left = (mpos[0]+20)+'px';
    $('read').style.top = (mpos[1]-10)+'px';
}

function InitXMLHttpRequest() {
	// Make a new XMLHttp object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function Preload() {
  if (d.images) {
	  d.prArr=new Array();
	  var a=Preload.arguments;
	  for(i=0; i<a.length; i++) {
		d.prArr[i]=new Image; 
		d.prArr[i].src=tpl+'images/'+a[i];
	  }
  }
}
// ]]>

