var WindowArray = [];

OpenWindow = function(Url, Width, Height)
{
	var Width = Width[1] && screen.width >= Width[1] ? Width[1] : Width[1] && screen.width > Width[0] ? screen.width : Width[0];
	var Height = Height[1] && screen.height >= Height[1] ? Height[1] : Height[1] && screen.height > Height[0] ? screen.heigth : Height[0];
	
  var Left	= Width == screen.width ? 0 : (screen.width / 2) - (Width / 2);
  var Top		= Height == screen.height ? 0 : (screen.height / 2) - (Height / 2) - 25;
  	  
	WindowArray[Url] = window.open(Url, "Window", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no, left=" + Left + ", top=" + Top + ", width=" + Width + ", height=" + Height);
	WindowArray[Url].focus();
}

OpenEleven = function(url,language)
{
	//OpenWindow(url + 'popup/' + language, [1025, 1025], [625, 625]);
	OpenWindow(url + 'popup/' + language, [screen.width, screen.width], [screen.height]);
}

OpenSite = function(url,language)
{
	OpenWindow('popup.html?language=' + language, [1025, 1025], [625, 625]);
	//OpenWindow('popup.html?language=' + language, [screen.width, screen.width], [screen.height]);
}
getLanguage = function(){
	
	if (document.location.search){
		var vals=document.location.search.substr(1).split("&");
		var request= new Array();

		for (var i in vals) {
			vals[i] = vals[i].replace(/\+/g, " ").split("=");
			request[unescape(vals[i][0])] =unescape(vals[i][1]);
		}
		return(request['language']);
	}
}

ConfirmDelete = function(url, id){
	var check = confirm("Are you sure you want to delete this address?");
	if(check){
		window.location =url;
	}
}

ConfirmSend = function(url){
	var check = confirm("Are you sure you want to send to all addresses?");
	if(check){
		window.location =url;
	}
}

ConfirmSave = function(url){
	var check = confirm("Are you sure you want to save the site?");
	if(check){
		window.location =url;
	}
}

SetTest = function(){
	var address = prompt("Please enter the email address for the test:");
	if(address){
		document.forms[0].elements[2].value = address;
		//alert(document.forms[0].elements[2].value);
		document.forms[0].submit();
	}
}
show_div = function(id){
		
		var t_div = document.getElementById(id).getElementsByTagName("div")[0];
		var t_img = document.getElementById(id).getElementsByTagName("img")[0];
				
		if(t_div.style.display == 'none' || t_div.style.display ==''){
			t_div.style.display = 'block';
			t_img.src = 'data/images/minus_sign.gif';
		} else {
			t_div.style.display = 'none';
			t_img.src = 'data/images/plus_sign.gif';
		}
}

add_HTML = function(id, src){
	var t_div = document.getElementById(id).getElementsByTagName("div")[0];
	var old_HTML = t_div.innerHTML;
	t_div.innerHTML = old_HTML + src;
	
}
select_Options = function(id){
	document.getElementById('t_Link').innerHTML = "";
	for (i=0; i<Sections[id].length; i++){
		
		var src = "<label title='Section"+i+"' for='Form[Section"+i+"]'>"+Sections[id][i][1]+"</label><div><select id='Form[Section"+i+"]' name='Form[Section"+i+"]' class='medium'><option value=''>none</option>";
		if(Modules[Sections[id][i][0]]){
			for(z=0; z<Modules[Sections[id][i][0]].length; z++){
				src += "<option value='"+Modules[Sections[id][i][0]][z][0]+"'>"+Modules[Sections[id][i][0]][z][1]+"</option>";
			}
		}
		
		src += "</div>";
		document.getElementById('t_Link').innerHTML += src;
	
	}
	
}

collect_vars = function(){
	var Tot_Secs = document.getElementById('Form[LayerID]').value;
	var Selector = document.getElementById('Form[LayerID]').value;
	for (x=0; x<Sections[Tot_Secs].length; x++){
		Selector += "," + document.getElementById('Form[Section'+x+']').value
	}
	document.getElementById('Form[NavigationItem][LinkID]').value = Selector;
}

collect_vars_2 = function(mNumber){
	var mNum = mNumber;
	var Tot_Secs = document.getElementById('Form[LayerID]').value;
	var Selector = document.getElementById('Form[LayerID]').value;
	for (x=0; x<Sections[Tot_Secs].length; x++){
		Selector += "," + document.getElementById('Form[Section'+x+']').value
	}
	var target = 'Form[Module]['+mNum+'][Item][LinkID]';
	
	document.getElementById(target).value = Selector;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

