
var xmlhttp;
var xml_error;

var lx;
var ly
var fx;
var fy;
var last_xml;
var zlevel;
zlevel=100;

var last_scroll;
var menushowid;
menushowid=-1;

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	//o = document.getElementById(objectId)
	o=objectId;
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	//o = document.getElementById(objectId)
	o=objectId
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}
function setiframesize(obj)
{
	h=obj.contentWindow.document.body.scrollHeight;
	obj.height=h;
	obj.style.visibility="";
}
function frameloaded()
{
	 xHTML=mainframe2.document.body.innerHTML;
	 table_frame.innerHTML=xHTML;
}
function displaymenu()
{
	menu_row.style.position="absolute"
	menu_row.filters.item(0).apply();	
	menu_row.style.visibility="";
	menu_row.style.top=window.document.body.scrollTop;
	menu_row.filters.item(0).play(0.4);
	
}
function doscroll()
{
 	//window.status =	window.document.body.scrollTop;
	 if (menushowid!=-1) window.clearTimeout(menushowid);
	
 	if (last_scroll!=0)
 		{
 			window_dic.style.posTop = window_dic.style.posTop + window.document.body.scrollTop - last_scroll;
 		}
 	
 	last_scroll=window.document.body.scrollTop;
 	
 	if (window.document.body.scrollTop<100)
 		{
 			menu_row.style.visibility="";
 			menu_row.style.position="";
 		}
 		else
 		{
 			menu_row.style.visibility="hidden";
			menushowid=window.setTimeout("displaymenu();",1000)
 		}
 	
}

function htmlEncode(source, display, tabs)
{
	function special(source)
	{
		var result = '';
		for (var i = 0; i < source.length; i++)
		{
			var c = source.charAt(i);
			if (c < ' ' || c > '~')
			{
				c = '&#' + c.charCodeAt() + ';';
			}
			result += c;
		}
		return result;
	}
	
	function format(source)
	{
		// Use only integer part of tabs, and default to 4
		tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
		
		// split along line breaks
		var lines = source.split(/\r\n|\r|\n/);
		
		// expand tabs
		for (var i = 0; i < lines.length; i++)
		{
			var line = lines[i];
			var newLine = '';
			for (var p = 0; p < line.length; p++)
			{
				var c = line.charAt(p);
				if (c === '\t')
				{
					var spaces = tabs - (newLine.length % tabs);
					for (var s = 0; s < spaces; s++)
					{
						newLine += ' ';
					}
				}
				else
				{
					newLine += c;
				}
			}
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
			lines[i] = newLine;
		}
		
		// re-join lines
		var result = lines.join('<br />');
		
		// break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/  /g, ' &nbsp;');
		
		// tada!
		return result;
	}

	var result = source;
	
	// ampersands (&)
	result = result.replace(/\&/g,'&amp;');

	// less-thans (<)
	result = result.replace(/\</g,'&lt;');

	// greater-thans (>)
	result = result.replace(/\>/g,'&gt;');
	
	if (display)
	{
		// format for display
		result = format(result);
	}
	else
	{
		// Replace quotes if it isn't for display,
		// since it's probably going in an html attribute.
		result = result.replace(new RegExp('"','g'), '&quot;');
	}

	// special characters
	result = special(result);
	
	// tada!
	return result;
}



function urlencode(strText) {                             

            var isObj;
            var trimReg;
/*
            if( typeof(strText) == "string" ) {

                        if( strText != null ) {

                                    trimReg = /(^\s+)|(\s+$)/g;

                                    strText = strText.replace( trimReg, '');

                                    for(i=32;i<256;i++) {               

                                                strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));                                                                 

                                    }

                        }

            }     */     

			while (strText.search("&")!=-1)
			{
				strText=strText.replace("&","");				
			}

            return strText;
            

}


