// *************************
// Functions for XSL testing
// *************************
function test_alert(msg)
{
	alert(msg);
}

// ******************************************
// Function for statistic-URL-transformation
// ******************************************
function statistic_target(v_uTem, v_uMen, v_uCon, v_uBasVariantCon, v_title, v_target, v_userid)
{
	v_URL = "http://log.ge.cms.icteam.net/glo_logpage.aspx?";
	v_type = "Internet";
	for( var i = 0; i < (v_target.length/2); i++)
	{
		v_target = v_target.replace(/\//,"%2f");
		v_target = v_target.replace(/\?/,"%3F");
		v_target = v_target.replace(/=/,"%3d");
		v_target = v_target.replace(/&/,"%26");
	}
	if(v_uTem.length > 1)	v_URL = v_URL +"uTem="+ v_uTem + "&amp;";
	if(v_uMen.length > 1)	v_URL = v_URL +"uMen="+ v_uMen + "&amp;";
	if(v_uCon.length > 1)	v_URL = v_URL +"uCon="+ v_uCon + "&amp;";
	if(v_uBasVariantCon.length > 1)	v_URL = v_URL +"uBasVariantCon="+ v_uBasVariantCon + "&amp;";
	if(v_title.length > 1)	v_URL = v_URL +"title="+ v_title + "&amp;";
	if(v_type.length > 1)	v_URL = v_URL +"type="+ v_type + "&amp;";
	if(v_userid.length > 1)	v_URL = v_URL +"userid="+ v_userid + "&amp;";
	if(v_target.length > 1)	v_URL = v_URL +"target="+ v_target;
	
	//alert(v_URL);
	document.write("<img width=\"1\" height=\"1\" border=\"0\" src=\""+ v_URL +"\"></img>");
}

// ****************************
// Functions for exlink-feature
// ****************************
var orgtitel = document.title;

function dynamic_td()
// sets the size of an iframe in dependence to the window-settings
{		
	//var tdw = document.body.clientWidth - 198;
	var tdh = document.body.clientHeight - 170;
	parent.document.getElementById("main").width= 800;
	parent.document.getElementById("main").height= tdh;
	//alert("weite: "+tdw+" \nhoehe: "+tdh);
}

function fenstertitel()
// sets a changed window-title back to the original one.
{
	
	document.title= orgtitel;
}

// ************************************
// Functions for news-feature
// ************************************
var millis = 0;
var millis2 = 0;

function news_table(create_date)
// writes a <table>-tag which differs new and old contents. The creation date has to be in the correct format (dd-mm-yyyy).
{
	// days that a news-content is shown as new
	var days = 7;
	
	var cd = create_date;
	var d = new Date();
	millis_now = Math.round(d.getTime()/(1000*60*60*24));	// calculated and rounded to full days
	
	var d1 = new Date();
    d1.setYear(cd.substring(6,10));
    d1.setDate(cd.substring(0,2));
    d1.setMonth(cd.substring(3,5) - 1);
    millis_cd = Math.round(d1.getTime()/(1000*60*60*24));

	if(millis_now - days < millis_cd) document.write("<table class=\"new\">");
	else document.write("<table class=\"old\">");

}

function close_table()
// closes an opened <table>-tag.
{
	document.write("</table>");
}

function open_tr()
// openes a <tr>-tag.
{
	document.write("<tr>");
}

function close_tr()
// closes an opened <tr>-tag.
{
	document.write("</tr>");
}

// ********************************
// Functions for author information
// ********************************
var author_array = new Array();
var author_index = 0;

function new_author(contentname,authorname,email,createdate)
{
	if(contentname == "") contentname = "undetermined headline";
	if(authorname == "") authorname = "unknown";
	if(email == "") email = "unknown";
	if(createdate == "") createdate = "unknown";	
	author_array[author_index] = new Array(contentname,authorname,email,createdate);
	//alert(author_array[author_index].join(" , "));
	author_index++;
}

function show_authorinfo()
{
	var html = "<body><html><head><title>Author Information for "+ document.title +"</title>";
	html = html + "<link rel=\"stylesheet\" href=\"\/systemstatic\/_master\/INTERnet_styles.css\" type=\"text\/css\"></link><head><body class=\"authorinfo\">";
	html = html + "<h3>Author Information</h3>";
	html = html + "<p> \""+ document.title +"\"</p>";
	if(author_array.length == 0) html = html + "<p>This page contains no contents</p>";
	
	for(var i = 0; i < author_array.length; i++)
	{
		html = html + "<table class=\"authorinfo_table\">";
		html = html + "<tr><td class=\"authorinfo_con\" colspan=2>"+ author_array[i][0] +"</td></tr>";
		html = html + "<tr><td class=\"authorinfo_text\">author:</td><td class=\"authorinfo_info\">"+ author_array[i][1] +"</td></tr>";
		html = html + "<tr><td class=\"authorinfo_text\">email:</td>";
		if(author_array[i][2] == "unknown")	html = html + "<td class=\"authorinfo_info\">unknown</td></tr>";
		else html = html + "<td class=\"authorinfo_info\"><a href=\"mailto:"+ author_array[i][2] +"\">"+ author_array[i][2] +"</td></tr>";
		html = html + "<tr><td class=\"authorinfo_text\">created:</td><td class=\"authorinfo_info\">"+ author_array[i][3] +"</td></tr></table>";
	}
	html = html + "</body></html>";
	var window_options ="left=40, top=30, dependent=yes, scrollbars=auto,status=no, width=380, height="+ (105 + author_array.length * 85);
	splashWin = window.open("about_blank","", window_options);
	
	window.focus();
	splashWin.focus();
	splashWin.document.writeln(html);
}

// *******************
// Functions for popup
// *******************
function open_popup(w_url,wheight,wwidth)
{	
	var w_height = String(wheight);
	var w_width = String(wwidth); 
	var w_options ="dependent=yes resizable=yes scrollbars=yes "; 
	if(w_height.length > 1) w_options = w_options +"height="+ w_height +" ";	
	if(w_width.length > 1) w_options = w_options +"width="+ w_width +" ";
	//alert(w_url+"\n"+ w_options);
	splashWin = window.open(w_url,"",w_options);
	window.focus();
	splashWin.focus();
}


// ***********************************
// Function for Content-Transformation
// ***********************************
function openMailWindow()
{
	var mailText = "mailto:?subject=Internet Link Recommendation&amp;body=I thought this information is of interest for you. Please follow this link "+ window.location +" to see more information about \'"+ document.title +"\' ."
	win = window.open(mailText);
}

function openPDFTool()
{	
	var curURL = String(window.location);
	var fileending = curURL.search(/\?/);
	if(fileending < 0)
	{
		fileending = curURL.search(/.jsp/);
		if(fileending < 0) curURL = curURL + ".jsp?";
		else curURL = curURL + "?";
	}
	var uTem = curURL.search(/uTem=/);
	if(uTem > -1) 
	{
		if(curURL.charAt(uTem-1) == '?') var cut = uTem;
		else var cut = uTem-1;
		curURL = curURL.substring(0,cut) + curURL.substring(uTem+41,curURL.length);
	}
	
	for( var i = 0; i < (curURL.length/2); i++)
	{
		curURL = curURL.replace(/\//,"%2f");
		curURL = curURL.replace(/\?/,"%3F");
		curURL = curURL.replace(/=/,"%3d");
		curURL = curURL.replace(/&/,"%26");
	}
	//alert(curURL);
	var uCon = curURL.search(/uCon%3d/);
	var ic_uCon = "";
	if(uCon > -1) var ic_uCon = "%26_ic_uCon=" + curURL.substring(uCon+7,uCon+43);	
	//var pdfURL = "\/pdfcreation\/pdfcreation.jsp?exportfile=Internet-PDF-Creation&amp;parseuri=true&amp;filename="+ curURL +"%26uTem%3Db7b70058-f27c-85f9-fb14-51c948b7234f"+ ic_uCon;
	var pdfURL = "\/pdf\/create?filename="+ curURL +"%26uTem%3D4C1E9F0E-3008-48CE-841F-D6AD5A979B97";
	//alert(pdfURL);
	win = window.open(pdfURL,"");
}

function openPrintView()
{
	var curURL = String(window.location);
	var fileending = curURL.search(/\?/);
	if(fileending < 0)
	{
		fileending = curURL.search(/.jsp/);
		if(fileending < 0) curURL = curURL + ".jsp?";
		else curURL = curURL + "?";
	}
	//alert(curURL);	
	var uTem = curURL.search(/uTem=/);
	if(uTem > -1) 
	{
		if(curURL.charAt(uTem-1) == '?') var cut = uTem;
		else var cut = uTem-1;
		curURL = curURL.substring(0,cut) + curURL.substring(uTem+41,curURL.length);
	}
	var uCon = curURL.search(/uCon=/);
	var ic_uCon = "";
	if( uCon > -1) ic_uCon = "&_ic_uCon=" + curURL.substring(uCon+5,uCon+41);
	printURL = curURL + "&uTem=b7b70058-f27c-85f9-fb14-51c948b7234f"+ ic_uCon;
	//alert(printURL);
	win = window.open(printURL,"");
	win.focus();
}

function openIFrame(iFrameURL)
{
	//alert(iFrameURL);
	splashWin = window.open(iFrameURL,"");
	splashWin.focus();
}


// *****************************
// Functions for DropDown-Menues
// *****************************
var menuposition = new Array(0,0,56,130,208,366,437,438,511,703,710); //first value is for invisible "GlobalSites"-Menu
var menucode = "";
var menuname = "";
var aktmenuid = 0;
 
function clean ()
{
   	if (navigator.appVersion.charAt (0)<'5')
	{
		var layers=document.all.tags ("div");
	}
	else 
	{
		var layers=document.getElementsByTagName("div");
	}
 	for(var i = 0; i < layers.length; i++)
	{
    	if(layers[i].name == "hdiv")
		{
			layers[i].style.visibility = 'hidden';
		}
 		else if(String(layers[i].name).substring(0,6) == "ddmenu")
 		{
 			layers[i].style.visibility = 'hidden';
 		}
 		else if(String(layers[i].name).substring(0,7) == "aktmenu")
 		{
 			layers[i].style.visibility = 'hidden';
 		}			
 		else	// do not change other div-tags used on the page
 		{
 		}
   	}   	
}

function menuhold()
{
	menu(menuname);
}

function menu(vcd)
{
	var mouse_x = window.event.x - 25;
	if(mouse_x < 0) mouse_x = 0;
	
	
	//alert(mouse_x +"  "+ vcd);
		
	if (navigator.appVersion.charAt (0)<'5')
	{
		var layers=document.all.tags ("div");
	}
	else 
	{
		var layers=document.getElementsByTagName("div");
	}
	//alert(layers.length);
	for(var i = 0; i < layers.length; i++)
	{
		//alert(layers[i].name);
		if(layers[i].name == "hdiv")
		{		
			// Größe und Position auf geöffnetes ddmenu anpassen
			for(var j = 0; j < layers.length; j++)
			{
				if(layers[j].name == "ddmenu_"+vcd)
				{	
					if(menuposition.length < 1)
						if(menuname != vcd)	layers[i].style.left = mouse_x;	
					layers[i].innerHTML = layers[j].outerHTML;	
					var layerX = document.getElementsByName("hdiv")[0].firstChild;
					layerX.name = "aktmenu_"+vcd;
					layerX.className = "dd";
					layerX.style.visibility = 'visible';
					//alert(layerX.name);					
					layers[i].visibility = 'visible';
				}				
			}	
		}
 		else if(String(layers[i].name).substring(0,6) == "ddmenu")
 		{
 			layers[i].style.visibility = 'hidden';
 		}
 		else // do not change other div-tags used on the page
 		{
 		}
 	}
 	menuname = vcd;
 
}

function create_menu(vcDenotation)
{
	//alert(vcDenotation);
	var menupos = 0;
	var menuwidth = 0;
	if(menuposition.length > 0)
	{
		menupos = menuposition[aktmenuid];
		menuwidth = menuposition[aktmenuid+1] - menuposition[aktmenuid];
	}
	menucode = "<div name=\"ddmenu_"+vcDenotation+"\" style=\"position:absolute; left:"+ menupos +"; top:71; padding-top: 19px; visibility: hidden\"><table class=\"ddmenu\" style=\"width:"+ menuwidth +";\" cellpadding=\"0\" cellspacing=\"0\">" + menucode;
	aktmenuid++;
}

function add_menuitem(vcDenotation, ddURL)
{
	//alert(vcDenotation + "   "+ ddURL);
	menucode = menucode + "<tr><td class=\"ddmenuitem\" style=\"white-space: nowrap;\"><a "+ ddURL +">"+vcDenotation+"<\/a><\/td><\/tr>";
}

function write_menu()
{
	menucode = menucode + "<\/table><\/div>";
	//alert(menucode);
	document.write(menucode);
	menucode = " ";
}

// ***********************************
// Functions for GlobalSites-Selection
// ***********************************

function openGlobalSite()
{
    if (document.siteselector.selectbox.options[document.siteselector.selectbox.selectedIndex].value != "none") 
    {
    	goto = document.siteselector.selectbox.options[document.siteselector.selectbox.selectedIndex].value
    	
    	if(goto != "")
    		window.open(goto, "",'toolbar=yes,status=yes,menubar=yes,width=800,height=600,resizable=yes,scrollbars=yes,location=yes,top=0,left=0');
    }                       
}

// ***********************
// PopUP Function
function PopUp()
{
NF=window.open("/systemstatic/_master/static/X-Mas2006.htm","XMas","width=550,height=310");
NF.focus; }

// Check required Fields in ContactForms
function CheckEntries() 
{
	if(document.Formular.sendfrom.value != "" &&document.Formular.Name.value != "" &&document.Formular.Company.value != "" &&document.Formular.Address.value != "" &&document.Formular.Town.value != "" &&document.Formular.Country.value != "" &&document.Formular.Phone.value != "" ) 
	{	
		var strMail = document.Formular.sendfrom.value;
		if (window.RegExp) 
		{
			var strReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
			var strReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
			var reg1 = new RegExp(strReg1);
			var reg2 = new RegExp(strReg2);
			if (!reg1.test(strMail) && reg2.test(strMail))
			{
				//alert ("mail correct");
				return true; 
			}
			else
			{
				alert("your e-mail address is not in correct spelling");
				return false;
			}
		}
		else 
		{
			if(strMail.indexOf("@") >= 0)
			  return true;
			
			return false;
		}
	}	
	else 
	{ 
		alert("Please fill out the mandatory fields"); 
		return false; 
	} 
}

function checkMail() 
{
	if(document.Formular.man_Email.value != "") 
	{	
		var strMail = document.Formular.man_Email.value;
		if (window.RegExp) 
		{
			var strReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
			var strReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
			var reg1 = new RegExp(strReg1);
			var reg2 = new RegExp(strReg2);
			if (!reg1.test(strMail) && reg2.test(strMail))
			{
				//alert ("mail correct");
				return true; 
			}
			else
			{
				alert("your e-mail address is not in correct spelling");
				return false;
			}
		}
		else 
		{
			if(strMail.indexOf("@") >= 0)
			  return true;
			
			return false;
		}
	}
	else
	{
		return true;
	}

}

