(function (){
var interval=null;
var div=null;
var TimeoutId=null;

var ZD = {
 // vars
 http_request : false,
 //basic
 dcw : function (s) { document.write(s+"<br>"); },
 ge : function (id) { return document.getElementById(id); },
 gn : function (id) { return document.getElementsByName(id); },
 gev : function (id) { return document.getElementById(id).value; },
 gtn : function (name) { return document.getElementsByTagName(name); },
 debug : function (str,id,is_append,sep){
  if(!sep){
   sep="<br>";
  }
  if(_.ge(id)){
   if(is_append){
    _.ge(id).innerHTML+=str+sep;
   }else{
    _.ge(id).innerHTML=str;
   }
  }else{
   if(_.ge('debug')){
    if(is_append){
     _.ge('debug').innerHTML+=str+sep;
    }else{
     _.ge('debug').innerHTML=str;
    }
   }
  }
 },
 
 //ajax
 http_get : function (murl, parameters, trg) {
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    _.http_request = new XMLHttpRequest();
    if (_.http_request.overrideMimeType) {
      _.http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      _.http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        _.http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!_.http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
  eval("_.http_request.onreadystatechange = "+trg+";");
  _.http_request.open('GET', murl + "?" + parameters, true);
  _.http_request.send(null);
  return true;
 },
 http_post : function (murl, parameters, trg) {
  //parameters=parameters+"url="+document.location.href+"&title="+escape(document.title)+"&";
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    _.http_request = new XMLHttpRequest();
    if (_.http_request.overrideMimeType) {
      _.http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      _.http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        _.http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!_.http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
  _.http_request.onreadystatechange = alertContents;
  _.http_request.open('POST', murl, true);
  _.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  _.http_request.setRequestHeader("Content-length", parameters.length);
  _.http_request.setRequestHeader("Connection", "close");
  _.http_request.send(parameters);
  return true;
 },
 
 //effects
 color_hex2dec : function (color_str) {
   var r=eval("0x"+color_str.substring(0,2));
   var g=eval("0x"+color_str.substring(2,4));
   var b=eval("0x"+color_str.substring(4,6));
   return {r : r, g : g, b : b}; //color obj
 },
 color_dec2hex_obj : function (color_obj) {
   var str=_.hex_zero(color_obj.r.toString(16))+_.hex_zero(color_obj.g.toString(16))+_.hex_zero(color_obj.b.toString(16));
   return str.toUpperCase();
 },
 hex_zero : function (z){
  var n=eval("0x"+z);
  if(isNaN(n))
   return '00'; 
  if(z.length==1){
   return '0'+z;
  }else if(n.toString(10)<0){
   return '00'; 
  }else if(n.toString(10)>255){
   return 'FF'; 
  }else{
   return z;
  }
 },
 motion : function(f) {
		//TimeoutId = setTimeout(function(){some_motion()}, f);
	},
 color_go : function(id,color_from,color_to,trg,step,speed) {
  if(TimeoutId != null){
 		clearInterval(TimeoutId);
 		TimeoutId = null;
 	}
 	if(interval != null){
 		clearInterval(interval);
 		interval = null;
 	}
  var obj_id=_.ge(id);
  var nob_cf=_.color_hex2dec(color_from);
  var nob_ct=_.color_hex2dec(color_to);
  var step=(parseInt(step)>=1 && parseInt(step)<=3)?parseInt(step):1;
  var speed=(parseInt(speed)>=1 && parseInt(step)<=9)?parseInt(speed):5;
		var nob_cc=nob_cf;
		direct={};
		direct.r=(nob_cc.r > nob_ct.r)?"down":"up";
		direct.g=(nob_cc.g > nob_ct.g)?"down":"up";
		direct.b=(nob_cc.b > nob_ct.b)?"down":"up";
		obj_id.style.backgroundColor="#"+color_from;
		var _go = function() {
		  step=parseInt(step+0.4);
		  
				if (nob_cc.r != nob_ct.r){
				 nob_cc.r = float_numb(nob_cf.r,nob_ct.r,direct.r,step);
				}
				if (nob_cc.g != nob_ct.g) {
					nob_cc.g = float_numb(nob_cf.g,nob_ct.g,direct.g,step);
				}
				if(nob_cc.b != nob_ct.b){
					nob_cc.b = float_numb(nob_cf.b,nob_ct.b,direct.b,step);
				}
				var nc=_.color_dec2hex_obj(nob_cc);
				obj_id.style.backgroundColor="#"+nc;
				if(nob_cc.r === nob_ct.r && nob_cc.g === nob_ct.g && nob_cc.b === nob_ct.b){
					clearInterval(TimeoutId);
					_.del_div(trg.name);
				}
				function float_numb(n,m,d,s){
				 var s=(parseInt(s)>=1)?s:1;
  		  if(d=="down" && n>m){
  				  n -= s;
  				}else if(d=="down" && n<m){
  				  n=m;
  				}
  				if(d=="up" && n<m){
  					 n += s;
  				}else if(d=="up" && n>m){
  				  n=m;
  				}
  				return n;
  		}
		}
		TimeoutId = setInterval(_go, speed);
	},

 
 //func
 set_ck : function (name, value, expire) {
  document.cookie = name + "=" + escape(value)+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
	},
	get_ck : function (Name) {
		var nr='';
		var cookies=document.cookie;
		var cookies2="";
    for (var i=0;i<cookies.length;++i) {
      var chrn=cookies.charAt(i);
      if (chrn!=" ") cookies2 += chrn;
    }
  var nvpair=cookies2.split(";");
  for(var i=0;i<nvpair.length;++i){
    var splitValues=nvpair[i].split("=");
    if(splitValues[0]==Name){
      nr=unescape(splitValues[1]);
      break;	
    }
  }
  return nr;
	},
	delete_ck : function (name, path, domain){
		if(get_cookie(name)){
			document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") +
		 ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	},
	act_ck : function (name, value, act){
		var today = new Date();
		var expires = new Date();
		if(act=="a"){
			expires.setTime(today.getTime() + 1000*60*60*24*365);
			set_cookie(name,value,expires);
		}else{
			delete_cookie(name);
		}
	},
	v_email : function (email){
  if(!email.match(/^([0-9a-z\-\._]+)@([0-9a-z\-]+)\.([0-9a-z\-\.]+)$/ig)){
   return (false);
  }else{
	 	return (true);
	 }
 },
 del_div : function (ff) {
 	var obj=eval("document."+ff);
 	if(div) obj.removeChild(div);
 	if(TimeoutId != null){
 		clearInterval(TimeoutId);
 		TimeoutId = null;
 	}
 	if(interval != null){
 		clearInterval(interval);
 		interval = null;
 	}
 },
 searchf_arr : function (f,id_arr,info_arr,cl_from,cl_to) {
  var is_ok=false;
  var id=null,info="";
  for(var i=0;i<id_arr.length;++i){
    id=id_arr[i];
    info=info_arr[i];
    if(div) div.innerHTML="";
   	if(_.ge(id)&& _.gev(id)==""){
   	  _.div_alert(f,id,info,cl_from,cl_to);
   		_.ge(id).focus();
   		is_ok=false;
   		break;
   	}else{
   	  if(id && _.gn(id)){
   	  var objs=_.gn(id);
   	  if(objs.length>0){
   	    var is_f=0;
   	    var cur_id=null;
   	    cur_id=objs[0].getAttribute('id');
     	  for(var j=0;j<objs.length;++j){
     	    if(objs[j].getAttribute('type')=="radio"){
     	      if(objs[j].checked){
     	         is_f=1;
     	         break;
     	      }
     	    }else if(objs[j].getAttribute('type')=="checkbox"){
     	      if(objs[j].checked){
     	         is_f++;
     	      }
     	    }else{
     	     is_f=1;
     	     //_.debug("type: "+objs[j].getAttribute('type'),"debug",1," ");
     	    }
     	  }
     	  if(is_f>0){
     	     is_ok=true;
     	  }else{
     	      _.div_alert(f,cur_id,info,cl_from,cl_to);
     	      is_ok=false;
         		break;
     	  }
   	  }
   		}
   	}
  }
  return is_ok;
 },
 div_alert : function (f,cur_id,info,cl_from,cl_to) {
   if(!cl_from)
     cl_from="FB9C39";
   if(!cl_to)
     cl_to="FFFFFF";
   _.color_go(cur_id,cl_from,cl_to,f,2);
   if(!div) div = document.createElement('div');
   div.className="err";
   div.id="errDiv";
   div.style.position="absolute";
   div.style.top=_.ge(cur_id).style.height;
   div.style.left="0px";
   f.appendChild(div);
   try{
     var pos = Position.get(cur_id);
     pos.top+=22;
     Position.set('errDiv',pos);
   }catch (ex){
     //_.debug(ex.description);
   }
   div.innerHTML=info;
 }

}
if(!window._){window._=ZD;}
})();


window.onload = function () {
  if(_.ge("pid")){
    _.http_get('/avail.php', "id="+_.gev("pid"), "chk_avail");
  }
}




function chk_avail(){
  if (_.http_request.readyState == 4) {
  	 if (_.http_request.status == 200) {
        var csq = _.http_request.responseText;
        
          if(_.ge("avail_btn") && csq.match(/^ok: ([0-9a-z]+) \[/i)){
            _.ge("avail_btn").src="/images/avail.jpg";
          }
          if(_.ge("avail_btn") && csq.match(/^err: noURL \[/i)){
            _.ge("avail_btn").style.display="none";
          }
          if(_.ge("price") && csq.match(/^ok: \[([0-9\.]+)\]$/i)){
            //_.ge("price").innerHTML="<font color=red>"+RegExp.$1+"</font>";
          }
        
      }else{
        //alert("Error: "+_.http_request.status);
      }
  }
}

