
/////////////////////////////////////class\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var BricksGuru=new Class();
var Element=new Class();
var Positions=new Class();
var DomCompute=new Class();
var Iteration=new Class();
var Observer=new Class();
var BackBone=new Class();
var FireWork=new Class();
var Validator=new Class();
////////////////////////////////////////////////end class\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

///////////////////////////////////////////////class constructors and prototypes\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

///////////////////////////////////////////////Validation methods, form computing \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Validator.prototype.construct=function()
{  
	this.form="";
	this.form_elements=[];	
	this.form_invalids=[];
	this.types=Array('email','zip',"empty","integer","compare","min","max");
	this.form_return=false;  
	this.form_contor=0;
	this.bounderies=[];
	this.use_firework=0;
	this.form_print_invalids="step";
	}
Validator.prototype.attachForm=function($form_id,$sub)
{    
	this.form=$form_id;
	if($form_id!=null && $sub==null)
	 dom.find(engine.getIt($form_id),"[type,submit]"); 
	if($sub!=null) dom.foundTarget=engine.getIt($sub); 
	  if(dom.foundTarget!="" && dom.foundTarget!=null)
	    dom.foundTarget.onclick=function(){ return validator.executeFormValidation() } ;
		
	}
Validator.prototype.validate=function($field_id,$valid_type,$error)
{ 
    if($valid_type==null || $valid_type=="") $valid_type="[empty]";
	if(!engine.contains(this.types,$valid_type,"partial"))
	 {
		  alert("Please insert a valid  validation type for the field: "+$field_id);
		  return false;
		 }
	            this.form_elements[this.form_elements.length]=
	                     {
						   field:$field_id,
						   type:$valid_type,
						   error:$error,
						   broke:-1
	                   }
				this.form_contor++;	   
	}
Validator.prototype.condition=function($field,$type)
{
	this.bounderies[this.bounderies.length]={
		                field:$field,
						type:$type,
						index:this.form_contor-1
		}
	}
Validator.prototype.isEmpty=function(el)
{
	 if(el.value!="" && el.value!=null)
	   return true;
	 else
	   return false;
	}
Validator.prototype.isEmail=function(el)
{
	 if(regexpr.test("email",el.value))
	   return true;
	 else
	   return false;
	}
Validator.prototype.isZip=function(el)
{
	 if(el=="" || el==null)
	   return true;
	 else
	   return false;
	}	
Validator.prototype.hasMin=function(el,target)
{
    el=string.erase("( ) min",el);
	el=parseInt(el);
	if(target.length>=el) return true; else return false;
	}	
Validator.prototype.hasMax=function(el,target)
{
    el=string.erase("( ) max",el);
	el=parseInt(el);
	if(target.length<=el) return true; else return false;
	}	
Validator.prototype.hasLength=function(el,target)
{
	el=parseInt(el);
	if(target.length==el) return true; else return false;
	}		
Validator.prototype.identify=function($victim)
{ 
      switch(this.use_firework)
	   {
		   default:engine.getIt($victim).focus();break;
		   }
	}
Validator.prototype.isValid=function($field,type)
{
	  var el=engine.getIt($field);
	  type=string.erase("[ ]",type).split("|");	 
	  for(var i=0;i<=type.length-1;i++){ 
		  if(type[i].indexOf("(")!=-1){
		     temp_type=type[i].split("(");
             temp_type=temp_type[0];
			 }
		  else if(number.isInteger(type[i])) {
			    temp_type="number";
			  }	 
		  else temp_type=type[i]; 
	  switch(temp_type)
	    {
			case "empty": $bool=this.isEmpty(el); break;
			case "email": $bool=this.isEmail(el); break;
			case "integer": $bool=number.isInteger(el.value); break;
			case "compare":
			               $field=string.erase("[ ]",$field).split("|");
			               $bool=string.compare(engine.getIt($field[0]).value,engine.getIt($field[1]).value); break;
			case "min":    $bool=this.hasMin(type[i],engine.getIt($field).value); break;
			case "max":    $bool= this.hasMax(type[i],engine.getIt($field).value); break;
			case "number":   $bool=this.hasLength(type[i],engine.getIt($field).value); break;
			case "checked":   $bool=brick.use($field).checked(); break;
			}
		if($bool==false) 
		 {
			 for(var j=0;j<=validator.form_elements.length-1;j++){ 
			   if(validator.form_elements[j].field==$field){
			     validator.form_elements[j].broke=i;
			   }
			 }
			 return false;
		 }
	  }
	  return $bool;
	}
Validator.prototype.printInvalids=function()
{
	for(var i=0;i<=this.form_invalids.length-1;i++) 
	 for(var j=0;j<=this.form_elements.length-1;j++)
			   if(this.form_elements[j].field==this.form_invalids[i] )
			    {
			      if(this.form_elements[j].broke!=-1)
				      {
						  $err=string.erase("[ ]",this.form_elements[j].error).split("|");
						   if(this.form_elements[j].broke>($err.length-1))
						     this.form_elements[j].broke=($err.length-1);
							    alert($err[this.form_elements[j].broke]);
						  }
				  else { 
				     alert(this.form_invalids[i]);
				      }
                      this.identify(this.form_elements[j].field);
					  if(this.form_print_invalids=="step")
									       return false;
				}
}
Validator.prototype.hasBoundery=function($contor)
{
	for(var i=0;i<=this.bounderies.length-1;i++)
	   {
		   if(!this.isValid(this.bounderies[i].field,this.bounderies[i].type) && $contor>=this.bounderies[i].index)
		     return true;
		  else 
		     return false;
		   }
	}
