/** 
 * Aimex - Asynchronous Interface and Manipulation Experience
 * Powered by Imac and Mac OSX 10.4.1
 * 
 * Author: 		@ Odemur Cezar Marangoni
 * Email: 		@ marangoni at mac dot com
 * Code Date:	@ 23/09/2006
 * 
 * Company Credits -> www.ifocus.com.br
 */

// Variables Declarations -> @Company Information
var AimexCompanyName	= 'Wu Xing';
var AimexCompanyUrl		= 'www.wuxing.com.br';

// Other Globals Variables Declarations -> @General Functions
var http_request = false;
var myWidth = 0, myHeight = 0; // @Blur div efects 

// XML -> Object Create
function criarObjetoXMLHttp() {
	try{
		xmlhttp = new XMLHttpRequest();
		return xmlhttp;
	} catch(ee) {
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			return xmlhttp;
		} catch(e) {
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				return xmlhttp;
			} catch(E) {
				return false;
			}
		}
	}
}


// @ Function -> Load Url Content
function leUrl(Url, MainDiv) {
	
	var AimexContent = document.getElementById(MainDiv);
	document.getElementById(MainDiv).innerHTML = '<p align=center><img src="images/spinner.gif"></p>';
	
	xmlHttpRequest = criarObjetoXMLHttp();
	xmlHttpRequest.open('POST', Url, true);
	
	xmlHttpRequest.onreadystatechange = function() {
		if (xmlHttpRequest.readyState == 4) {
			var retornoHTML = xmlHttpRequest.responseText;	
	
   			retornoHTML = retornoHTML.replace(/\+/g," ")
    		retornoHTML = unescape(retornoHTML)
			
			AimexContent = document.getElementById(MainDiv);
			//AimexContent.innerHTML = retornoHTML;						
			AimexContent.innerHTML = '<img src="images/pic_full/' + Url + '.JPG" width="570" border="1">';
			
		}
	}
	
	xmlHttpRequest.send(null);
}

// @ Function -> Load XML Content
function leXml(xDiv, yDiv) {
	var strXML = document.getElementById(xDiv).innerHTML;

      strXML=strXML.replace(/\+/g," ")
      strXML=unescape(strXML)	
			
	document.getElementById(ydiv).innerHTML = strXML;
}

// @ Forms Functions -> General Forms Manipulation
	 
   function makePOSTRequest(url, parameters) {

      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; iso-8859-1");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;

      			result=result.replace(/\+/g," ")
      			result=unescape(result)
						
            document.getElementById('cnt').innerHTML = result;  	
						
         } else {
            alert('Não foi possível realizar esta operação.\nTente novamente....');
         }
      }
   }
	 
// @ Function -> SubMenu Manipulation
function montaSubMenu(divX, divY, i) {
	for (j=0; j <= 16; j ++) {
		
		if (i == j) {		
			if (document.getElementById(divX + '-' + j).innerHTML !== "") { 
				leXml(divX + '-' + j, divY + '-' + j);
				document.getElementById(divY + '-' + i).style.display='block';
			}	
		} else {
			document.getElementById(divY + '-' + j).style.display='none';
		}	
	}
}
 

// @ Function -> Block Mouse Events
if (document.all) {
	document.onmousedown=new Function("if (event.button==2||event.button==3)alert(AimexCompanyName)");
}

// @ Function -> New Pop UP Windows
function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// @ Function -> Get Window Size
function getWindowsSize() {
  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;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

// @ Funciton -> Active Screen
function ativaScreen(ativeCnt) {
		getWindowsSize();
		document.getElementById('divImage').innerHTML = '<font color="#FFFFFF">..:: Clique na imagem para fechar ::.. </font><br><img src="imagens/' + ativeCnt + '.jpg" onclick="desativaScreen();">';
		document.getElementById('divScreen').style.display = 'block';
		document.getElementById('divScreen').style.width = myWidth + 'px';
		document.getElementById('divScreen').style.height = (myHeight+300) + 'px';	
}

// @ Function -> Deactive Screen
function desativaScreen() {
	getSize();
		document.getElementById('divScreen').style.display = 'none';
}

// @ Function -> Set Div Background Color
function setColor(div, color) { 
		document.getElementById(div).style.background=color; 
}

// @ Function -> Set Font Size
function setFontSize(div, size) { 
		document.getElementById(div).style.fontSize=size; 
}

// @ Function -> Set Image Path
function setImage(div,imagem) {
	document.getElementById(div).src='images/' + imagem;
}

// @ Function -> Set Background Image
function setBackGroundImage(div,imagem) {
	document.getElementById(div).style.background='#FFFFFF url(images/' + imagem + ') left top repeat-y';
}

// @ Function -> Show Div Hint
function showHint(div, txt)
{
	document.getElementById(div).style.display='block';
	document.getElementById(div).innerHTML = txt;
}

// @ Function -> Hide Div Hint
function resetHint(div)
{
	document.getElementById(div).style.display='none';
	document.getElementById(div).innerHTML = " ";
}

// @ Function -> Add in Favorites
function AddFav(){
	window.external.AddFavorite('http://' + AimexCompanyUrl, AimexCompanyUrl)
}

// @ Function -> Confirm Events
function Confirm(idAction, Msg)
{
var Send = confirm(Msg)
	if (Send == true) {
		makePOSTRequest(idAction, 'GET');
	}
}

function setStatusBar(SetStatusBarText) {
		if (event) {
		window.status = SetStatusBarText;
	}
}