/* 
	Basic Scripts for Winteractive Developer Framework
	ver. 0.1b
*/
function PageScriptError() {return true;}
window.onerror = PageScriptError;



// Tooltip
var divLayer = 'genuineTooltip';
var mouseX   = 0;
var mouseY   = 0;
var tip      = null;

if( document.layers ) 
{
	document.captureEvents( Event.MOUSEMOVE );
}

//document.onmousemove = GetCursor; 

function sCreateXMLObject()
{
	var xmlDoc = null;
	if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	}
	else if (document.implementation.createDocument)
	{
		xmlDoc=document.implementation.createDocument("","",null); 
	}
	else
	{
		alert('Your browser cannot handle this script'); 
	}
	
	if (xmlDoc != null)
		xmlDoc.async = false;
		
	return xmlDoc;
}

function sGetCDATA(element)
{
	var ie = (typeof window.ActiveXObject != 'undefined');
	var returnText;

	if(ie){
		if(element.hasChildNodes)
		{
			returnText = element.childNodes[0].nodeValue;
		}
	}
	else
	{

		if(element.hasChildNodes)
		{
			returnText = element.childNodes[1].nodeValue;
		}
	}

	return returnText;
}

function sContentFilter(containerName, filterFile)
{
	var xmlDoc = sCreateXMLObject();						
	xmlDoc.load(filterFile)
	
	var filters = xmlDoc.getElementsByTagName("item");	
	var tmpcontrol = sys_FindControl(containerName);
	var tmpvalue = tmpcontrol.innerHTML;			

	tmpvalue = tmpvalue.replace(RegExp("&#174;", "ig"), "®");
	tmpvalue = tmpvalue.replace(RegExp("&reg;", "ig"), "®");
	tmpvalue = tmpvalue.replace(RegExp("&#8482;", "ig"), "™");
	
	var sWord, sReplacer;
	for (var i = 0; i < filters.length; i++)
	{
		sWord = filters[i].getElementsByTagName("word")[0].childNodes[0].nodeValue;
		sReplacer = sGetCDATA(filters[i].getElementsByTagName("replacer")[0]);
		
		tmpvalue = tmpvalue.replace(RegExp(sWord, "ig"), sReplacer);						
							
	} // end for

	sys_ChangeControlText( containerName, tmpvalue );			
} 

function IsRightToLeft()
{
	if( document.getElementsByTagName )
	{
		var htmlElement = document.getElementsByTagName("html");

		if( htmlElement.length == 1 )  
  		{		
	    	var dirElemAttr = htmlElement[0].getAttribute("dir");		

			if(dirElemAttr.toLowerCase() == "rtl")
			{
				return true;
			}
  		}
	}

	return false;
}


function GetCursor( e ) 
{	
	var tmp = (tip == null) ? GetHandle() : tip;	
	var tipWidth = parseInt(tmp.width); 

	if( document.layers ) 
	{		
		mouseX = IsRightToLeft() ? e.pageX - tipWidth : e.pageX;		
		mouseY = e.pageY + 20;
	}
	else if( document.all ) 
	{
		mouseX = IsRightToLeft() ? event.clientX - tipWidth : event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop + 20;
	}
	else if( document.getElementById )
	{
		mouseX = IsRightToLeft() ? e.pageX - tipWidth : e.pageX;		
		mouseY = e.pageY + 20;	
	}
	
	return true;
}

function GetHandle() 
{
	if( document.layers ) 
	{
		return ( document.layers[divLayer] );
	}

	if( document.all ) 
	{
		var block = eval( 'document.all.' + divLayer + '.style' );
		
		return ( block );
	}
	
	if( document.getElementById ) 
	{
	    return document.getElementById( divLayer ).style;
	}
}

function ShowToolTip() 
{
	tip = GetHandle();
	
	tip.left = mouseX;
	tip.top  = mouseY;
	
	if( document.layers )
	{
		tip.visibility = "show";
	}
	else if( document.all )
	{
		tip.visibility = "visible";
	}
	else if( document.getElementById )
	{
		tip.visibility = "visible";
	}
}

function HideToolTip()
{
	window.setTimeout( 'HideToolTip2()', 4000 );	
}

function HideToolTip2()
{
	var tip = GetHandle();
	
	if( document.layers )
	{
		tip.visibility = "hide";
	}
	else if( document.all )
	{
		tip.visibility = "hidden";
	}
	else if( document.getElementById )
	{
	    tip.visibility = "hidden";
	}
}



function getQueryVariable(variable) {  
	var query = window.location.search.substring(1);  
	var vars = query.split("&");  
	for (var i=0;i<vars.length;i++) 
	{    
		var pair = vars[i].split("=");    
		if (pair[0] == variable) {      
			return pair[1];    
		}  
	} 
	return "";
}