Validator.prototype.executeFormValidation=function()
 {
	 for(var $i=0;$i<=validator.form_elements.length-1;$i++)
	   { 
		   
		  if(!validator.isValid(validator.form_elements[$i].field,validator.form_elements[$i].type) &&  !validator.hasBoundery($i) )
		    { 
				validator.form_invalids[validator.form_invalids.length]=validator.form_elements[$i].field;
				}
		   
		   }  
		   if(validator.form_invalids.length==0) 
		         validator.form_return=true; 
		   else  validator.printInvalids();	 
		         this.emptyContainers();  
		   return validator.form_return;
		  
	 }
Validator.prototype.emptyContainers=function()
{
	    this.form_invalids=[];
	}
///////////////////////////////////////////////FireWorks methods...this class computes effects on elements\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
FireWork.prototype.construct=function($type,$victim)
{    
	this.type=$type; 
	this.victim=$victim; 
	this.control=1;

	}

FireWork.prototype.options=function($type,$arg1,$arg2,$arg3,$arg4,$arg5)
 {
	 switch($type)
	 {
		 case "out":   
		      observer.activate("interval",this.fadeout,'',$arg1);
	    	if($arg2==null) $arg2=1;
			this.state=100;
			 observer.observe(this.type+$type,this.victim,this.state,$arg2);
		    break;
		case "in":   
		      observer.activate("interval",this.fadein,'',$arg1);
			  this.state=0
	    	if($arg2==null) $arg2=1;
			 observer.observe(this.type+$type,this.victim,this.state,$arg2);
			 engine.hash("get",this.victim,'',observer.bricks).filter("alpha",0);
		    break;
		case "line":   
		      observer.activate("interval",this.lineMotion,'',1); 
			observer.observe(this.type+$type,this.victim,$arg1,$arg2,$arg3);
			    break;	
		case "target":   
		      observer.activate("interval",this.target,'',1);
			  if($arg2==null) $arg2=1; 
			observer.observe(this.type+$type,this.victim,$arg1,$arg2);
			    break;	
		case "vertical":   
		if($arg2==null) $arg2=1;
		      observer.activate("interval",this.verticalScale,'',1);  
		  if(!observer.isObservedFirework(this.type+$type,this.victim))	  
		      observer.observe(this.type+$type,this.victim,$arg1,$arg2,$arg3);

			    break;			
		 } 
	 }
 FireWork.prototype.verticalScale=function()
{
     $events=observer.getEvents("scalevertical");
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($events[i].control==0)
	      { 
		   if($events[i].state=="in") $sign="-";
		    else if($events[i].state=="out") $sign="+";
			 else $sign="-"; 
		   if($events[i].arg1==null) $events[i].arg1=10;
		          dom.objSize($victim.obj,"set",'',eval(dom.objSize($victim.obj,"get").h+$sign+$events[i].arg2)); 
			if(dom.objSize($victim.obj,"get").h<=0 || (dom.objSize($victim.obj,"get").h>=$events[i].arg3 && $events[i].state=="out" ))	 $events[i].control=1;
		  }
	   }
	}	 
 FireWork.prototype.lineMotion=function()
{
 $events=observer.getEvents("motionline");
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($events[i].control==0)
	      {   
		    $distance=pos.distance($victim.obj,$events[i].state,$events[i].arg2);
		    if($distance.x<=$events[i].arg3 && $distance.y<=$events[i].arg3) $events[i].arg3=1;
			    $move=pos.getDirection($victim.obj,$events[i].state,$events[i].arg2)
			if($move.x!="=")
			  $nextx=pos.getLeft($victim.obj)+$move.x+$events[i].arg3;
			else 
			   $nextx=pos.getLeft($victim.obj);
			if($move.y!="=")
			  $nexty=pos.getTop($victim.obj)+$move.y+$events[i].arg3;
			else
			  $nexty=pos.getTop($victim.obj);
		    pos.move($victim.obj,eval($nextx),eval($nexty));
			if($move.x=="=" && $move.y=="=") $events[i].control=1;
		  }
	   }
	}
 FireWork.prototype.target=function()
{
	  $events=observer.getEvents("motiontarget");
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($events[i].control==0)
	      {  
		    $distance=pos.distance($victim.obj,engine.getIt($events[i].state)); 
		    if($distance.x<=$events[i].arg2 && $distance.y<=$events[i].arg2) $events[i].arg2--;
		    $move=pos.getDirection($victim.obj,engine.getIt($events[i].state))
			if($move.x!="=")
			  $nextx=pos.getLeft($victim.obj)+$move.x+$events[i].arg2;
			else 
			   $nextx=pos.getLeft($victim.obj);
			if($move.y!="=")
			  $nexty=pos.getTop($victim.obj)+$move.y+$events[i].arg2;
			else
			  $nexty=pos.getTop($victim.obj);
		    pos.move($victim.obj,eval($nextx),eval($nexty));
			if($move.x=="=" && $move.y=="=") $events[i].control=1;
		  }
	   }
	}	
FireWork.prototype.fadeout=function()
 {
    $events=observer.getEvents("fadeout");
	for(var i=0;i<=$events.length-1;i++){ 
	$victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
    if($events[i].control==0)
	  {
		  $victim.filter("alpha",$events[i].state); 
		  $events[i].state-=$events[i].arg2; 
		   if($events[i].state==0) $events[i].control=0;
		  } 
    	}
	 }
