var urls_arrInput = new Array(0);
var urls_arrInputValue = new Array(0);

var tube_arrInput = new Array(0);
var tube_arrInputValue = new Array(0);

function confirmDelete(msg,id,page) {
	
	var state = confirm(msg);
	
	if (state) {
		document.location.href = 'index.php?page=' + page + '&action=delete&id=' + id;
	} else {
		return false;
	}
	
}

function confirmTickerDelete() {
 	
	var id = document.getElementById('pick_ticker').value;
	
	var msg = "Radera rullare " + id + ", säker?";
	var state = confirm(msg);
	
	if (state) {
		document.location.href = 'index.php?page=tickers&action=delete&id=' + id;
	} else {
		return false;
	}
	
}


function addInput(which) {
	
	if(which == "urls") {

		arrInput = urls_arrInput;
		arrInputValue = urls_arrInputValue;
	
	} else if(which == "tube") {

		arrInput = tube_arrInput;
		arrInputValue = tube_arrInputValue;

	}
  
  	arrInput.push(arrInput.length);
	arrInputValue.push("");
  
  display(which);
  
}

function display(which) {
	
		if(which == "urls") {

		arrInput = urls_arrInput;
		arrInputValue = urls_arrInputValue;
	
	} else if(which == "tube") {

		arrInput = tube_arrInput;
		arrInputValue = tube_arrInputValue;

	}
	
  document.getElementById(which).innerHTML="";
  
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById(which).innerHTML += createInput(arrInput[intI], arrInputValue[intI], which);
  }
  
  var out_name = which + "_count";
  
  document.getElementById(out_name).value = intI;
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}  

function createInput(id,value,which) {
	
	var out_name = "new_" + which + "_";
	
	return '<input type="text" name="' + out_name + id + '" class="' + out_name + 'blog" onchange="javascript:saveValue('+ id +',this.value)" value="'+ value +'"><br />';

}

function deleteInput() {
  if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(); 
}

// popup-functions

function openNewPopup(url, winname, w, h) { 

	var posx = (screen.width - w) / 2;
	var posy = (screen.height - h) / 2;

	var properties = ""; 
	properties += "resizable = 0, titlebar = 0, menubar = 0, scrollbars = 0, fullscreen = 0, dependent = 0, toolbar = 0, location = 0, directories = 0, status = 0, "; 
	properties += "width = " + w + ", "; 
	properties += "height = " + h + ", ";
	properties += "left = " + posx + ", ";
	properties += "top = " + posy;
	
	window.open(url, winname, properties);
}

function openNewWindow(url, winname, w, h) { 

	var posx = (screen.width - w) / 2;
	var posy = (screen.height - h) / 2;

	var properties = ""; 
	properties += "resizable = 1, titlebar = 1, menubar = 1, scrollbars = 1, fullscreen = 0, dependent = 0, toolbar = 1, location = 1, directories = 1, status = 1, "; 
	properties += "width = " + w + ", "; 
	properties += "height = " + h + ", ";
	properties += "left = " + posx + ", ";
	properties += "top = " + posy;
	
	window.open(url, winname, properties);
}