//*******************************************************
//*		ajaxLib.js contains all required JS libs required	*
//*		for the proper AJAX work with the clients sites		*
//*		outside the PRISM.																*
//*******************************************************
//Preload main AJAX Engine
var libURL;
if(!libURL) libURL = "http://" + location.host;
document.write("<script type=\"text\/javascript\" src=\"" + libURL + "/prism_resource\/javascript\/ajaxengine.js\"><\/script>");
var enginePath;
var ajaxActionFile = libURL + "/client_ajax/index.cfm";

function WriteOutput(where,what){if(getElement(where)) getElement(where).innerHTML = what;}
function getElement(id){if(document.getElementById(id)) return document.getElementById(id);else return false;}
function get_random(){var ranNum= Math.round(Math.random()*999999);return ranNum;} 
function cutLine(str,len){if(str && str.length > len) str = str.substring(0,len) + '..'; return str;}

//Window mehtods
var openWindowID;
function CreatePopupWindow(id, ww, hh, message, bgcolor, toBeAttached, xx, yy){  
  if(document.getElementById(id)) return false;
  if(!bgcolor) bgcolor = 'FFFFFF';
  var e = document.createElement("div");
  e.id = id;
  e.style.visibility = "hidden";
  e.style.position = "absolute";
  e.style.overflowY = "hidden";
  divww = ww + 10; divhh = hh + 10;
  e.style.width = divww + "px";
  e.style.height = divhh + "px";
  e.style.zIndex = "-1";
  document.getElementsByTagName("body")[0].appendChild(e);	
  changeWindowIndex(id);
if(xx) var x = xx; else var x = Math.ceil(pageWidth()/4); 
if(yy) var y = yy; else var y = 50; 		
var partbody = "";	  
    partbody += "<table width='98%'><tr><td height='98%' align='center' valign='middle'><div id='boxContainer'><div id='boxContent'><table cellpadding=0 cellspacing=10 width=\"100%\" border=0 align=center bgcolor=\"#" + bgcolor + "\"><tr><td id=\"movebar\" onmousedown=\"changeWindowIndex('" + id + "')\"><table cellpadding=0 cellspacing=0 width=\"100%\" border=0><tr><td style=\"cursor:move;background-image:url('prism_resource/image/ajax_drag.gif');\"><ilayer width=\"100%\" onSelectStart=\"return false\"><layer width=\"100%\" onMouseover=\"isHot=true;if (isN4) ddN4("+id+")\" onMouseout=\"isHot=false\" height=\"25\">&nbsp;<\/layer><\/ilayer><\/td><td width=\"25\" align=\"right\"><a href=\"javascript:\" onclick=\"deletePopupWindow('" + id + "')\"><img src=\"prism_resource/image/ajax_close.gif\" width=20 height=20 border=0><\/a><\/td><\/tr><\/table><\/td><\/tr>";					
			if(toBeAttached) partbody += "<tr><td id=\"popcontent_" + id + "\"><\/td><\/tr>"; 
      else partbody += message;          
			partbody += "<\/table><\/div><\/div></td></tr></table>";
      WriteOutput(id,partbody);          
      if(toBeAttached) getElement('popcontent_' + id).appendChild(toBeAttached);          	
		  document.getElementById(id).style.visibility = 'visible';
		  document.getElementById(id).style.top = y + "px";	
		  document.getElementById(id).style.left = x + "px";
  return true;
}
function deletePopupWindow(what){
  openWindowID = null;
	var d = document.getElementsByTagName("body")[0];
  var olddiv = document.getElementById(what);
  if(document.getElementById(what)) d.removeChild(olddiv);		
}
function changeWindowIndex(id){
	if(openWindowID) document.getElementById(openWindowID).style.zIndex = "99";
	document.getElementById(id).style.zIndex = "100";
	openWindowID = id;
}

//Screen resolution
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}

function loadDataToMainArrays(xml){
    mainMassives = new Array(); 
    var x = xml.responseXML.getElementsByTagName('myRoot');  					
        if(x[0].childNodes.length == 0) {
  		    alert('No data has arrived, please contact us for support');return;
  	    }	  					
      	for (j = 0; j < x[0].childNodes.length; j++) {
      		massivename = x[0].childNodes[j].nodeName;     
          eval(massivename + "Array = new Array();");
      		eval(massivename + "ArrayStatic = new Array();");
          eval(massivename + "Massives = new Array();");      
          mainMassives.push(massivename);
      		for (k = 0; k < x[0].childNodes[j].childNodes.length; k++) {
      			thename = x[0].childNodes[j].childNodes[k].nodeName;
      			if(x[0].childNodes[j].childNodes[k].firstChild) {								
      					thevalue = x[0].childNodes[j].childNodes[k].firstChild.nodeValue;					
      				}
      			else {thevalue = ""};  
           //alert(massivename + '/' + thename + '/' + thevalue);            
           eval(massivename + "Array['" + thename + "'] = thevalue");
					 eval(massivename + "ArrayStatic['" + thename + "'] = thevalue");
           eval(massivename + "Massives.push(thename)");							
      	}
      } 
  }
	
	function searchPrismArray(ar,vl){
    for(var a = 0; a < ar.length; a++) {
      if(ar[a] == vl) return a; 
    }
    return -1;    
  }
	function createListFromArray(array,delimiter){
     var newlist = "";
     if(!delimiter) var delimiter = ",";
     for(a = 0; a < array.length; a++){
       if(array[a]) {        
        if(newlist != '') newlist += delimiter; 
        newlist += array[a];        
       }
     }    
     return newlist;    
  }
	function cEscape(str){  
		str = unicodeToEntities(str);//convert to entities  
	  try{
		str = str.replace(/;amp;/g,";");
		str = str.replace(/&amp;#/g,"&#");	
		str = str.replace(/"/g,"&quot;");
		str = str.replace(/</g,'&lt;');
		str = str.replace(/>/g,'&gt;');  
		str = escape(str);  
	  } catch(err){}
		return str;
	}
	function unicodeToEntities(str){  	 
	try{
		str = str.toString();   
    var q='';
    for(i=0; i<str.length; i++) {
      j=str.charCodeAt(i);
      q+=(j==38)?'&amp;':(j<128)?str.charAt(i):'&#'+j+';';      
    }    
		return q;
    }catch(err){return str;}
  }
	
	function changeOpac(opacity, id) { 
			if(getElement(id)) var object = document.getElementById(id).style;		
			else var object = document.body.style; 
      object.opacity = (opacity / 100); 
      object.MozOpacity = (opacity / 100); 
      object.KhtmlOpacity = (opacity / 100); 
      object.filter = "alpha(opacity=" + opacity + ")"; 
  } 