FireWork.prototype.fadein=function()
 {
    $events=observer.getEvents("fadein");
	for(var i=0;i<=$events.length-1;i++){ 
	$victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
    if($events[i].control==0)
	  {
		  $victim.filter("alpha",$events[i].state); 
		  $events[i].state+=$events[i].arg2; 
		   if($events[i].state==100) $events[i].control=0;
		  } 
    	}
	 }	 
//////////////////////////////////////////////////end firework \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

/////////////////////////////////////////////////////////Backbone - ajax- operations \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
BackBone.prototype.construct=function(url_way,tip,idu)
{   
	this.url=url_way;
	this.type=tip;
	this.id=idu;
	this.xmlHttp='';
	this.result=-1;
	}
BackBone.prototype.connect=function(){
	
    
  try
    {    // Firefox, Opera 8.0+, Safari
	 this.xmlHttp=new XMLHttpRequest();   
		 }
  catch (e)
    {    // Internet Explorer
	  try
        {      
		this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      }
      catch (e)
          {
         try
            {        
			this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        }
           catch (e)
                   { 
	         alert("Your browser does not support AJAX!");  
			         return false;  
					       }  
						       } 
							      }
	   this.result=null;						  
       this.xmlHttp.onreadystatechange=this.computeResult;
      
	   this.xmlHttp.open("GET",this.url,true);
       this.xmlHttp.send(null);	
	   
       
	}
BackBone.prototype.computeResult=function()
{
     if($ajax.xmlHttp.readyState==4)
       {
      if($ajax.xmlHttp.status == 200) {	  
	     if($ajax.type=="populate")
		   { 
		     if(engine.getIt($ajax.id).nodeName=="INPUT")
			 {
			   engine.getIt($ajax.id).value=$ajax.xmlHttp.responseText; 
			 }
			 else if(engine.getIt($ajax.id).nodeName=="SELECT")
			  {
			
				  }
			 else{ 
			   engine.getIt($ajax.id).innerHTML=$ajax.xmlHttp.responseText;
			 }
			 }
	   else if($ajax.type=="return")
		  {    
			 $ajax.result=$ajax.xmlHttp.responseText;  	
			 
			 }	
		 else if($ajax.type=="activate")
		  {   
     	    $function=$ajax.id+"('"+$ajax.xmlHttp.responseText+"')"; 
			 eval($function);
			 }		 
	   }
	   else { 
	    alert('\n\nThere was a problem with the request.\n\nStatus code: '+$ajax.status+'\n'+$ajax.statusText); } 
     }
	   
	} 
/////////////////////////////////////////////////////////////end \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

////////////////////////////////////////////////////////OBSERVER METHODS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\c
Observer.prototype.construct=function(){
	this.active_observers=[]; 
	this.element_handlers=[];
	this.bricks=[];
	this.fireworks=[];
	this.events=[];
}
Observer.prototype.isObservedFirework=function($event,$victim_search)
 {
	 $events=observer.getEvents($event); 
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($victim.obj.id==$victim_search) return true;
	   }
	   return false;
	 }
Observer.prototype.activateFirework=function($event,$victim_search)	
 { 
	 $events=observer.getEvents($event); 
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($victim.obj.id==$victim_search){  $events[i].control=1; }
	   }
	 }
Observer.prototype.deactivateFirework=function($event,$victim_search)	
 {
	 $events=observer.getEvents($event); 
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($victim.obj.id==$victim_search) $events[i].control=0;
	   }
	 }	 
Observer.prototype.observe=function($type,$victim,$init,$arg2,$arg3){ 
	this.events[this.events.length]=
	      {
			   operation:$type,
			   victim:$victim,
			   state:$init,
			   control:0,
			   last_action:null,
			   arg2:$arg2,
			   arg3:$arg3
			   }
	if(!engine.contains(observer.active_observers,"interval"+observer.taskManager))
	   observer.activate("interval",observer.taskManager,'',1);
			 
}
Observer.prototype.taskManager= function(){
	if(observer.events.length==0) observer.activate("kill_interval","interval"+observer.taskManager);
	$handle=iterator.arrayWalk(observer.events,0,1);
	$op=$handle.next();
	if($op && $op.control==1)
	   {
		   if($op.last_action!=null)
		     {
				 eval($op.last_action);
				 }
		   }

}
Observer.prototype.getEvents=function($op)
 {
	 var ev=[];
	 for($i=0;$i<=observer.events.length-1;$i++)
	  {
		  if(observer.events[$i].operation==$op || $op=="all")
		     ev[ev.length]=observer.events[$i];
		  } 
		  	 return ev;
	 }
