var isReady = false;

function showAddress(What){

  if (isReady){

    document.teleport.imageAddress.value = What;
    document.teleport.textorpic[0].checked='true';
    //document.teleport.imageAddress.focus();

    //document.teleport.imageAddress.select();

  }else{

    alert("This page is not fully loaded yet...\nPlease wait for the page to finish loading.");

  }

}



function clearAddress(){

  if (isReady){

    document.teleport.imageAddress.value = '';

  }else{

    alert("This page is not fully loaded yet...\nPlease wait for the page to finish loading.");  

  }

}



function generateCode()
{
	// In textstring I gather the data that are finally written to the textarea.

	var textstring = '';
        // Get value of the textorpic radio button

	text_pic = '';

		if (document.forms['teleport'].textorpic[0].checked) {
		 text_pic = 'pic';
                 var box = document.forms['teleport'].imageAddress;
                 var message = '<img src="'+box.value+'">';
		 if (!box.value || box.value=='http://') {
			alert('Вы собрались телепортировать картинку, но не ввели ее адрес!');
			box.focus()
			return;
		       }
		} else { 
                 text_pic = 'text';
                  var box = document.forms['teleport'].textInput;
                  var message = '<p style="width:600px; color:red; font-size:50px; font-weight:bold;">'+box.value+'</p>';
		  if (!box.value) {
			alert('Вы собрались телепортировать текст, но не ввели его!');
			box.focus()
			return;
                       }
                }


		var box_x = document.forms['teleport'].x;
		if (!box_x.value) {
			alert('Введите координату смещения x!');
			box_x.focus()
			return;
		}
                var box_y = document.forms['teleport'].y;
		if (!box_y.value) {
			alert('Введите координату смещения y!');
			box_y.focus()
			return;
		}

textstring = '<div style="height:0px; width:0px; overflow:visible; margin:0; padding:0;"><div style="position:relative; bottom:' + box_y.value + 'px; left:' + box_x.value + 'px; z-index:100;">' + message + '</div></div>'; 

	// Write textstring to the textarea.

	document.forms['teleport'].output.value = textstring;
}


function example(textorpic,input,x,y) {
	if (textorpic == 'pic') {
	 document.teleport.textorpic[0].checked='true';
	 document.teleport.imageAddress.value=input;
	 document.teleport.textInput.value='';
	}
	if (textorpic == 'text') {
	 document.teleport.textorpic[1].checked='true';
	 document.teleport.textInput.value=input;
	 document.teleport.imageAddress.value='http://';
	}
	document.teleport.x.value = x;
        document.teleport.y.value = y;


	generateCode();
}