var popUpWindow

function checkEmail(email)
{
    if (!isEmail(email))
    {
        alert("Error: Invalid email.");
        result = false;
    }
    else
    {
        result = true;
    }
    return result;
}

function isEmail(string)
{
    var result;
    if (string.search(/^[\w\d-][\w\d-\.]{1,20}@(([\w\d-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[\w]{2})|[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})$/) != -1)
    {
        result = true;
    }
    else
    {
        result = false;
    }
    return result;
}

function initCopyBillingToShipping()
{
	if(document.getElementById(to_addr + '_SameAsBilling').checked) {
	//if(document.forms["address"].elements["shippingSameAsBilling"].checked){
		copyBillingToShipping(true);
	}
}

function copyBillingToShipping(status)
{
	var i;
	//var fields = new Array("FirstName", "LastName", "Address1", "Address2", "City", "State", "OtherProvince", "PostalCode", "Country", "Telephone", "Fax")
	var fields = new Array("Source", "AddressId", "FirstName", "LastName", "Address1", "Address2", "City", "State", "OtherProvince", "PostalCode", "Country", "Telephone", "Fax")
	var booDisable;
	if (status){ booDisable = true; }
	else{ booDisable = false; }
	for (i = 0; i < fields.length; i++)
	{
		with (document)
		{
			//alert(document.getElementById( fr_addr + '_' + fields[i] ));
			var ob = document.getElementById( to_addr + '_' + fields[i] )
			if(ob) ob.disabled = booDisable;
			//if (address["shipping" + fields[i]] != undefined){
				//address["shipping" + fields[i]].value = address["billing" + fields[i]].value;
			//	address["shipping" + fields[i]].disabled = booDisable;
			//}
		}
	}
}

function toggleBox(boxId, state)
{
    var obj = document.layers ? document.layers[boxId] : document.getElementById ? document.getElementById(boxId).style : document.all[boxId].style;
    obj.visibility = document.layers ? (state ? "show" : "hide") : (state ? "visible" : "hidden");
    return false;
}

function cango()
{
    toggleBox("container", false)
    toggleBox("StopWatch", true)
    return true;
}


function openPopUpWindow(url, width, height, scrollbars)
{
    var defaultHeight = 600;
    var defaultWidth = 800;
    var defaultScrollbars = "yes";
    
    if (height == null) { height = defaultHeight; }
    if (width == null) { width = defaultWidth; }
    if (scrollbars == null) { scrollbars = defaultScrollbars; }
    
    if (popUpWindow && !popUpWindow.closed) { popUpWindow.document.location.href = url; }
    else
    {
        popUpWindow = window.open(url, "popUpWindow", "scrollbars=" + scrollbars + ",status=no,resizable=no,left=100,top=100,width=" + width + ",height=" + height);
    }
    return false;
}