function xmlsubmit(frmname)
{
	var x;
	var i;
	var part;
	var args;
	args="";
	if (document.all(frmname)!=null)
	{
		x=	document.all(frmname).all
		
		for (i=0;i<x.length;i++)
			{
				part=""
				tag_type=x(i).tagName;
				//vl=urlencode(x(i).value);
				
				if (tag_type=="INPUT")
					{
						
						if (x(i).type=="" || x(i).type=="text") part=x(i).name + "=" +(x(i).value) + "&";
						
						if (x(i).type=="" || x(i).type=="text") part=x(i).name + "=" +(x(i).value) + "&";
						
						if (x(i).type=="checkbox")
							{
								if (x(i).checked==true)
									{
										part=x(i).name + "=" +x(i).value + "&";
									}
							}
							
						if (x(i).type=="hidden")
							{
								part=x(i).name + "=" +(x(i).value) + "&";
							}							
							
						if (x(i).type=="radio")
							{
								if (x(i).checked==true)
									{
										part=x(i).name + "=" +x(i).value + "&";
									}
							}
	
					}
				
				if (tag_type=="TEXTAREA") part=x(i).name + "=" +(x(i).value) + "&";
	
				if (tag_type=="SELECT")
					{

						v=x(i).options(x(i).selectedIndex).value;
						
						if (v=="") v=x(i).options(x(i).selectedIndex).text;

						part=x(i).name + "=" +v + "&";
					}
					
	
				
				
				if (part!="")
					args=args+part;				

	
			}
			
			//u=document.all(frmname).action+"?"+args;
		    u=document.all(frmname).action+"?"+args;
			openpage(u);




	
	}
	else
	{
		alert("Error sending form data , form '"+frmname+"' not present.")
	}

}


function openpopup(url)
{

	table_popup.style.visibility="";
	table_popup.style.left=(window.document.body.clientWidth-350)/2;
	table_popup.style.width=350;
	table_popup.style.top=(window.document.body.clientHeight -150)/2;
	zlevel++;
	table_popup.style.zIndex=zlevel;	
	gethtml(url,"popup_cell");
}

function submitsearch()
{
	xsearch=document.all("Searchtext").value
	if (xsearch!='')
		{
				xpage=document.all("category").value
				xtype=document.all("type").value
				openpage("search.asp?searchtext="+xsearch+"&category="+xpage+"&type="+xtype);
		}

}

function onenter(obj)
{
	x=window.event.keyCode;
	if (x==13) {
				window.event.keyCode=0;
	             eval (obj);
	             
	 		   }
	
}


function sendlogin()
{
	a="signin.asp?USER="+document.all("txt_username").value+"&PASS="+document.all("txt_password").value
	z=gethtml2(a,"login_frame");
	if (z.match('Login successful!'))
		{
			gethtml("usertab.asp","window_usertab");
			
		}
		
}


function showlogin()
{
	table_login.style.visibility="";
	table_login.style.left=(window.document.body.clientWidth-350)/2;
	table_login.style.width=350;
	table_login.style.top=(window.document.body.clientHeight -150)/2;
	//document.all("txt_username").value="";
	//document.all("txt_password").value="";	
	//document.all("txt_email").value="";		

}

function checkdicclick()
{
	x=window.event.keyCode
	if (x==13) translate();
}
function checkhistory(obj)
{

	x=obj.contentWindow.document.body.innerText;
	
	z="";
	if (x.substring(0,3)=="OK=")
		{
			z=x.substring(3,x.length)
			z=z.toString();


			while (z.search("_and_")!=-1)
			{
			 z=z.replace('_and_','&');
			}			
			
			openpage_xml(z);		
		}
		else
		{
			//alert("Cannot open page , some server problem !");
		}

}


function movewindow(obj)
{
	if (window.event.button==1)
		{
			if ((fx+window.event.x-lx>0) && (fx+window.event.x-lx<window.document.body.clientWidth-300) )
				{
					obj.style.left=fx+window.event.x-lx;
				}
			if ((fy+window.event.y-ly>0) && (fy+window.event.y-ly<window.document.body.clientHeight-150) )
				{
					obj.style.top=fy+window.event.y-ly;
				}

		}
		else
		{
			lx=window.event.x;
			ly=window.event.y;
			fx=obj.style.posLeft;
			fy=obj.style.posTop;
		}

}

