
var gShow; //variable holding the id where feedback will be sent to.
var gErrors = 0; //number of errors is set to none to begin with
var http = getHTTPObject();//don't worry about this
var rowidorg = "insertrow";
var imageorg = "referenzen";
var imagestr = "close";
var rowid;
var imageid;

function GetText(sVal) {
	var sUrl = "referenzen_ajax.php?modul=text&val=";//url is the page which will be processing all of the information.  it is important to make sure validationtype is ajax
	rowid = rowidorg + sVal;
	imageid = imageorg + sVal;

//sends the rules and value to the asp page to be validated
	http.open("GET", sUrl + (sVal), true);
  
	http.onreadystatechange = handleHttpResponse; 	// handle what to do with the feedback 
	http.send(null);  
}

function GetImage(sVal) {
	var sUrl = "referenzen_ajax.php?modul=images&val=";//url is the page which will be processing all of the information.  it is important to make sure validationtype is ajax
	rowid = rowidorg + sVal;
	imageid = imageorg + sVal;
	
	//sends the rules and value to the asp page to be validated
	http.open("GET", sUrl + (sVal), true);
  
	imagestest = document.getElementsByTagName('img');
	for (i=0; i<imagestest.length; i++) {//loop through all the <img> elements 
		if (imagestest[i].src.substr(62,5) == imagestr) {
			imagestest[i].src='template/img/icon_referenzen.gif'; 
		}				
	}

	http.onreadystatechange = handleHttpResponseImage; 	// handle what to do with the feedback 
	http.send(null);  
}


function handleHttpResponse() {
	//if the process is completed, decide to do with the returned data
	if (http.readyState == 4) 
  	{
		tables = document.getElementsByTagName('td');
		for (i=0; i<tables.length; i++)//loop through all the <td> elements 
		{
			if (tables[i].className == rowid )
			{
				//alert(http.responseText + tables[i].className );
				if (document.getElementById(imageid).src.substr(62,5) == imagestr) {
					document.getElementById(imageid).src='template/img/icon_referenzen.gif'; 
					tables[i].innerHTML = "";
				} else {
					tables[i].innerHTML = http.responseText;
					document.getElementById(imageid).src='template/img/icon_referenzen_close.gif'; 
				}
				
			} else if (tables[i].className.substring(0,9) == rowidorg) {
				tables[i].innerHTML = "";
			}
		}
		imagestest = document.getElementsByTagName('img');
		for (i=0; i<imagestest.length; i++) {//loop through all the <img> elements 
			if (imagestest[i].src.substr(62,5) == imagestr && imagestest[i].name != imageid) {
				imagestest[i].src='template/img/icon_referenzen.gif'; 
			}				
		}

  	}
}

function handleHttpResponseImage() {
	//if the process is completed, decide to do with the returned data
	if (http.readyState == 4) 
  	{
		tables = document.getElementsByTagName('td');
		for (i=0; i<tables.length; i++)//loop through all the <td> elements 
		{
			if (tables[i].className == rowid )
			{
				tables[i].innerHTML = http.responseText;
			} else if (tables[i].className.substring(0,9) == rowidorg) {
				tables[i].innerHTML = "";
			}
		}
  	}
}

function getHTTPObject() {
var xmlHttp = null;
// Mozilla, Opera, Safari sowie Internet Explorer 7
if (typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}
if (!xmlHttp) {
    // Internet Explorer 6 und älter
    try {
        xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        try {
            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            xmlHttp  = null;
        }
    }
}
return xmlHttp;
}