Observer.prototype.stopPropagation= function(event){ 
    if (!event) var event = window.event; 
    if (event){ 
        event.cancelBubble = true; 
        if (event.stopPropagation) event.stopPropagation(); 
    } 
} 
Observer.prototype.activate=function(meth,object,priority,time,func){ 
if(object!="document") 
  if(typeof object!="function")
    $id=object.id;
  else $id=object;	
	else $id="document"; 
if(engine.contains(this.active_observers,meth+object) && priority!="absolute") return false;
	switch(meth)
	{
		
	    case "onmouseover":        this.active_observers[this.active_observers.length]=meth+$id;  
		                          eval(object).onmouseover=eval(func);
						          break;
		case "kill_onmouseover":     compactare(this.active_observers,getIndex(this.active_observers,"onmouseover"+$id),"out");	
									eval(object).onmouseover=null;
					         		break;	
	    case "onmousedown":        this.active_observers[this.active_observers.length]=meth+$id; 
		                          eval(object).onmousedown=eval(func);
						          break;
		case "onclick":          this.active_observers[this.active_observers.length]=meth+$id; 
		                          eval(object).onclick=eval(func);
						          break;
		case "kill_onclick":    compactare(this.active_observers,getIndex(this.active_observers,"onclick"+$id),"out");	
									eval(object).onclick=null;
					         		break;							  
		case "kill_onmousedown":   compactare(this.active_observers,getIndex(this.active_observers,"onmousedown"+$id),"out");	
									eval(object).onmousedown=null;
					         		break;						  
		case "onmousemove":      this.active_observers[this.active_observers.length]=meth+$id; 
		                          eval(object).onmousemove=eval(func); 
							     break;						  
		case "kill_onmousemove": compactare(this.active_observers,getIndex(this.active_observers,"onmousemove"+$id),"out");
		                         eval(object).onmousemove=null; 
								 break;
		case "onmouseup":          this.active_observers[this.active_observers.length]=meth+$id;  
		                          eval(object).onmouseup = eval(func); 
								  break;
		case "kill_onmouseup":     compactare(this.active_observers,getIndex(this.active_observers,"onmouseup"+$id),"out");
								  eval(object).onmouseup  =null; 
							      break;
		case "IE_drag_start":     this.active_observers[this.active_observers.length]=meth+$id; 
		                          document.ondragstart = function() {return false;}
		                          break;
		case "kill_IE_drag":       compactare(this.active_observers,getIndex(this.active_observers,"IE_drag_start"+"document"),"out");
        		                   document.ondragstart =null;
		                           break;
		case "interval":              this.active_observers[this.active_observers.length]=meth+$id; 
		                             engine.hash("set","interval"+object,setInterval(object,time));	
					                break;
		case "kill_interval":     compactare(this.active_observers,getIndex(this.active_observers,"interval"+$id),"out");  
		                          clearInterval(engine.hash("get","interval"+object));
		                            break;
		case "kill_select_start":    this.active_observers[this.active_observers.length]=meth+$id;
		                            eval(object).onselectstart =eval(func);	
		                            break;
		case "select_start_on": 
		                           compactare(this.active_observers,getIndex(this.active_observers,"kill_select_start"+$id),"out");
		                           eval(object).onselectstart =eval(func);	
		                           break;
		}
	
	}
Observer.prototype.growTree=function(node, num)
{
	 if (node.nodeType == Node.ELEMENT_NODE)  
      d1.write('<li><b><large>&lt;'+node.nodeName+'&gt;</large></b>');  
     else  
      d1.write('<li><b><large>'+node.nodeName+'</large></b>');  
     if (node.nodeType != Node.TEXT_NODE && node.nodeType != Node.ELEMENT_NODE)  
      d1.write(' <i>('+node_types[node.nodeType].toLowerCase().replace(/ node$/,'')+')</i> ');  
     if (node.attributes && node.attributes.length) {  
     d1.write('<ol type="A"> ')  
     for (var i=0;i<node.attributes.length; ++i)  
         this.growTree(node.attributes.item(i),i);  
     d1.write('</ol>')  
     }  
     if (node.childNodes && node.childNodes.length) {  
     d1.write('<ol>')  
     for (var i=0;i<node.childNodes.length;++i)  
         this.growTree(node.childNodes.item(i), i);  
     d1.write('</ol>')  
     }  
     d1.write("</li>\n");  
	}
Observer.prototype.debug=function(type,element)
{   
   
	if(type=="document_tree")
	 {
	  var w1=window.open('', 'TREE');  
      d1=w1.document;  
      d1.open();  
      d1.writeln('<h1>Document tree</h1>\n<ol>');  
      this.growTree(document,'',1);  
      d1.writeln('</ol>');  
      d1.close(); 
		 }
	else if(type=="dump")
	 {
		 
		 }
	}	
/////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//////////////////////////////////////////////||Iteration methods||\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Iteration.prototype.construnc=function()///////////////////////custom iteration with or without exeception throwing\\\\\\\\\\\\\\\\\\
{
	this.$index=0;
	this.StopIteration = function () {};
    this.StopIteration.prototype = new Error();
    this.StopIteration.name = 'StopIteration';
    this.StopIteration.message = 'StopIteration';
	}
Iteration.prototype.arrayWalk=function (array,start_index,tail) { ///// walking an array with prev and next\\\\\\\\\\\\\\\\
    if(start_index==null) start_index=0;
    var i = start_index;
	if(tail==null) tail=0;
    return {
        'next': function (increment) {
		 if(increment==null) increment=1; 
            if (i >= array.length) {
			  if(tail==0)
                throw StopIteration;
			  else i=0;
			   
            }
		    i=i+increment;
            return array[i-1];
        },
		 'prev': function (increment) {
			if(increment==null) increment=1;	 
            if (i < 0) {
            if(tail==0)
                throw StopIteration;
			 else i=array.length;
            }
			i=i-increment;
            return array[i+1];
        }
		 
    }
}

Iteration.prototype.stack=function (array,method) { ///// stack like -fifo - lifo  principel \\\\\\\\\\\\\\\\
var i = 0;
if(method==null) method="fifo";
 return {
        'pop': function () {
            if (array.length==0) {
                throw StopIteration;
            }
			if(method=="fifo")
			 {
			 var poped=array[0];
			 array=compactare(array,array.length-1,"out"); 
              return poped;
			 }
        },
		     'push': function (element) { 
              array=compactare(array,0,"in",element);
        }
		 
    }
}

/////////////////////////////////////|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