function getword()
{
	if (document.selection.type=="Text")
		{
			var a;
			a=document.selection.createRange();
			if (a.text!="")
				{
					
					opendic();
					dictext.value=a.text;
					translate();
				}
		}
}


function translate()
{
	a="dic.asp?word="+document.all('dictext').value;
	gethtml(a,"dic_frame");
}
function opendic()
{
	window_dic.style.visibility="";
	window_dic.style.zIndex=zlevel;		
	dictext.value="";
	dictext.select();
	if (window.event.x-320<window.document.body.clientWidth-320)
		{
			if (window.event.x-320<0)
				{
					window_dic.style.left=10;		
				}
				else
				{	
					window_dic.style.left=window.event.x-320;							
				}
		}
		else
		{	
				window_dic.style.left=window.document.body.clientWidth-320;		
		}

	if (window.event.y<window.document.body.clientHeight-220)
		{
			window_dic.style.top=window.event.y+20;		
		}
		else
		{
			window_dic.style.top=window.document.body.clientHeight-220;
		}

}

function dosearch()
{
	s=searchtxt.value;
	if (s!='')
	{
	x=mainframe.document.location.toString();
	y="all";
	z=x.search('projects.asp');
	if (z!=-1)  y="projects"
	z=x.search('news.asp');
	if (z!=-1)  y="projects";
	openpage("search.asp?searchtxt="+s)	;
	}
//	navframe("search.asp");
}


function setlink(html)
{

	var i;
	var x;
	x=0;
	i=0;

	while (x!=-1)
	{
		x=html.indexOf('href=',i);
		if (x>0)
		{
			y=html.indexOf('"',x+7);
			
			html1=html.substr(0,x+6);
			html2=html.substr(x+6,y-x-6);
			html3=html.substr(y);
			extlink=0
			if (html2.search('http://')!=-1) extlink=1;
			if (html2.search('javascript:')!=-1) extlink=1;
			if (html2.search('https://')!=-1) extlink=1;
			if (html2.search('ftp://')!=-1) extlink=1;
			if (html2.search('www.')!=-1) extlink=1;
			if (html2.search('@')!=-1) extlink=1;
			
			if (extlink==0)
				{
					html2="javascript:openpage('"+html2+"');";
					html2=html2+'" target="_top';
				}
				else
				{
				html2=html2+'" target="_blank';
				}				
			html=html1+html2+html3

		}
		i=x+10;
	}
	
	  return html;
}

function closeerror2()
{

	table_error.style.visibility="hidden";
	table_error.style.left=-2000;
	table_error.style.top=-2000;

	table_login.style.visibility="hidden";
	table_login.style.left=-2000;
	table_login.style.top=-2000;

	table_popup.style.visibility="hidden";
	table_popup.style.left=-2000;
	table_popup.style.top=-2000;

	error_frame.height=1;

}


function closeerror()
{

	table_error.style.visibility="hidden";
	table_error.style.left=-2000;
	table_error.style.top=-2000;

//	table_popup.style.visibility="hidden";
//	table_popup.style.left=-2000;
//	table_popup.style.top=-2000;


	error_frame.height=1;

}
function showdetail()
{
	table_error.style.visibility="";
	table_error.style.left=(window.document.body.clientWidth-650)/2;
	table_error.style.top=100;
	table_error.style.width=650;
	error_frame.height=300;
	error_frame.width=630;
	error_msg.document.body.innerHTML=xml_error;

}
function showerror()
{
	table_error.style.visibility="";
	table_error.style.left=(window.document.body.clientWidth-450)/2;
	table_error.style.width=450;
	table_error.style.top=(window.document.body.clientHeight -150)/2;
}

