
// telepark.cms
// (c) by telepark
var globVid;
var globVideoSwitch;
function getfocus() {
	self.focus();
}

function newWindow(url,name,width,height) {
	fenster = window.open (
	url,
	name, 					// name
	'toolbar=0' 			// tool bar 
	+',location=0' 			// address bar
	+',directories=0' 		// additional bars
	+',status=0' 			// status bar
	+',menubar=0' 			// menu bar
	+',scrollbars=1' 		// scroll bars
	+',resizable=1' 		// window resizable
	+',width=' + width 		// window width in pixels
	+',height=' + height 	// window height in pixels
	);
}

function createHttpRequest() {
	var xmlhttp;
 	try {
 		xmlhttp = new XMLHttpRequest();
 	} catch (e) {
  		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
  										'MSXML2.XMLHTTP.5.0',
  										'MSXML2.XMLHTTP.4.0',
  										'MSXML2.XMLHTTP.3.0',
  										'MSXML2.XMLHTTP',
  										'Microsoft.XMLHTP'
  										);
  		for (var i = 0; i<XmlHttpVersions.length && !xmlhttp; i++) {
  			try {
  				xmlhttp = new ActiveXObject(XmlHttpVersions[i]);
  			}
  			catch(e) {
  			}
  		}
 	}
 	if (!xmlhttp) {
 		alert('Error creating the XMLHttpRequest object.');
 	} else {
		return xmlhttp;
 	}
}

function reloadAgencyList(searchstring,cw,start) {
	var s = '';
	if (searchstring!='') var s = encodeURI(searchstring);
	
	var xmlhttp = createHttpRequest();
	
	//alert('searchstring: ' + s);
	//alert('cw: ' + cw);
	//alert('start: ' + start);
	
	//alert(window.location.href);
	currentURL = window.location.href;
	currentURL = currentURL.split("index.php");
	//alert(currentURL.length);
	if (currentURL.length>1) targetURL = "admin/modules/agency/ajax/reloadagencylist_web.php";
	else targetURL = "ajax/reloadagencylist.php";
	//alert("targetURL: "  + targetURL);
	
	xmlhttp.open("GET", targetURL + "?searchstring=" + s + "&sp=" + start, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				if (cw==true) {
					fenster.close();
				}
			}
		}
		catch(e) {
			status = '';
			if (cw==true) {
				fenster.close();
			}
		}
	  }
	}
	xmlhttp.send(null);
}

function reloadAgentList(searchstring,cw,start) {
	var s = '';
	if (searchstring!='') var s = encodeURI(searchstring);
	
	var xmlhttp = createHttpRequest();
	
	//alert('searchstring: ' + s);
	//alert('cw: ' + cw);
	//alert('start: ' + start);
	
	//alert(window.location.href);
	currentURL = window.location.href;
	currentURL = currentURL.split("index.php");
	//alert(currentURL.length);
	//if (currentURL.length>1) targetURL = "admin/modules/agency/ajax/reloadagentlist_web.php";
	targetURL = "ajax/reloadagentlist.php";
	//alert("targetURL: "  + targetURL);
	
	xmlhttp.open("GET", targetURL + "?searchstring=" + s + "&sp=" + start, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				if (cw==true) {
					fenster.close();
				}
			}
		}
		catch(e) {
			status = '';
			if (cw==true) {
				fenster.close();
			}
		}
	  }
	}
	xmlhttp.send(null);
}

function deleteAgency(id) {
	var c = confirm(deleteconfirm);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "ajax/deleteagency.php?agency_id=" + id , true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
		  	// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					reloadAgencyList('');
				}
			}
			catch(e) {
				status = '';
				reloadAgencyList('');
			}
		  }
		}
		xmlhttp.send(null);
	}
	else
		return false;
}

function deleteAgent(id) {
	var c = confirm(deleteconfirm);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "ajax/deleteagent.php?agent_id=" + id , true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
		  	// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					reloadAgentList('');
				}
			}
			catch(e) {
				status = '';
				reloadAgentList('');
			}
		  }
		}
		xmlhttp.send(null);
	}
	else
		return false;
}