/////////////////////////////////////////////BRICK GURU MAIN OP\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
BricksGuru.prototype.construct=function()
{
 this.element_prop={width:0,height:0};
 this.innerTemp={};
 this.offsetTemp={};
    if (window.innerWidth) {
        this.innerTemp={x:window.innerWidth, y:window.innerHeight};
    } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
        this.innerTemp={x:document.body.parentNode.clientWidth, y:document.body.parentNode.clientHeight};
    } else if (document.body && document.body.clientWidth) {
       this.innerTemp={x:document.body.clientWidth, y:document.body.clientHeight};
    }
    if (window.pageYOffset) {
        this.offsetTemp={o_x:window.pageXOffset, o_y:window.pageYOffset};
    } else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
       this.offsetTemp={o_x:document.documentElement.scrollLeft,o_y:document.documentElement.scrollTop};
    } else if (document.body && document.body.clientWidth) {
        this.offsetTemp={o_x:document.body.scrollLeft, o_y:document.body.scrollTop};
    }
 this.window_prop={
     x:this.innerTemp.x,
     y:this.innerTemp.y,
     offset_x:this.offsetTemp.o_x,
     offset_y:this.offsetTemp.o_y ,
	 screen_x:screen.availWidth,
	 screen_y:screen.availHeight
};
 this.create=function(type,properties)
	{ 
     	  var handler=new Element(type,properties); 
		  engine.hash("set",handler.obj.id,handler,observer.bricks);	
		  return handler;
		}
 this.use=function(id)
    {   
	/////////////////////////////////singleton, create unic handler\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	  if(engine.hash("get",id,'',observer.bricks)==null){
		var handler=new Element("id",id);
		 engine.hash("set",id,handler,observer.bricks);
	  }
	  else
	  { 
		var handler=engine.hash("get",id,'',observer.bricks);   
		  }
		  return handler;
		}///////////////////////////////////////////////////////////////////////////
 this.blockScreen=function()
   {  
      if(engine.hash("get","blockscreen",'',observer.bricks)==null)
	    $brick=brick.create("div","id=blockscreen");
	  else
	    $brick=engine.hash("get","blockscreen",'',observer.bricks);
	  $brick.glue("guru_root");
	  $brick.filter("alpha",20);
	  $brick.visible(true);
	  observer.activate("onclick",$brick.obj,'','',"brick.freeScreen");
	    }
 this.freeScreen=function()
 {
	  engine.hash("get","blockscreen",'',observer.bricks).visible(false);
	  engine.hash("get","dialogbox",'',observer.bricks).visible(false);
	  observer.activate("kill_onclick",$brick.obj,'','',null);
	 }
 this.dialogBox=function($id,$type,$mspeed,$fspeed)
  {
	  if($id==null) $id="dialogbox";
	  if($type==null) $type="motion";
	  if($mspeed==null) $mspeed=6;
	  if($fspeed==null) $fspeed=1; var x=dom.objSize($id).h;
	  pos.move(engine.getIt($id),(brick.window_prop.screen_x/2),-200); 
	  $brick=brick.use($id);
	  $brick.visible(true);
	  $brick.filter("alpha",0); 
	  $brick.firework("motion").options("line",(brick.window_prop.screen_x/2),(brick.window_prop.screen_y/2)-200,$mspeed);
	  $brick.firework("fade").options("in",1,$fspeed); 
	  }

}
/////////////////////////////////////////end brick guru main ops\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//////////////////////////////DOM operations\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
DomCompute.prototype.construct=function()
{ 
  this.body=document.body;
  this.total_nodes=window.document.childNodes;
  this.foundTarget="";
  this.fragment=function(nr,type) ////////////return a fragment with a series of elements\\\\\\\\\\\
   {
	   var frag = document.createDocumentFragment();
        for( var i = 0, p; i < nr-1; i++ ) {
          p = document.createElement(type);
          frag.appendChild(p);
           }
		  return frag; 
	   }
}
DomCompute.prototype.objPadding=function(obj) {
	var elem = engine.getIt(obj);
      if(elem==null) elem=obj;
	var l = 0;
	var r = 0;
	var t = 0;
	var b = 0;
	if (elem.currentStyle)
	{
		if (elem.currentStyle.paddingLeft)
			l = parseInt(elem.currentStyle.paddingLeft, 10);
		if (elem.currentStyle.paddingRight)
			r = parseInt(elem.currentStyle.paddingRight, 10);
		if (elem.currentStyle.paddingTop)
			t = parseInt(elem.currentStyle.paddingTop, 10);
		if (elem.currentStyle.paddingBottom)
			b = parseInt(elem.currentStyle.paddingBottom, 10);
	}
	else if (window.getComputedStyle)
	{
		l = parseInt(window.getComputedStyle(elem,null).paddingLeft, 10);
		r = parseInt(window.getComputedStyle(elem,null).paddingRight, 10);
		t = parseInt(window.getComputedStyle(elem,null).paddingTop, 10);
		b = parseInt(window.getComputedStyle(elem,null).paddingBottom, 10);
	} 
	if (isNaN(l) == true) l = 0;
	if (isNaN(r) == true) r = 0;
	if (isNaN(t) == true) t = 0;
	if (isNaN(b) == true) b = 0;
	return {l:(l),r:(r),t:(t),b:(b)};
}
DomCompute.prototype.objSize=function(obj,type,width,height) {
    var elem = engine.getIt(obj); 
    if(elem==null) elem=obj;
    if(type==null) type="get";
    if(type=="set") {
		if(width!=null)
	    	elem.style.width=width+"px";
		if(height!=null)	
		elem.style.height=height+"px";
		}
    var w = 0;
    var h = 0;
    if (elem.offsetWidth) {//elem.offsetHeight=1000;
			w = elem.offsetWidth; h = elem.offsetHeight;
    } else if (elem.clip && elem.clip.width) {
			w = elem.clip.width; h = elem.clip.height;
    } else  {
			w = elem.style.pixelWidth; h = elem.style.pixelHeight;
    }
    
    w = parseInt(w, 10);
    h = parseInt(h, 10);
    
   // remove any original element padding
   var padding = this.objPadding(elem);
   w -= (padding.l + padding.r);
   h -= (padding.t + padding.b);
   return {w:(w), h:(h)};
}
DomCompute.prototype.getMargins=function(victim)
 {
	 var size=dom.objSize(victim); 
	 var left_=(parseInt(pos.getLeft(victim)));
	 var right_=(left_+parseInt(size.w));
	 var top_=(parseInt(pos.getTop(victim)));
	 var bottom_=(top_+parseInt(size.h));
	 return {
		     left:left_,
			 right:right_,
			 top:top_,
			 bottom:bottom_
		 };
	 
 }