// on Tool tip function
function sys_onContentToolTipAction(id, visible)
{

	if (visible == 1)
	{
		ShowToolTip();
	}
	else
	{
		HideToolTip();
	}

}
// change control text
function sys_ChangeControlText (id, text) 
{       		
	//text = text.replace (/\n/g, "<BR>");
	//text = text.replace (/\'/g, "\\\'");
	
    //var statemenet;
    if (!sys_IsNetScape) 
	{
		//statemenet = "document.all['" + id + "'].innerHTML = '" + text + "';";
		document.all[id].innerHTML = text;
    }
    else if (document.getElementById)
    {   
		document.getElementById(id).innerHTML = text;    
		//statemenet = "document.getElementById('" + id + "').innerHTML = '" + text + "';";		
	} 
                        
	/*
	try {	    
	    eval (statemenet); 	    	    	   
	} catch (e) {	
	
	}
	*/
}
// Change Control visibility
function sys_ControlVisibilityChange (id, visible)
{
	var o;
	var v = (visible) ? "" : "none";
	if (sys_IsNetScape ())
	{
		o = "document.getElementById ('" + id + "').style.display = '" + v + "';";		
	}
	else
	{
		o = id + ".style.display = '" + v + "';";	
	}	
	try{ eval (o); }catch(e){}		
}
// Change Control Position
function sys_ControlPositionChange (id, xpos, ypos) 
{	
	var control = sys_FindControl(id);
	control.style.position = "absolute";	
	if (!sys_IsNetScape()) {	
		with (control.style)
		{
			top  = ypos;
			left = xpos;	
		}				
					
	} else {
		with (control.style)
		{
			pixelTop  = ypos;
			pixelLeft = Xpos;	
		}	
	}
}
// Get Control visibility
function sys_ControlVisibilityGet (id)
{
	var systatement;
	var sResult = '';
	
	if (sys_IsNetScape ())
		systatement = "sResult = document.getElementById ('" + id + "').style.display;";		
	else
		systatement = "sResult = " + id + ".style.display;";	
		
	try {
		eval (systatement);
	} catch (e) {}			
	
	return sResult == '';
}
// NetScape browser check
function sys_IsNetScape () 
{
	return !document.all;
}
// find control
function sys_FindControl(id) 
{
    var r;
    if (!sys_IsNetScape) 
	{
		r = document.all[id];
    }
    else if (document.getElementById)
    {       
		r = document.getElementById(id);		
	} 	
	
	try {	       	    
		return r;
	} catch (e) {	
	}
}
// formating string
function sys_StringFormat(sFormat){
	//var sRet="";
	var args = sys_StringFormat.arguments;

	//var sAry = sFormat.split(/{[0-9]}+/g);
	var isfound = 1;
	var findex = 0;
	while (isfound)
	{
		var qstring = '{'+findex+'}';
		if (sFormat.indexOf(qstring) > -1)
		{
			sFormat = sFormat.replace(qstring, args[findex+1]);
		}else{
			isfound = 0;
		}	
		findex += 1;
	} 
	/*for(i=0;i<sAry.length;i++){
		var argstring = args[i+1]
		if (argstring == null)
		{
			argstring = '';
		}
		sRet+= sAry[i] + argstring;
	}*/
	return sFormat;
 }
 

// check if the object is valid 
function sys_IsValidObject(o) 
{
	var r = true;
	if ( o == null )
	{
		r = false;
	}
	else if ( typeof(o) == "undefined")
	{
		r = false;
	} 
	return r;
}

// Open new window
function windowOpener(url,iHeight,iWidth,sShowTools){	
	var thisHeight = 500;
	var thisWidth = 500;
	var thisShowTools = 'no';
	
	if (iHeight != undefined) 
		thisHeight = iHeight;
	if (iWidth != undefined) 
		thisWidth = iWidth;		
	if (sShowTools != undefined)
		thisShowTools = sShowTools;
	
	if((navigator.appName.indexOf('Netscape') > -1) && (parseInt(navigator.appVersion) < 4 )) {
	// for Mac Netscape 3.0
		var newWin = window.open(url,"_blank","width=" + thisWidth + ",height=" + thisHeight  + ",left=100,top=100,toolbar=" + thisShowTools + ",directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
		if (newWin.focus)newWin.focus();
	} else {
		var newWin = window.open(url,"_blank","width=" + thisWidth + ",height=" + thisHeight  + ",left=100,top=100,toolbar=" + thisShowTools + ",directories=no,status=no,menubar=no,scrollbars=yes,resizable=no");
		if (newWin.focus)newWin.focus();
	}	
}