// JavaScript Document

function changeselection( txbox ,opentxt,closetxt)
{
	var txtarea = document.getElementById (txbox);
	seltext  = (txtarea.value).substring(txtarea.selectionStart,txtarea.selectionEnd);  
	starttext = (txtarea.value).substring(0,txtarea.selectionStart);  
	endtext = (txtarea.value).substring(txtarea.selectionEnd);  

	
	
	replacetext = opentxt+seltext+closetxt;
	
	txtarea.value = starttext + replacetext + endtext;
	
}

function insertLink( txbox )
{
	var txtarea = document.getElementById (txbox);
	seltext  = (txtarea.value).substring(txtarea.selectionStart,txtarea.selectionEnd);  
	starttext = (txtarea.value).substring(0,txtarea.selectionStart);  
	endtext = (txtarea.value).substring(txtarea.selectionEnd);  

	
	linkname = seltext;
	
	if (linkname == "") linkname = prompt("What is the name of this link?");
	
	linkloc = prompt("Enter page or URL this link is pointing to");
	
	replacetext = "<a href='"+linkloc+"'>"+ linkname + "</a>";
	
	if (linkloc == null || linkname == null) return;
	
	txtarea.value = starttext + replacetext + endtext;
	
}


function copy2Clipboard(idname){
	
	document.getElementById ( idname ).select();
	
	if( window.clipboardData && clipboardData.setData )
	{	
		v =  document.getElementById( idname ).value;
		clipboardData.setData("Text",v);
	}
	
	document.getElementById ( idname ).select();
}

function fillBlock( idname,value){

	document.getElementById( idname ).value = value;
}

// USED IN CHECKOUT SCRIPT

var regSetting,prodSetting;

function showhidewindow ( idname ){

	val = document.getElementById( idname ).style.display;
	
	if (val == "none")
		document.getElementById( idname ).style.display = "";
	else
		document.getElementById( idname ).style.display = "none";
	
}

function show_window ( selbox, idname ){

	
	val = document.getElementById( selbox ).value;
	
	if (selbox == "reg_shipping"){		
		regSetting = val;
	}else  if (selbox == "prod_shipping"){	
		prodSetting = val;
	}
	
	if (val == "To Registry") {
		document.getElementById( "showRegList" ).style.display = "";
	}else {
		document.getElementById( "showRegList" ).style.display = "none";
	}
	
	if (regSetting == "To Shipping Address" || prodSetting == "To Shipping Address"){
		document.getElementById( idname ).style.display = "";
	}else {
		document.getElementById( idname ).style.display = "none";
	}
}
// =========================



function openwindow(page)
{
	window.open(page,"mywindow","toolbar=0,menubar=0,resizable=0,width=350,height=250");
}

function popUp(URL,width,height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=" + width + ",height="+ height +",left = 50,top = 50');");
}	


temp = true;

function confirmSubmit ( )
{
	valid = temp;
	temp = true; // reset form status
	return valid;
}

function confirmLink (msg,urllink){

	
	var sure = confirm(msg);
	if (sure == true)	
		window.location = urllink;

}