DomCompute.prototype.attributes=function(obj,meth,name,value) ////////////////////computes the attributed of an html dom object
{    
    if(meth=="get"){
		for( var x = 0; x < obj.attributes.length; x++ ) {
         if( obj.attributes[x].nodeName.toLowerCase() == name ) {
			  return obj.attributes[x].nodeValue;	
           }
      }
	}
    else
	{
	    	obj.setAttribute(name,value);
		}
	}
DomCompute.prototype.anchors=function(name) ////////////////return a specified link\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
{
	var anchorTags = document.getElementsByTagName("a");
    for (var i = 0; i < anchorTags.length ; i++)
      {
        if(anchorTags[i].href==name) return anchorTags[i];
      }
	}
DomCompute.prototype.insertAfter=function( referenceNode, newNode ) //////////////inserts a nod after reference nod\\\\\\\\\\\\\
{
    referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}	
DomCompute.prototype.find=function(node,$target)
{   
    $target_temp=$target;
	$target=$target.replace("[","");
	$target=$target.replace("]","");
	$target=$target.split(",");  
	 switch($target[0])
		 {
			 case "type":$statement=node.type; break;
			 }
	
		   if($statement==$target[1])  dom.foundTarget=node;
	        if (node.childNodes != null) {
               for (var i=0; i < node.childNodes.length; i++) { 
                  this.find(node.childNodes.item(i),$target_temp);
                  }
                } 

		
	}
DomCompute.prototype.navigate=function(type,nod,value){ //////////////////////operations on nods\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  switch(type) {
	   case "first_parent": 
	                  return nod.parentNode;
                   break;
	   case "first_child": 
	        var kid=nod.firstChild,temp; 
	            while(kid && kid.nodeType==3){ 	
	 		           kid=dom.navigate("next_sibling",kid); 
		          }
	                  return kid;
                   break;	
	   case "last_child": 
	                  return nod.lastChild;
                   break;				   
	  case "next_sibling": 
	            var temp=nod.nextSibling;
				 while(temp && temp.nodeType==3){ 
					 nod=nod.nextSibling;
				 }
	             return  nod.nextSibling; 
                   break;
      case "first_sibling":
	             var tempObj=nod.nextSibling; 
				 while(tempObj && tempObj.nodeType==3)
				 {
					 	 tempObj=tempObj.nextSibling;
					 } 
                  return tempObj;
                 break;
      case "last_sibling":
				 var temp=nod.parentNode.lastChild;	  
				 while(temp && temp.nodeType==3){
				  temp=temp.previousSibling;
				 }
				 return temp;  
                 break;
	case "kids": 
  				var kids=[],temp;
				 for($i=0;$i<=nod.childNodes.length-1;$i++){ 
				    if(nod.childNodes[$i].nodeType==1)
					  kids[kids.length]=nod.childNodes[$i];
				 }
				 return kids;
                 break;			 
	case "swap": 
	         nod.parentNode.replaceChild(value.cloneNode(true), nod);
             value.parentNode.replaceChild(nod.cloneNode(true), value);
	         break;
	case "replace_child": 
	           var parent=dom.navigate("first_parent",nod);
			    try{
	             parent.replaceChild(nod,value);
				 }
				catch(e)
				 {
					 alert(e);
					 }
	            break;
           }
}
////////////////////////////////////////////end DOM operations\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\	

//////////////////////////////////////////////////////////Brick elements operations\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Element.prototype.construct=function(type,properties)
{ 
  
   if(type!="id"){  /////creates an eleement with the given properties\\\\
	      var prop=new Array(),chunk=new Array(),rule;
		  this.obj=document.createElement(type);
		  document.body.appendChild(this.obj);
		  if(properties!=null)
		   {
			   prop=properties.split(","); 
			    for(var i=0;i<=prop.length-1;i++)
				 {  
					chunk=prop[i].split("=");
				    rule=chunk[0];
				    this.obj=addCSS(this.obj,chunk[0],chunk[1]);
				 }
		   }
		   return this.obj;
       }
	 else
	  { ///////// return an element as an object\\\\\\\\\\
		  this.obj=engine.getIt(properties); 
		  this.id=properties;
		  this.x=pos.getLeft(this.obj);
		  this.y=pos.getTop(this.obj);
		  }
		 
	   
	}