function getValues() {
	var values = document.getElementById('search1').value + " ";
	values += document.getElementById('search2').value + " ";
	values += document.getElementById('search3').value + " ";
	values += document.getElementById('search4').value + " ";
	values += document.getElementById('search5').value + " ";
	values += document.getElementById('search6').value;
	return values;
}

function clearSearch() {
	document.getElementById('search1').value ='';
	document.getElementById('search2').value ='';
	document.getElementById('search3').value ='';
	document.getElementById('search4').value ='';
	document.getElementById('search5').value ='';
	document.getElementById('search6').value ='';
	reloadPhotoList('','','');
}

function clearSearchFields() {
	document.getElementById('search1').value ='';
	document.getElementById('search2').value ='';
	document.getElementById('search3').value ='';
	document.getElementById('search4').value ='';
	document.getElementById('search5').value ='';
	document.getElementById('search6').value ='';
}

// replace photo
function replacePhoto(position) {
	var xmlhttp = createHttpRequest();
	
	targetURL = "ajax/replacephoto.php";
	
	xmlhttp.open("GET", targetURL + "?pos=" + position, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// replace vita
function replaceVita() {
	var xmlhttp = createHttpRequest();
	
	targetURL = "ajax/replacevita.php";
	
	xmlhttp.open("GET", targetURL, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// replace big photo
function replacePhotoBig() {
	var xmlhttp = createHttpRequest();
	
	targetURL = "ajax/replacephotobig.php";
	
	xmlhttp.open("GET", targetURL, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// replace agent photo
function replaceAgentPhoto() {
	var xmlhttp = createHttpRequest();
	
	targetURL = "ajax/replacephotoagent.php";
	
	xmlhttp.open("GET", targetURL, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}


// replace vita
function replacePhotoPdf() {
	var xmlhttp = createHttpRequest();
	
	targetURL = "ajax/replacephotopdf.php";
	
	xmlhttp.open("GET", targetURL, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// replace preview photo
function replacePhotoPreview() {
	var xmlhttp = createHttpRequest();
	
	targetURL = "ajax/replacephotopreview.php";
	
	xmlhttp.open("GET", targetURL, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// clear group selection
function clearGroupSelection() {
	document.getElementById('groups').value="";
}

// populate group
function populateGroup(group) {
	document.getElementById('agency_group').value=group;
}

// enlarge FLV video
function enlargeFLVVideo(vid,aid) {
	embedFLV(vid,aid,'false');
	newWindowRes("enlargeVideoFLV.php?vid=" + vid,'videoflv',800,600);
}

// enlarge FLV video
function enlargeYTVideo(vid,aid) {
	embedYT(vid,aid,false);
	newWindowRes("enlargeVideoYT.php?vid=" + vid,'videoyt',800,600);
}

// embed YT video
function embedYT(vid,aid,autostart) {
	globVid = vid;
	globVideoSwitch = "yt";
	deactivatePhotogallery(aid);
	var xmlhttp = createHttpRequest();
	
	targetURL = "admin/modules/agency/ajax/embedYT.php";
	
	xmlhttp.open("GET", targetURL + "?vid=" + vid + "&aid=" + aid + "&autostart=" + autostart, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// embed FLV video
function embedFLV(vid,aid,autostart) {
	globVid = vid;
	globVideoSwitch = "flv";
	deactivatePhotogallery(aid);
	var xmlhttp = createHttpRequest();
	
	targetURL = "admin/modules/agency/ajax/embedFLV.php";
	
	xmlhttp.open("GET", targetURL + "?vid=" + vid + "&aid=" + aid + "&autostart=" + autostart, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200 && xmlhttp.responseXML && xmlhttp.responseXML.documentElement) {
				doEmbedFLV(xmlhttp.responseXML.documentElement,vid,aid,autostart);
				//alert(xmlhttp.responseText);
				//eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

function doEmbedFLV(req,vid,aid,autostart) {
	var enlargegif = getXMLData(req.getElementsByTagName('enlargegif'));
	var enlargetext = getXMLData(req.getElementsByTagName('enlargetext'));
	var width = getXMLData(req.getElementsByTagName('width'));
	var height = getXMLData(req.getElementsByTagName('height'));
	var file = getXMLData(req.getElementsByTagName('file'));
	var autostart = getXMLData(req.getElementsByTagName('autostart'));
	document.getElementById('embedVideo').style.display='block';
	document.getElementById('embedVideo').innerHTML="<img src=\"admin/imgs/anim-loading.gif\" height=\"20\" width=\"20\" border=\"0\" />";
	document.getElementById('enlargeVideo').style.display='block';
	//document.getElementById('enlargeVideo').innerHTML="<p><a href=\"#\" onClick=\"enlargeFLVVideo(" + vid + "," + aid + ");\"><img src=\"" + enlargegif + "\" border=\"0\" alt=\"" + enlargetext + "\" title=\"" + enlargetext + "\" /></a></p>";
	document.getElementById('enlargeVideo').innerHTML="<p><a href=\"#\" onClick=\"enlargeFLVVideo(" + vid + "," + aid + ");\" style='color:#404040; font-size:9px;'>"+enlargetext+"</a></p>";
	var videocode = "<p id=\"flvplayer\"><a href=\"http://www.macromedia.com/go/getflashplayer\">Get the Flash Player</a> to see this player.</p>\n"
	document.getElementById('embedVideo').innerHTML=videocode;
	var FO = { movie:"admin/modules/agency/flvplayer.swf",width:"" + width + "",height:"" + height + "",majorversion:"7",build:"0",bgcolor:"#FFFFFF",flashvars:"file=" + file + "&showdigits=true&autostart=" + autostart + "" };
	UFO.create(FO,"flvplayer");
}

// stop video
function stopVideo() {
	document.getElementById('embedVideo').innerHTML="";
	document.getElementById('enlargeVideo').innerHTML="";
}

function stopVideo2(aid) {
	if(globVideoSwitch == "flv") {
		embedFLV(globVid,aid,'false');
	}
	else if(globVideoSwitch == "yt") {
		embedYT(globVid,aid,'false');
	}
}

// activate photo gallery
function activatePhotogallery(aid) {
	//document.getElementById('embedVideo').innerHTML="";
	//document.getElementById('enlargeVideo').innerHTML="";
	var xmlhttp = createHttpRequest();
	targetURL = "admin/modules/agency/ajax/fillPhotogallery.php";
	
	xmlhttp.open("GET", targetURL + "?aid=" + aid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// deactivate photo gallery
function deactivatePhotogallery(aid) {
	var xmlhttp = createHttpRequest();
	targetURL = "admin/modules/agency/ajax/blankPhotogallery.php";
	
	xmlhttp.open("GET", targetURL + "?aid=" + aid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// © Christian Köchy http://www.shck.de mail@shck.de
function shckbp(shckp,shckti,shckte,copyright)
{ 
	var undefined;

	if (shckte==undefined)
		{shckte='';}
	
	if (shckti==undefined)
		{shckti='';}
	
	shcknw = window.open('', '','resizable=1');
	
	with (shcknw)
	{
		document.open();
		document.write('<!--\n\t© Christian Köchy\n\thttp://www.shck.de\n\tmail@shck.de\n-->\n\n');
		document.write('<title>'+shckte+'</title>');
		//document.write('<meta http-equiv=\"imagetoolbar\" content=\"no\">');
		document.write('<body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" scroll=\"no\" onload=\"opener.shckrez(document.images[0].width,document.images[0].height)\">')
		document.write('<a href=\"javascript:self.close()\">');
		document.write('<img src=\"'+shckp+'\" border=\"0\" alt=\"'+shckte+'\ title=\"'+shckte+'\" />');
		document.write('</a>');
		document.write('<br /><center>');
		document.write('<h1 style=\"font-family:Verdana,Arial,Helvetica; font-size:14px; margin:5px; padding:0;\">'+shckte+'</h1>');
		if (copyright != "" && copyright != "undefined") {
			//document.write('<td align=\"right\">');
			document.write('<span style=\"font-family:Verdana,Arial; font-size:11px;\">&copy; <strong>' + copyright + "</strong></span>");
			//document.write('</td>');
		}
		//document.write('</center>');
		//document.write('<table width=\"100%\" cellpadding=3 cellspacing=0 border=0><tr><td>');
		document.write('<br /><img src=\"templates/default/images/logo_unit_one_small.gif\" alt=\"unit|one\" title=\"unit|one\" border=\"0\" />');
		//document.write('</td>');
		//document.write('</tr></table>');
		document.write('<br /><a href=\"javascript:self.close()\">');
		document.write('<img src=\"templates/default/images/close2.gif\" alt=\"\" title=\"\" border=\"0\" />');
		document.write('</a>&nbsp;&nbsp;<a href=\"javascript:print()\"><img src=\"templates/default/images/pikt_print.gif\" alt=\"\" title=\"\" border=\"0\" /></a></center>');
		document.close();
	}
}

// © Christian Köchy http://www.shck.de mail@shck.de
function shckrez(x,y)
{
	//alert(navigator.appName);
	//alert(navigator.appVersion);
	
	//alert("X: " + x + ", Y: " + y);
	
	y +=130;
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		if (navigator.appVersion.indexOf("7.0")!=-1)
		{ shcknw.resizeTo(x+10,y+70); }
		else
		{ shcknw.resizeTo(x+11,y+57); }
	}
	
	else
	{
		if(navigator.appVersion.substring(0,1) < "5")
			{shcknw.resizeTo(x,y);}
		else
			{shcknw.resizeTo(x+8,y+60);}
	}
	
	shckx=(screen.availWidth/2)-(x/2);
	shcky=(screen.availHeight/2)-(y/2);
	shcknw.moveTo(shckx,shcky);
}


// agent info
function agentData(agentphone, agentemail) {
	if (document.getElementById('agentPhoneInfo') && agentphone!='') document.getElementById('agentPhoneInfo').innerHTML = agentphone;
	if (document.getElementById('agentEmailInfo') && agentemail!='') document.getElementById('agentEmailInfo').href = "mailto:" + agentemail;
}

// display name and agent info
function displayName(actorname,agentname, agentphone, agentemail, agentpic) {
	if (document.getElementById('actorName')) document.getElementById('actorName').innerHTML = actorname;
	if (document.getElementById('agentName') && agentname!='') document.getElementById('agentName').innerHTML = agentname;
	if (document.getElementById('agentPic') && typeof(agentpic)!="undefined") document.getElementById('agentPic').innerHTML = "<img src='"+agentpic+"'>";
	if (document.getElementById('agentInfo') && agentphone!='') {
		document.getElementById('agentInfo').style.visibility = 'visible';
		document.getElementById('agentPhone').innerHTML = agentphone;
	}
	if (document.getElementById('agentEmail') && agentemail!='') document.getElementById('agentEmail').href = "mailto:" + agentemail;
}

// hide name and agent info
function hideName() {
	if (document.getElementById('actorName')) document.getElementById('actorName').innerHTML = '';
	if (document.getElementById('agentName')) document.getElementById('agentName').innerHTML = '';
	if (document.getElementById('agentPic')) document.getElementById('agentPic').innerHTML = '';
	if (document.getElementById('agentPhone')) document.getElementById('agentPhone').innerHTML = '';
	if (document.getElementById('agentInfo')) document.getElementById('agentInfo').style.visibility = 'hidden';
}

// select actor
function selectActor(url) {
	document.location.href=url;
}

// select agent
function selectAgent(url) {
	document.location.href=url;
}

// toggle agent selector
function toggleAgentSelector() {
	var xmlhttp = createHttpRequest();
	targetURL = "ajax/toggleAgentSelectorVisibility.php";
	
	if (document.getElementById('toggleagentselector').checked==true) value = 1;
	else value = 0;
	
	xmlhttp.open("GET", targetURL + "?vis=" + value, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			//alert(xmlhttp.status);
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// get xml data
function getXMLData(p1)	{
	return (p1 && p1[0] && p1[0].firstChild)?p1[0].firstChild.data:'';
}

//alert("js loaded, location:" + location.href);
