﻿
//globals
var y;
//var url = 'alert.aspx';
//var params = '';
var method = 'get';
var http;
var req;

//onLoad
window.onload = function(){};

//***************************************************************
//create the ajax obj
function createRequestObject() {

    if(window.XMLHttpRequest){

        // Firefox, Safari, Opera...
        req = new XMLHttpRequest();

    } else if(window.ActiveXObject) {

        // Internet Explorer 5+
        req = new ActiveXObject("Microsoft.XMLHTTP");

    } else {

        // There is an error creating the object,
        // just as an old browser is being used.
        alert('Problem creating the XMLHttpRequest object');

    }

    return req;

}
//***************************************************************

// Make the XMLHttpRequest object
var http = createRequestObject();

//***************************************************************
//send the ajax request
function sendRequest( url ) {
    
    http.open( method , url , true );
    http.onreadystatechange = function(){ handleResponse() };
	http.send( null );

}
//***************************************************************
//handle the ajax response
function handleResponse(){

	if(http.readyState == 4 && http.status == 200){
        
        var response = http.responseText;
        var r = '';
        //alert(response);
        
        if( response != '' ){
            //parse
            r = eval('('+response+')');
			//alert(response);
            
            //set values
            //text
            //alert(r.text.txt);
            $('layer5').innerHTML = r.text.txt;
            
            //images
            var imgs = r.imgs.length;
            //alert(imgs);
            
            if( imgs != 0 ){
				
				//$('imgs_').style.width = '700px';
				$('imgs_').style.border = '0px solid red';
				
				for( i=0 ; i<imgs ; i++){
					
                    if( i%5 == 0 && i>0 )  x = "";
                    else x = '';
            		
					$('imgs_').innerHTML += "<img style='border:1px solid #999; margin:3px; height:70px;' src='images/logos/" + r.imgs[i].img + "' />" + x;

                }
				
				//$('imgs_').innerHTML += "<img style='border:1px solid #999; margin:3px;' src='images/logos/" + r.imgs[0].img + "' />";
				//alert($('imgs_').innerHTML);
				
			}
        Init();    
        }
       
	}
}
//***************************************************************
//helper functions
function $() {

      var elements = new Array();
      for (var i = 0 ; i < arguments.length ; i++) {      
            var element = arguments[i];
            
            if ( typeof element == 'string' ) element = document.getElementById(element);
            if ( arguments.length == 1 ) return element;
            elements.push( element );
      }
      return elements;
}
//***************************************************************
function Init()
{
  // Grab the appropriate div
  theDiv = document.getElementById('layer5');
  // Grab all of the links inside the div
  links = theDiv.getElementsByTagName('a');
  // Loop through those links and attach the target attribute
  for (var i=0, len=links.length; i < len; i++) {
    // the _blank will make the link open in new window
    links[i].setAttribute('target', '_blank');
  }
}
//***************************************************************
