///////////////  === utilities
function hideFrame(id)
{
var ele = document.getElementById(id);
if (ele) {//ele.style.display = "none";
          document.body.removeChild(ele);
}
var ele1 = document.getElementById('bookdiv');
if (ele1) {//ele.style.display = "none";
          document.body.removeChild(ele1);
}
}

//////////////////////////////////////////////////////////
function getMouseXY()
{
var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
return new Array(posx,posy-30);
}
function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!window.event) return new Array(400,300);
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
//alert(e.type);
  if (e)
  { 
	  if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;//alert(mousex+" "+mousey);
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;//alert(mousex+" "+mousey);
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }
  
return new Array(mousex,mousey);
}

//////////////////////////////////////////////////////////////////////
function getStaticPosition(w,h)
{
//	var w=250;
//	var h=150;
var a = getWindowCenter();
var nw = a[0]-w/2;
var nh = a[1]-h/2;
return new Array(nw,nh);                
}
function getWindowCenter()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
return new Array(myWidth/2,myHeight/2);
}
////////////////////////////////////////////////////////////////

///=============== UI basic Object
function UI()
{
	this.createTable = function()
					   {
							var table = document.createElement('table');
								table.setAttribute("border","0");
								table.setAttribute("width","100%");
								//table.style.border = sborder;
							return table;
							}
	this.createColumn = function(align,className,valign,width) 
						{
							var td = document.createElement('td');
								td.setAttribute("align",align);
								td.className = className;
							if (valign.length>0) td.setAttribute("valign",valign);
							if (width.length>0) td.setAttribute("width",width);
                            return td;
							}
	this.createButton = function(name,value,onclick)
						{
							var b = this.createInput("button",name,value);
								b.onclick = onclick;
								b.className = "inputgr";
							return b;
							}
	this.createInput = function(type, name, value)
					   {
							var input = document.createElement('input');
						        input.setAttribute("type",type);
		                        input.setAttribute("name",name);
		                        input.setAttribute("value",value);
							return input;
							}
    this.createTextField = function(name,value,className) 
							{
								var tx = this.createInput("text",name,value);
								    tx.className = className;
								return tx;
								}
	this.createForm = function(name) 
						{
		                  var form = document.createElement("form");
						      form.setAttribute("name",name);
							  form.setAttribute("id",name);
							  form.setAttribute("action",location.href);
							  form.setAttribute("method","post");
						  return form;
							}
   this.createSelect = function(name, className, values, text, label)
						{
							var select = document.createElement('select');
							    select.className = className;
								select.setAttribute("name" , name);
								option = document.createElement('option');
								option.value = 0;
								option.text = "- "+label+" -";
								select.options.add(option);
									
								for(i=0;i<values.length;i++)
							    {
									option = document.createElement('option');
								    option.value = values[i];
									option.text = text[i];
									select.options.add(option);
									}
							return select;
							}
   this.createTextArea = function(nume,className,rows,cols)
						{
							var ta = document.createElement("textarea");
							    ta.className = className;
								ta.setAttribute("name",nume);
								ta.setAttribute("rows",rows);
								ta.setAttribute("cols",cols);
							return ta;
							}
//===========
	this.createBackground = function()
	{
		var div = document.createElement('div');
			div.setAttribute('id','bookdiv');
		var center = getWindowCenter();
			div.className = "bookdiv";
			div.style.top = "0px";
			div.style.left = "0px";
			div.style.width = ""+center[0]*3+"px";
			div.style.height = ""+center[1]*4+"px";
			document.body.appendChild(div);
		}
}


//============  PopupFrame