function openpage(url)
{
	url=url.replace("../dbmanager/","")
	closeerror2();
	ex=0
	if (url=="") ex=1;
	if (url==" ") ex=1;	
	if (url=="-") ex=1;		

	if (ex==0)
	{

		if (url=='index.asp') return 0;		

		loading_frame.style.visibility="";
		loading_frame.style.left=0;
		loading_frame.style.top=72;  
		loading_frame.style.width="100%";

		urlx=url;
		
		while (urlx.search('&')!=-1)
		{
		 urlx=urlx.replace('&','_and_');
		}
		
		mainframe.document.location="history.asp?URL="+urlx;
		
		mainframe.src="history.asp?URL="+urlx;

	}

//	openpage_iframe(url);
}
function openpage_xml(url)
{
	ex=0
	if (url=="") ex=1;
	if (url==" ") ex=1;	
	if (url=="-") ex=1;		

	if (ex==0)
	{
		loading_frame.style.visibility="";
		loading_frame.style.left=0;
		loading_frame.style.top=72;  
		loading_frame.style.width="100%";
	
		loading_frame.style.height=window.document.body.clientHeight-72 ;  
	


		if (window.XMLHttpRequest)
		  {
		  xmlhttp=new XMLHttpRequest()
		  }
		// code for IE
		else if (window.ActiveXObject)
		  {
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		  }
		if (xmlhttp!=null)
		  {

			  xmlhttp.onreadystatechange=state_Change		  
			  xmlhttp.open("GET",url,true)
			  xmlhttp.send(null)
		  }

		}

}
//---------------------------------------------------------------
function state_Change()
{
document.body.scrollTop=0
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  loading_frame.style.visibility="hidden";
  html=xmlhttp.responseText;
  // if "OK"
  if (xmlhttp.status==200)
  {
  		if (html.search('NOACCESS'))
  			{
				html=setlink(html);
				table_frame.innerHTML=html;
			}
			else
			{
				openpopup('errora.htm');
			}

  }
  else
  {

		  xml_error=html;
		  xml_error=xml_error.replace('href','_href');
		  showerror();	  
  }
  }
}
//---------------------------------------------------------------

function openpage_iframe(url)
{
	ex=0
	if (url=="") ex=1;
	if (url==" ") ex=1;	
	if (url=="-") ex=1;		

	if (ex==0)
	{
		loading_frame.style.visibility="";
		loading_frame.style.left=0;
		loading_frame.style.top=72;  
		loading_frame.style.width="100%";
	
		loading_frame.style.height=window.document.body.clientHeight-72 ;  
	
	
		mainframe.document.location=url;
		mainframe.src=url;
	}
}

function showpage()
{
	var html;   
	loading_frame.style.visibility="hidden";    		
	html = mainframe.document.body.innerHTML;


  if (html.search("HTTP Error")==-1)
  	{
		html=setlink(html);
		table_frame.innerHTML=html;
	}
	else
	{
		  xml_error=html;
		  xml_error=xml_error.replace('href','_href');
		  showerror();		
	}	
}



function makeover(obj)
{
	var a;
	a=obj.src;
	if (a.search('_over.gif')==-1)
		{
			a=a.replace('.gif','_over.gif');
			obj.src=a;		
		}		
}
function makenormal(obj)
{
	var a;
	a=obj.src;
	if (a.search('_over.gif')!=-1)
		{
			a=a.replace('_over.gif','.gif');
			obj.src=a;		
		}		
}

function gethtml(url,objname)
{
	obj=document.all(objname);
	obj.innerHTML="<img border='0' src='images/loading2.gif'>";	
	window.setTimeout("gethtml2('"+url+"','"+objname+"');",100);

}
function gethtml2(url,objname)
{
var xmlhttp;
xmlhttp=null;

last_xml="";
obj=document.all(objname);

// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  	  
	  xmlhttp.open("GET",url,false)
	  xmlhttp.send(null)
	  if (xmlhttp.status==200)
	  	{
	  	  //	alert(obj.id);
	  	  xhtm = xmlhttp.responseText;
		  obj.innerHTML = xhtm;
		  return xhtm;
	    }
	    else
	    {
	    obj.innerHTML="<font face='Tahoma' size='1'>Error Loading Data!</font>";	
	    obj.innerHTML=xmlhttp.responseText;
	    }
  }
}


/*********************************************************************************************************************************/
// Change DIV Opacity all browser



function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 
