var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;
var halfScreenWidth = screenWidth / 2;
var halfScreenHeight = screenHeight / 2;


function popup(url, name, width, height) {
	
	if (name == null) {
		name = 'popup';
	}
	
	if (width == null) {
		width = 600;
	}
	
	if (height == null) {
		height = 300;
	}
	

	var xPos = 0;
	if (screenWidth == null) {
		xPos = 50;
	} else if (width > screenWidth) {
		width = screenWidth - 20;
		xPos = 5;
	} else {
		xPos = halfScreenWidth - ( width / 2 );
	}

	var yPos = 0;
	if (screenHeight == null) {
		yPos = 50;
	} else if (height > screenHeight) {
		height = screenHeight - 40;
		yPos = 5;
	} else {
		yPos = halfScreenHeight - ( height / 2 );
	}

	var tempWin = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes,left=' + xPos + ',top=' + yPos);
	tempWin.focus();
}




function selectProduct( idTextBoxName, nameTextBoxName ) {
	selectProduct( idTextBoxName, nameTextBoxName, '' );
}

function selectProduct( idTextBoxName, nameTextBoxName, priceTextBoxName ) {
	popup( '/shared/admin/select/product.aspx?idTextBoxName=' + escape(idTextBoxName) + '&nameTextBoxName=' + escape(nameTextBoxName) + '&priceTextBoxName=' + escape(priceTextBoxName), 'selectProduct', 800, 350 );
}




// adds a link to a textfield
function addLink(mytextfield) {
	var link = prompt('Please enter the link url, eg. http://www.google.com/', 'http://');
	if (link == null) {
		// is null when user presses escape (at least in IE5.0)
		return;
	}
	if (link.indexOf(':') < 0) {
		alert('Not a valid link. Examples of valid links:\n\nhttp://www.google.com - website link\nmailto:someone@somewhere.com - email link');
		return;
	}
	var linkName = "";
	while (linkName == "") {
		linkName = prompt('Please enter the link name, eg Google', '');
		if (linkName == null) {
			// is null when user presses escape (at least in IE5.0)
			return;
		}
		if (linkName.length == 0) {
			if (!confirm('Please enter a name for this link. This will be the text that users can click on.\nOtherwise, press \'cancel\' if you do not wish to add a link.')) {
				return;
			}
		}
	}
	mytextfield.value += "<a href=\"" + link + "\">" + linkName + "</a>";
	mytextfield.focus();
}


/****************************************App Writer******************************************/

function writeMedia(htmlText)
{
    document.write(htmlText);
}