// globale Instanz von XMLHttpRequest
var xmlHttp = false;
var cookieOptions = { path: '/', expires: 365 };
var survey_id = null; 


//window.onload=new Function('fx','attachListeners(document,"td","suncare_lookup")');
$(survey);
$(attachListeners);

function survey() {
	survey_id = $('#survey_id').attr('rel');

	if($('#survey').children('div').length > 0) {
		$('a.close').click(function(){				
			survey_close();
		});
		var queryString = window.location.search;
		if(queryString.search(/survey=true/) != -1) {
			survey_reset();
		} else if ($.cookie('survey_'+survey_id) == 'false') {
			$('#survey').hide();
		} else {
			$('#survey').show();
		}
	}

}

function drawPie(array) {
	
	if(array.length > 0){
		P=new Array();
		C=new Array("#88267b","#a04995","#b365a9","#c281b9","#d3a0cc","#e6c5e2","#f2e2f0");
		var perc = 0;
		$.each(array, function(i){
			P[i]=new Pie(340,220,0,80,perc*3.6,(this.percent+perc)*3.6,C[i],this.name);				  
			perc = this.percent+perc;
			$('.tx-simplesurvey-pi1-result-percent:eq('+i+')').css('background-color',C[i]);
		});
	}
}

function writeCookie() {
	$.cookie('survey_'+survey_id, 'false', cookieOptions);	
}

function survey_close(){
	writeCookie();
	$('#survey').hide();
	xajax_countClosedSurveys(survey_id);
}

function survey_reset() {
	$.cookie('survey_'+survey_id, null, cookieOptions);
	$('#survey').show();		
}

function attachListeners(oElm, strTagName, strClassName){

oElm = document;
strTagName = 'td';
strClassName = 'suncare_lookup';

	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
   //	var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){

           oElement.onmouseover = mousehandler;
        }   
    }

if (document.layers)
  document.captureEvents(Event.MOUSEDOWN);

for (var i=0; i<document.images.length; i++){
document.images[i].onmousedown=right;
document.images[i].oncontextmenu=right;
}


}
			
function mousehandler(e){

	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	
		ajax_call(targ.innerHTML);
}

function getXMLHTTPRequest(){

// XMLHttpRequest-Instanz erstellen
// ... f�r Internet Explorer
    try {
        xmlHttp  = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
        try {
            xmlHttp  = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
            xmlHttp  = false;
        }
    }
// ... fr Mozilla, Opera und Safari
    if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }
    
    return xmlHttp;
}

function ajax_call(string) {

	 var xmlHttp = getXMLHTTPRequest();

     if (xmlHttp && string != ''){

       	xmlHttp.onreadystatechange = function (){
                if (xmlHttp.readyState == 4){
                
		          	if(document.getElementById('result') && xmlHttp.responseText.length > 1){

		          		document.getElementById('result').innerHTML = xmlHttp.responseText;

		          		document.getElementById('result').style.visibility = 'visible';
		          	}
                }
         };
	    xmlHttp.open("GET", 'typo3conf/ext/spareparts/suncare_lookup.php?type='+string , true);         
        xmlHttp.send(null);
      }
}

function right(e) {
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)){
return false;
}
else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
alert('Action not allowed');
return false;
}
return true;
}