function PopupFrame()
{
	this.base = UI;
	this.title;
    this.content;

	this.createFrame = function()
	{
		this.createBackground();
		var div = document.createElement('div'); 
            div.setAttribute('id', 'framediv');
            div.className = "framediv";
//		var ww = getStaticPosition(400,500);alert(ww[0]+' '+ww[1]);
	    var pos = getMouseXY(); //alert(pos);
            div.style.top = pos[1]/2+"px";//"200px";
            div.style.left = pos[0]/2+"px"; 
	   //     div.style.width = "500px";
	//		div.style.height = "400px";
		
		var mainTable = this.createTable();
        var tbody = document.createElement("tbody");
		var tr = document.createElement("tr")
		var td = this.createColumn("left","r_text","","");
		var topPart = this.createTopPart();
			td.appendChild(topPart);
			tr.appendChild(td);
			tbody.appendChild(tr);

		var tr = document.createElement("tr")
		var td = this.createColumn("left","r_text","","");
			td.appendChild(this.content);
			tr.appendChild(td);
			tbody.appendChild(tr);

        var tr = document.createElement("tr")
		var td = this.createColumn("left","r_text","","");
		var bottomPart = this.createBottomPart();
			td.appendChild(bottomPart);
			tr.appendChild(td);
			tbody.appendChild(tr);

			mainTable.appendChild(tbody);
		div.appendChild(mainTable);
        document.body.appendChild(div);

		}
	this.createTopPart = function ()
							{
								var rt = this.createTable("");
                                    rt.style.backgroundColor="dbdbdb";
								var tbody = document.createElement("tbody");
								var tr = document.createElement("tr");
                                    tr.style.backgroundColor="#dbdbdb";
								var td = this.createColumn("left","r_text","","80%");
                                    td.style.backgroundColor="dbdbdb";
                                var b = document.createElement("b");
								    b.appendChild(document.createTextNode(this.title));
								    td.appendChild(b);
									tr.appendChild(td);
								var td = this.createColumn("right","comm_t","","15%");
								var img = document.createElement("img");
									img.setAttribute("src","images/inchide.gif");
									img.onclick = function(){hideFrame("framediv");};
                                    td.appendChild(img);
								    tr.appendChild(td);
									tbody.appendChild(tr);
									rt.appendChild(tbody);
								return rt;
								}
   this.createBottomPart = function ()
							{
								var rt = this.createTable("");
								var tbody = document.createElement("tbody");
								var tr = document.createElement("tr");
								var td = this.createColumn("center","r_text","","");
								var button = this.createButton("close","close",function(){hideFrame("framediv");});
                             	    td.appendChild(button);
									tr.appendChild(td);
									tbody.appendChild(tr);
									rt.appendChild(tbody);
								return rt;
								}

   this.createSubmitButton = function(name,text,func)
								{
									var trm = document.createElement("tr");
         							var tdm = this.createColumn("left","comm_t","","");

									var table = this.createTable();
								        table.style.borderTop = "1px dotted BBBBBB";
								    var tbody = document.createElement("tbody");
								    var tr = document.createElement("tr");
								    var td = this.createColumn("left","r_text","","");
								        td.style.paddingLeft = "20px";
								    var submit = this.createButton(name,text,func);//function(){checkContactForm();});
								        td.appendChild(submit);
								        tr.appendChild(td);
								        tbody.appendChild(tr);
									    table.appendChild(tbody);
								    
		        					    tdm.appendChild(table);
						        		trm.appendChild(tdm);
									return trm;
									}
	this.createTextAreaMesaj = function(name,text,rows,cols)
							{
                        		var trm = document.createElement("tr");
						    	var tdm = this.createColumn("left","comm_t","","");
							
								var table = this.createTable();
								var tbody = document.createElement("tbody");
								var tr = document.createElement("tr");
								var td = this.createColumn("left","r_text","center","");
							    var preferinte = this.createTextArea(name,"comm_t",rows,cols);
								    td.appendChild(document.createTextNode(text));
								    tr.appendChild(td);
								 td = this.createColumn("left","r_text","top","");
								    td.appendChild(preferinte);
									tr.appendChild(td);
									tbody.appendChild(tr);
									table.appendChild(tbody);
								
								 tdm.appendChild(table);
								 trm.appendChild(tdm);
								 return trm;
								}
	this.createLinesTable = function(header,names,texts)
							{
								var trm = document.createElement("tr");
								var tdm = this.createColumn("left","comm_t","","");
							
								var table = this.createTable();
								    table.style.borderTop = "1px dotted CCCCCC";
								var tbody = document.createElement("tbody");
								
								if (header.length>0)
								{
									var trh = document.createElement("tr");
									var tdh = this.createColumn("left","r_text","","");
										tdh.colSpan = "2";
										tdh.appendChild(document.createTextNode(header));
										trh.appendChild(tdh);
										tbody.appendChild(trh);
									}
							    for(i=0;i<names.length;i++)
								{
									trk = document.createElement("tr");
									tdk = this.createColumn("left","r_text","","");
									tdk.appendChild(document.createTextNode(texts[i]));
									trk.appendChild(tdk);
				                    tdk = this.createColumn("left","r_text","","");
									nume = this.createTextField(names[i],"","comm_t");
									tdk.appendChild(nume);
									trk.appendChild(tdk);
									tbody.appendChild(trk);
									}
							   
								table.appendChild(tbody);
								
								tdm.appendChild(table);
								trm.appendChild(tdm);
								return trm;
								}
	
}
PopupFrame.prototype = new UI;