Element.prototype.getStyle=function(styleProp)
{   
    var el=this.obj;
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}	
Element.prototype.visible=function($type,$option)
{
	if($type==true){
	 if($option=="visibility")	
	    this.obj.style.visibility="visible";
	 else if($option=="display")
	    this.obj.style.display="block";
	else if($option==null)	
	   {
		    this.obj.style.visibility="visible";
			this.obj.style.display="block";
		   }
	}
   else if($type==false)
   {
	 if($option=="visibility")	
	    this.obj.style.visibility="hidden";
	 else if($option=="display")
	    this.obj.style.display="none";
	else if($option==null)	
	   {
		    this.obj.style.visibility="hidden";
			this.obj.style.display="none";
		   }
   }
   else    //////////////// getter
     {
		 if($option==null)
		 if(this.obj.style.visibility=="hidden" || this.obj.style.display=="none") return false;
		   else return true;
		 else if($option=="visibility")
		         if(this.obj.style.visibility=="hidden") return false;
			  else 	  if(this.obj.style.display=="none") return false;
			    else return true;
		 }
	}
Element.prototype.firework=function($type)
  {
	   return new FireWork($type,this.obj.id);
	  }
Element.prototype.dumpFirework=function($type,$method)
{
	$name=$type+$method;
	$events=observer.getEvents("all");
	$temp=[];
	 for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks); 
		  if($victim.obj.id!=this.obj.id)
		     $temp[$temp.length]=$events[i];
	   }
	   observer.events=$temp;
	}
Element.prototype.fireworkLastAction=function($function,$event)
 {   
   if($event==null) $event="all";
   $function=$function+"('"+this.obj.id+"')";
	$events=observer.getEvents($event); 
	  for(var i=0;i<=$events.length-1;i++)
	   { 
	     $victim=engine.hash("get",$events[i].victim,'',observer.bricks);
		  if($victim.obj.id==this.obj.id){ 
		     $events[i].last_action=$function;
		  }
	   }
	     
	 }
Element.prototype.replace=function(id)
{         
 	 dom.navigate("replace_child",engine.getIt(id),this.obj);
	}
Element.prototype.swap=function(id)
{         
 	 dom.navigate("swap",engine.getIt(id),this.obj);
	}	
Element.prototype.resizeTo=function(width,height)
{
  var NewWidth =width;
  if(height==null)
   var NewHeight = Math.round(NewWidth * .667);
  else
   var NewHeight=height;
  dom.objSize(this.obj,"set",NewWidth ,NewHeight );
}	
Element.prototype.limitText=function($type,limit,print_id)
{    
  //observer.activate("onkeydown",this.obj,'','',"drag_handler.dragOff");
  if($type=="chars")
	var nrc=this.obj.value.length;
 else  if($type=="words")
   {
	  var tmp=this.obj.value.split(" ");
	  var nrc=tmp.length;
	   } 
	var ramase=limit-nrc;
	if(ramase<=0)
	{
	var text_redus=this.obj.value.substr(0,limit);
	this.obj.value=text_redus;
	ramase=limit;
     }
    if(engine.getIt(print_id).readOnly ==false)	 engine.getIt(print_id).readOnly =true;  
	var afis=engine.getIt(print_id);
	afis.value=ramase+'/'+limit;
	 
	}
Element.prototype.filter=function(type,nr) { ///////////////////use filters on elements\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	  var element=this.obj;  
      var style = element.style;
	if(type='alpha'){
	  var alpha=nr; 
      if( style.MozOpacity != undefined ) { //Moz and older
       style.MozOpacity=(alpha/100);   // in firefox, moz rage 0.0 .. 1.0 (0.(9))
      }
      else if( style.filter != undefined ) { //IE
        style.filter = "alpha(opacity=0)"; 
        element.filters.alpha.opacity = ( alpha ); 
      }
      else if( style.opacity != undefined ) { //Opera
      style.opacity =alpha;
      }
    }
}
Element.prototype.dragOn=function()
{  
if(engine.contains(dragArray,this)){
  dragObject=this;
if(dragObject.style.position!="absolute") dragObject.style.position="absolute";
   observer.activate("onmouseup","document",'','',"drag_handler.dragOff");
   pos.offsetY=(XY.y-parseInt(pos.getTop(dragObject)));
   pos.offsetX=(XY.x-parseInt(pos.getLeft(dragObject)));	
   	     drag_flag=1;  
    	 document.body.style.cursor=cursors[5];
	     observer.activate("interval","DragON()",'',1); 
		 observer.activate("kill_select_start","document",'','',"function () { return false; }"); ///////// no text selections
		 observer.activate("IE_drag_start"); //////////////////only for IE
      } 
	   return false;
	}
Element.prototype.dragOff=function(){
    	   observer.activate("kill_onmouseup","document",'','',"drag_handler.dragOff"); 
		   observer.activate("kill_interval","DragON()",'',1);
		   observer.activate("select_start_on","document",'','',null);
		   observer.activate("kill_IE_drag");
		   drag_flag=0;
		   dragObject=null;
		   XY.x=0;
		   XY.y=0;
		document.body.style.cursor=cursors[0];
	}	
	
Element.prototype.drag=function(type) /////////////////drags an element after the mouse\\\\\\\\\\\\\\\\\\\
 {  observer.activate("onmousemove","document","",'',"updateMouse"); 
    dragObject  = this.obj;
   if(type==null || type=="mousedown"){
	  drag_handler=this;
      observer.activate("onmousedown",dragObject,"absolute",'',drag_handler.dragOn);
   } 
    dragArray[dragArray.length]=dragObject; 
    }
Element.prototype.resizeOn=function()
{ 
	if(engine.contains(resizeArray,this)){
       resObject=this; 
       observer.activate("onmouseup","document",'','',"resize_handler.resizeOff");
       res_flag=1;  
	   observer.activate("interval","ResizeON()",'',1); 
      } 

	}
Element.prototype.startResize=function()
{ 
	alert("test");
//  resize_handler.resizeTo(400);
	}	
Element.prototype.resizeOff=function()
{
	
	}
Element.prototype.resize=function() /////////////////drags an element after the mouse\\\\\\\\\\\\\\\\\\\
 {  observer.activate("onmousemove","document","",'',"updateMouse"); 
    resObject  = this.obj;
    resize_handler=this;
    observer.activate("onmouseover",resObject,"absolute",'',resize_handler.resizeOn);
    resizeArray[resizeArray.length]=resObject; 
    }	
Element.prototype.glue=function(pilar,offset_type,offset,offset_)
	      {  
	if(pilar!="guru_root"){	  
        if(this.obj.style.position!="absolute") this.obj.style.position="absolute";
        if(offset_type!=null)
		    {
			if(offset_type=="left"){
		        var left=parseInt(pos.getLeft(engine.getIt(pilar)))+offset; 
	              var top=parseInt(pos.getTop(engine.getIt(pilar)));		
			}
			else if(offset_type=="top")
			{
				var left=parseInt(pos.getLeft(engine.getIt(pilar))); 
	                  var top=parseInt(pos.getTop(engine.getIt(pilar)))+offset;		
				}
			 else
			   {
				 var left=parseInt(pos.getLeft(engine.getIt(pilar)))+offset; 
	              var top=parseInt(pos.getTop(engine.getIt(pilar)))+offset_; 
				   }
			}
			else
			{  
	
		      var left=parseInt(pos.getLeft(engine.getIt(pilar))); 
	            var top=parseInt(pos.getTop(engine.getIt(pilar)));


				}  
	}
	else if(pilar=="guru_root") 
	   {
		    var left=0;
			var top=0;
		   }
		pos.move(this.obj,left,top)		
		  }
Element.prototype.checked=function($set)
 {
	  if($set==null)
	   return this.obj.checked;
	  else
	   this.obj.checked=$set;
	 }		  
//////////////////////////////////////////////////////end Brick elements operatiojns \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

////////////////////////////////////////////Positioning operations \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Positions.prototype.construct=function()
{
this.lastMouseX=0;
this.lastMouseY=0;
this.offsetX=0;
this.offsetY=0;
this.getLeft=function(obj)
	      {   
            var curleft = 0; 
             while(obj.offsetParent) {
                curleft += obj.offsetLeft;
                obj = obj.offsetParent;
             } 
            return curleft;
         }
 this.getTop=function(obj) 
        {
            var curtop = 0;
            while(obj.offsetParent)     {
                 curtop += obj.offsetTop;
                 obj = obj.offsetParent;
            }
          return curtop;
        }
 this.getMouse=function (e) {
	       if(e.pageX ){ 
		       return {x:e.pageX, y:e.pageY};
	          }
      	return {
	        	x:e.clientX + document.body.scrollLeft - document.body.clientLeft,
	        	y:e.clientY + document.body.scrollTop  - document.body.clientTop
	           };
 
		   }
 this.move=function(victim,left,top)
		{ 
      if(victim.style.position!="absolute") victim.style.position="absolute";
		if(victim.style){  
		 victim.style.top=top+"px"; 
		 victim.style.left=left+"px"; 
		}
		else
		{  
		 victim.top=top+"px";
		 victim.left=left+"px"; 
		
			}
		}
 this.getDirection=function($victim,$target,$arg)
  {
	      if($arg==null)
		  {
	  		  $targetx=pos.getLeft($target);
			  $targety=pos.getTop($target);
			  $victimx=pos.getLeft($victim);
			  $victimy=pos.getTop($victim);	  
           }
		   else
		   {
			  $targetx=$target;
			  $targety=$arg;
			  $victimx=pos.getLeft($victim);
			  $victimy=pos.getTop($victim);	 
			   }
        if(($targetx-$victimx)>0)
		   {
			   var $x="+";
			   }
		else   if(($targetx-$victimx)<0)
		   {
			   var $x="-";
			   }	 
	    else   var $x="=";	
	    if(($targety-$victimy)>0)
		   {
			   var $y="+";
			   }
		else   if(($targety-$victimy)<0)
		   {
			   var $y="-";
			   }	 
	    else   var $y="=";
           
	      return {x:$x,y:$y};
	  }
this.distance=function($victim,$target,$arg)
  {           
         if($arg==null)
		 {
	  		  $targetx=pos.getLeft($target);
			  $targety=pos.getTop($target);
			  $victimx=pos.getLeft($victim);
			  $victimy=pos.getTop($victim);	  
           }
		   else
		   {
			  $targetx=$target;
			  $targety=$arg;
			  $victimx=pos.getLeft($victim);
			  $victimy=pos.getTop($victim);	 
			   }
			  return {x:(Math.abs($targetx-$victimx)),y:(Math.abs($targety-$victimy))};
	}
}

/////////////////////////////////////////////end positioning operations]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

////////////////////////////////////////////////////////end prototypes and constructors\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//////////////////////////////initializari]\\\\\\\\\\\\\
var brick=new BricksGuru("0");
var pos=new Positions("0");
var dom=new DomCompute("0");
var iterator=new Iteration("0");
var observer=new Observer("0");
var validator=new Validator("0");
//////////////////////////end inituri\\\\\\\\\\\\\\\\\\\\

	

