// JavaScript Document
var values, pgroupID, prodIDgroup, prodID;

function change(el)
{
	if(document.getElementById('calcform'))
	{
		document.getElementById('calcform').innerHTML = '<div align="center"><img src="/images/ajax-loader.gif" /></div>';
	}
	switch (el.id){
		case "catID":
			if(hasvalue(el))
			{
				docClickLoader.loadInto('calc_inline.asp?catID=' + getvalue(el), 'targetArea2');
			}
			break;
		case "prodID":
			if(hasvalue(el))
			{
				docClickLoader.loadInto('calc_inline.asp?catID=' + getvalue(el.form.catID) + '&prodID=' + getvalue(el), 'targetArea2');
			}
			break;
		case "prodPriceID":
			if(hasvalue(el))
			{
				docClickLoader.loadInto('calc_inline.asp?catID=' + getvalue(el.form.catID) + '&prodID=' + getvalue(el.form.prodID) + '&prodPriceID=' + getvalue(el), 'targetArea2');
			}
			if(document.getElementById('targetArea3'))
			{
				document.getElementById('targetArea3').style.visibility="hidden";
				document.getElementById('targetArea3').style.display="none";	
			}
			break;
		default : return true;
	}
}

function update_insert(el, page_str)
{
	var pgroupID = document.getElementById('pgroupID').value; //el.form.pgroupID.value;
	var prodIDgroup =  document.getElementById('prodIDgroup').value; //el.form.prodIDgroup.value;
	var prodID = document.getElementById('prodID').value; //el.form.prodID.value;
	var prodPriceID = el.options[el.selectedIndex].value;
	if (page_str == 'addtocart1_det_insert.asp')
	{
		docClickLoader.loadInto(page_str + '?prodIDgroup=' + prodIDgroup + '&prodPriceID=' + prodPriceID + '&pgroupID=' + pgroupID + '&prodID=' + prodID, 'targetArea2');
	}
	else
	{
		docClickLoader.loadInto(page_str + '?prodIDgroup=' + prodIDgroup + '&prodPriceID=' + prodPriceID + '&pgroupID=' + pgroupID, 'targetArea2');
		
	}
}

function redirect(str1, str2)
{
	docClickLoader.loadInto(str1, str2);
}
// Welcome to the HTMLHttpRequest demonstration!
//
// This script allows you to make background asynchronous GET and POST requests to a
// server in an accessible manner that is backwards-compatible with older browsers,
// mobile devices, screenreaders and search engines.
//
// The overall architecture is assembled in 3 layers:
//
// 1) A "Transport" object ('HTMLHttpRequest') that makes a request to the server.
// 2) A "Threading" object ('RemoteFileLoader') that creates and allocates Transports
//    and provides an easy way of loading content into your existing page.
// 3) An "Interface" layer of code that captures clicks/submissions on the document.
//
// Layers (1) and (2) are objects included in the external .JS file above.
// Both contain documentation if you are interested in customising the implementation.
// Otherwise, the code below is the "Interface" layer that will process our document.


// First, we create an example object for our document click handler.
var docClickLoader = new RemoteFileLoader('docClickLoader');

// At any stage you can call docClickLoader.loadInto('file.html', 'IDOfTarget') to trigger
// a content load into an element from your script.
// The example below does this when suitable links in the document are clicked.


function loadInto(src, destId, evt)
{
 // Called to when a link with class="loadinto-IdOfTarget" is clicked.
 // Parameters: src = reference to link, destId = ID of target element, evt = event object.
 var ok = docClickLoader.loadInto(src.href || src.getAttribute('href'), destId);
 if (ok) cancelEvent(evt);
};


function toggleInto(src, destId, evt)
{
 // As above, but loads only once and toggles the display of the target.
 var dest = document.getElementById(destId);
 if (!dest.contentLoaded)
 {
  var ok = docClickLoader.loadInto(src.href || src.getAttribute('href'), destId);
  if (ok) dest.contentLoaded = true;
 }
 cancelEvent(evt);
 if (!dest.toggleState)
 {
  src.innerHTML = 'Close: ' + src.innerHTML;
  dest.style.display = 'block';
  dest.toggleState = 1;
 }
 else
 {
  src.innerHTML = src.innerHTML.replace(/^Close: /, '');
  dest.style.display = 'none';
  dest.toggleState = 0;
 }
};


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function UnformatCurrency(num)
{
    var noJunk = ""
    var withDollar = ""
    var foundDecimal = 0
    var foundAlphaChar = 0
    num += "";

    if (num == "") { return(0); }
    for (i=0; i <= num.length; i++)
    {
        var thisChar = num.substring(i, i+1);
        if (thisChar == ".")
        {
          foundDecimal = 1;
          noJunk = noJunk + thisChar;
        }
        if ((thisChar < "0") || (thisChar > "9"))
        {
          if ((thisChar != "$") && (thisChar !=".") && (thisChar != ",") && (thisChar != " ") && (thisChar !="")) foundAlphaChar = 1;
        }
        else 
 {
    withDollar = withDollar + thisChar
    noJunk = noJunk + thisChar
 }

 if ((thisChar == "$") || (thisChar == ".") || (thisChar == ","))
 {
   withDollar = withDollar + thisChar
 }
  }
     if (foundDecimal) { return parseFloat(noJunk); }
     else if (noJunk.length > 0) { return parseFloat(noJunk); }
     else return 0;
}
function formatmynumber (num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (num);
}
function GetSelectedItem() {

chosen = "";
len = document.getElementById('myside').length; //document.getElementById('myside').length;

for (i = 0; i <len; i++) {
if (document.getElementById('myside')[i].checked){ //document.getElementById('myside')[i].checked) {
chosen = document.getElementById('myside')[i].value; //document.getElementById('myside')[i].value;
}
}

if (chosen == "") {
alert("No Location Chosen")
}
else {
document.getElementById('proofID')[1].disabled=false;
}
updatallprices();
}
function setSides(num) {
if (num == 1) {
document.getElementById('proofPrice_1').value = formatCurrency(document.getElementById('mysideamt1').value);
if (document.getElementsByName('proofID')[1].checked){
document.getElementById('proofPrice').value = UnformatCurrency(document.getElementById('proofPrice_1').value); 
document.getElementById('mysideamt').value = UnformatCurrency(document.getElementById('proofPrice_1').value); 
}
} else {
document.getElementById('proofPrice_1').value = formatCurrency(document.getElementById('mysideamt2').value)
if (document.getElementsByName('proofID')[1].checked) {
document.getElementById('proofPrice').value = UnformatCurrency(document.getElementById('proofPrice_1').value);
document.getElementById('mysideamt').value = UnformatCurrency(document.getElementById('proofPrice_1').value);
}
}
document.getElementsByName('proofID')[1].disabled=false;
document.getElementsByName('proofID')[2].disabled=false;
updatallprices()
}
function activeMaillist() {
	if(!checkConflict())
	{
		document.getElementById('tomail').checked = false;
		return false;
	}

if (document.getElementById('maillistActive').value==0) { 
//alert("USPS requires a 4”w by 2”h space left clear for inkjetting and barcoding of any piece that mails. Please make sure you have left adequate space to meet these requirement. Any adjustments required by PrintDirectForLess.com will incur a $25 charge.");
openWin('/address-mailing-services-details.html','MailServ','scrollbars=yes','500','500','true');
document.getElementById('mailshop').disabled=false; 
if (document.getElementById('myhidden_prodIDgroup'))
{
	document.getElementById('mailshop').disabled=false; 
}
else
{
	document.getElementsByName('mailshopType')[0].disabled=false;	
}
document.getElementsByName('mailshopType')[1].disabled=false;
document.getElementsByName('mailshopType')[2].disabled=false;
document.getElementById('mailshopdate').disabled=false;
document.getElementById('BtnCal').disabled=false;
document.getElementById('maillistActive').value=1;
addnote('M');
} else {
document.getElementById('maillistActive').value=0;
document.getElementById('mailPrice').value = '';
document.getElementById('mailshopdate').value = '';
document.getElementById('mailShopPrice').value = 0;
document.getElementById('addOnIds2').value = '';
selectOption(0);
clear_mailshopType();
document.getElementById('mailshop').disabled=true;
document.getElementsByName('mailshopType')[0].disabled=true;
document.getElementsByName('mailshopType')[1].disabled=true;
document.getElementsByName('mailshopType')[2].disabled=true;
document.getElementById('mailshopdate').disabled=true;
document.getElementById('mailPrice').disabled=true;
document.getElementById('BtnCal').disabled=true;
remnote('M');
}
updateweight();
updatemodarray();
updatallprices()
}
function clear_mailshopType() {
     for (var i = 0; i < document.getElementsByName('mailshopType').length; i++) {
          document.getElementsByName('mailshopType')[i].checked = false;
     }
}
function selectOption(num)
{
	var selObj = document.getElementById('mailshop');
	selObj.selectedIndex = num;
}

function addAddons(num) {
	var myprice2 = 0;
	var a = new Array();
	var design_id = -1;
	var i, j;
	var wafer_id = -1;
	var turnid, turnval, turnprodid;
	remnote('A');
	remnote('D');
	remnote('W');
	if(document.getElementById('design_Id'))
	{
		design_id = document.getElementById('design_Id').value;
	}
	if(document.getElementById('wafer_id'))
	{
		wafer_id = document.getElementById('wafer_id').value;
	}
	//alert("num: " + num + ", modid: " + eval("document.getElementsByName('modPriceID')["+num+"].value") + ", mod_checked: " + eval("document.getElementsByName('modPriceID')["+num+"].checked"));
	turnprodid = "";
	//turn around time checks and calculations
	if(document.getElementById('radTurnAround'))
	{
		for(i = 0; i < document.getElementsByName('radTurnAround').length; i++)
		{
			if(document.getElementsByName('radTurnAround')[i].checked == true)
			{
				turnid = document.getElementsByName('radTurnAround')[i].value;
			}
		}
		if(document.getElementById('hdnRadTurnAroundProdID_' + turnid))
		{
			turnprodid = document.getElementById('hdnRadTurnAroundProdID_' + turnid).value;
		}
		if(document.getElementById('hdnRadTurnAroundPrice_' + turnid))
		{
			turnval = document.getElementById('hdnRadTurnAroundPrice_' + turnid).value;
		}
		if(turnprodid != "")
		{
			a.push(turnprodid);
			myprice2 = parseFloat(turnval);	
		}
	}
	//end turn around time calcs
	/*
	*/
	if(document.getElementById('modPriceID'))
	{
		if (eval("document.getElementsByName('modPriceID')["+num+"].checked")) {
			eval("document.getElementById('modPrice_"+num+"').disabled=false");
		} 
		else {
			eval("document.getElementById('modPrice_"+num+"').disabled=true");
		}
	}
	else
	{
		var d = document.createElement('div');
		var p = document.getElementById('prodID').value;
		var q = document.getElementById('myQty').value;
		d.style.display = 'none';
		d.style.visibility = 'hidden';
		d.id = 'errorDiv';
		docClickLoader.loadInto('error_mail.asp?prodID=' + p + '&qty=' + q, 'errorDiv');
	}

	for(i = 0; i < document.getElementsByName('modPriceID').length; i++) {
		if (eval("document.getElementsByName('modPriceID')["+i+"].checked")) {
			myprice2 = myprice2 + parseFloat(UnformatCurrency(eval("document.getElementById('modPrice_"+i+"').value")));
			if(eval("document.getElementsByName('modPriceID')["+i+"].value.length") > 0)
			{
				a.push(eval("document.getElementsByName('modPriceID')["+i+"].value"));
			}
			else
			{//kludge for safari
				a.push(eval("document.getElementById('selFamily_"+i+"').options[document.getElementById('selFamily_"+i+"').selectedIndex].value"));	
			}
			for(j = 0; j < a.length; j++)
			{
				if(a[j] == design_id)
				{
					addnote('D');	
				}
				else if(a[j] == wafer_id)
				{
					addnote('W');
				}
				else
				{
					addnote('A');	
				}		
			}
		} 
	}
	document.getElementById('addOnIds').value = a;
	document.getElementById('addOnPrice').value = myprice2;
	updatemodarray();
	updatallprices();
}

function activateMainPrice(str) {
document.getElementById('price_118').disabled=false;
}
function updatallprices() {
var a =  parseFloat(document.getElementById('prodIDPriceCalc').value)
var b =  parseFloat(document.getElementById('addOnPrice').value)
var c =  parseFloat(document.getElementById('mailShopPrice').value)
var d =  parseFloat(document.getElementById('proofPrice').value)
var e =  parseFloat(document.getElementById('cutShopPrice').value)
document.getElementById('myprice').value = formatCurrency(a + b + c + d + e);
if(document.getElementById('myprice2'))
{
	document.getElementById('myprice2').value = formatCurrency(a + b + c + d + e);	
}
if(document.getElementById('radTurnAround'))
{
	setTurnAround();	
}
}
function calcPrice(num,num1) {
	document.getElementById('prodIDPriceCalc').value = UnformatCurrency(num);
	for(i = 0; i < document.getElementsByName('myQty').length; i++)
	{
		if(document.getElementsByName('myQty')[i].type == 'hidden')
		{
			document.getElementsByName('myQty')[i].value = num1;			
		}
		else
		{
			document.getElementsByName('myQty')[i].value = formatmynumber(num1);					
		}
	}
	updatallprices()
}
function getProofPrice_0() {
document.getElementById('proofPrice_0').disabled=false;
document.getElementById('proofPrice_1').disabled=true;
document.getElementById('proofPrice_2').disabled=true;
document.getElementById('proofPrice').value = UnformatCurrency(document.getElementById('proofPrice_0').value);
document.getElementById('mysideamt').value = UnformatCurrency(document.getElementById('proofPrice_0').value);
updatallprices();
//add udesignit note
remnote('MP');
}
function getProofPrice_1() {
document.getElementById('proofPrice_0').disabled=true;
document.getElementById('proofPrice_1').disabled=false;
document.getElementById('proofPrice_2').disabled=true;
document.getElementById('proofPrice').value = UnformatCurrency(document.getElementById('proofPrice_1').value);
document.getElementById('mysideamt').value = UnformatCurrency(document.getElementById('proofPrice_1').value);
updatallprices()
addnote('MP');
}
function getProofPrice_2() {
document.getElementById('proofPrice_0').disabled=true;
document.getElementById('proofPrice_1').disabled=true;
document.getElementById('proofPrice_2').disabled=false;
document.getElementById('proofPrice').value = UnformatCurrency(document.getElementById('proofPrice_2').value);
document.getElementById('mysideamt').value = UnformatCurrency(document.getElementById('proofPrice_2').value);
updatallprices()
remnote('MP');
}
function getcut() {
var selObj = document.getElementById('cutshop');
var txtIndexObj = document.getElementById('cutPrice');
var selIndex = selObj.selectedIndex;
var myqty;
for(i = 0; i < document.getElementsByName('myQty').length; i++)
{
	if(document.getElementsByName('myQty')[i].type == 'hidden')
	{
		myqty = document.getElementsByName('myQty')[i].value;			
	}
}

if (selIndex==0) {
document.getElementById('cutPrice').value = '';
document.getElementById('cutShopPrice').value = 0;
document.getElementById('addOnCutQty').value = myqty;
remnote('X');
} else {
document.getElementById('cutPrice').value = formatCurrency((((selIndex+1)*myqty)*document.getElementById('addOnCutPrice').value)/1000);
document.getElementById('cutShopPrice').value = (((selIndex+1)*myqty)*document.getElementById('addOnCutPrice').value)/1000;
document.getElementById('addOnCutQty').value = myqty*(selIndex+1);
addnote('X');
}
updatallprices();
}
function getmaillist() {

var selObj = document.getElementById('mailshop');
var txtIndexObj = document.getElementById('mailPrice');
var txtValueObj = document.getElementById('addOnIds2');
var selIndex = selObj.selectedIndex;
var c;
if (document.getElementById('myhidden_cmyarray'))
{
	c = document.getElementById('myhidden_cmyarray').value.split(",")
}
if (selIndex==0) {
document.getElementById('mailPrice').disabled=true;
document.getElementById('mailPrice').value = '';
document.getElementById('mailShopPrice').value = 0;
document.getElementById('addOnIds2').value = '';
if(document.getElementById('mailid'))
{
	document.getElementById('mailid').value = '';	
}
} else {
document.getElementById('mailPrice').disabled=false;
document.getElementById('mailPrice').value = formatCurrency(c[selIndex-1]);
document.getElementById('mailShopPrice').value = c[selIndex-1];
document.getElementById('addOnIds2').value = selObj.options[selIndex].value;
if(document.getElementById('mailid'))
{
	document.getElementById('mailid').value = selObj.options[selIndex].value;
}
}
updateweight();
updatemodarray();
updatallprices();
}
function updatemodarray() {
	if (document.getElementById('addOnIds').value!=''){
		if (document.getElementById('addOnIds2').value!=''){
			document.getElementById('addOnIds3').value = document.getElementById('addOnIds').value+','+document.getElementById('addOnIds2').value;
		}
		else {
			document.getElementById('addOnIds3').value = document.getElementById('addOnIds').value;
		} 
	}
	else {
		document.getElementById('addOnIds3').value = document.getElementById('addOnIds2').value;
	}
}

function setFamilyAddon(num)
{
	
	var i, id, price, waschecked
	waschecked = false;
	//alert( "sel_fam_index: " + eval("document.getElementById('selFamily_"+num+"').selectedIndex"));
	if(!checkConflict())
	{
		document.getElementById('selFamily_'+num).selectedIndex = 0;
		//return false;
	}
	if(eval("document.getElementById('selFamily_"+num+"')"))
	{
		i = eval("document.getElementById('selFamily_"+num+"').selectedIndex");
		if(i == 0)
		{
			eval("document.getElementsByName('modPriceID')["+num+"].disabled=true");
			eval("document.getElementsByName('modPriceID')["+num+"].value=''");
			eval("document.getElementsByName('modPriceID')["+num+"].checked=false");
			addAddons(num);
			eval("document.getElementById('modPrice_"+num+"').value='$0.00'");						
			eval("document.getElementById('modPrice_"+num+"').disabled=true");						
		}
		else
		{
			//alert("sel_fam_value: " + eval("document.getElementById('selFamily_"+num+"').options["+i+"].value"));
			id = eval("document.getElementById('selFamily_"+num+"').options["+i+"].value");
			//alert("id: " + id);
			price = eval("document.getElementById('selFamily_"+num+"').options["+i+"].text");
			price = price.split(" + ")[1];
			if(eval("document.getElementsByName('modPriceID')["+num+"].checked==true"))
			{
				waschecked = true;
				eval("document.getElementsByName('modPriceID')["+num+"].checked=false");
				addAddons(num);
			}
			eval("document.getElementsByName('modPriceID')["+num+"].disabled=false");

			document.getElementsByName('modPriceID')[num].value=id;

			eval("document.getElementById('modPrice_"+num+"').value='"+price+"'");							
			eval("document.getElementsByName('modPriceID')["+num+"].checked=true");
			addAddons(num);
		}
	}
	waschecked = false;
}

function setTurnAround()
{
	
	var i, id, price, waschecked;
	var turnid;
	price = 0.00
	if(document.getElementById('radTurnAround'))
	{
		for(i = 0; i < document.getElementsByName('radTurnAround').length; i++)
		{
			turnid = document.getElementsByName('radTurnAround')[i].value;
			if(document.getElementsByName('radTurnAround')[i].checked == true)
			{
				document.getElementById('radPrice_' + turnid).disabled = false;
				price = parseFloat(document.getElementById('hdnRadTurnAroundPrice_' + turnid).value);
			}
			else
			{
				document.getElementById('radPrice_' + turnid).disabled = true;
			}
		}
		for(i = 0; i < document.getElementsByName('radTurnAround').length; i++)
		{
			turnid = document.getElementsByName('radTurnAround')[i].value;
			if(document.getElementById('hdnRadTurnAroundPrice_' + turnid))
			{
				document.getElementById('radPrice_' + turnid).value = formatCurrency(parseFloat(document.getElementById('hdnRadTurnAroundPrice_' + turnid).value) + parseFloat(document.getElementById('myprice').value.replace("$","").replace(",","")) - price);
			}
		}
	}
}

function setFamily(num)
{
	if(!document.getElementsByName('modPriceID')[num].checked)
	{
		document.getElementById('selFamily_'+num).selectedIndex = 0;
		document.getElementsByName('modPriceID')[num].disabled = true;
	}
}

function updateweight()
{
	var finalwieght, startweight, mailweight, mailcount, myQty, a, x;
	if(document.getElementById('startweight').value == '')
	{
		document.getElementById('startweight').value = document.getElementById('weight').value
	}
	if(document.getElementById('mailshop'))
	{
		x = document.getElementById('mailshop');
		if(x.selectedIndex > 0)
		{
			a = x.options[x.selectedIndex].text.split('-');
		}
		else
		{
			a = new Array('0');	
		}
		//document.getElementById('mailweight').value = a[0].trim();
		mailcount = a[0].trim();
		startweight = document.getElementById('startweight').value;
		for(i = 0; i < document.getElementsByName('myQty').length; i++)
		{
			if(document.getElementsByName('myQty')[i].type == 'hidden')
			{
				myQty = document.getElementsByName('myQty')[i].value
			}
		}
		//document.getElementById('origweight').value = startweight;		
		document.getElementById('weight').value = ((myQty - mailcount)/myQty) * startweight;
		
	}
}

function valbutton(el) {

// place any other field validations that you require here
// validate myradiobuttons
if(document.getElementsByName('radTurnAround').length > 0)
{
	myOption = -1;
	for (i=0; i < document.getElementsByName('radTurnAround').length; i++) {
		if (document.getElementsByName('radTurnAround')[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select a turn around time.");
		return false;
	}
}
if (document.getElementsByName('prodID'))
{
	myOption = -1;
	for (i=0; i < document.getElementsByName('prodID').length; i++) {
		if (document.getElementsByName('prodID')[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select an Item");
		return false;
	}
}
if(document.getElementsByName('myside'))
{
	myOption = -1;
	for(i=0; i < document.getElementsByName('myside').length; i++) {
		
		if(document.getElementsByName('myside')[i].type == 'hidden')
		{
			myOption = i;	
		}
		if(document.getElementsByName('myside')[i].type == 'radio')
		{
			if(document.getElementsByName('myside')[i].checked == true)
			{
				myOption = i;	
			}
		}
	}
	if (myOption == -1) {
		alert("Please select a Side");
		return false;
	}
}
if(document.getElementById('reqFamily'))
{
	var c, myOption;
	myOption = 1;
	for(i = 0; i < document.getElementsByName('reqFamily').length; i++)
	{
		c = document.getElementsByName('reqFamily')[i].value;
		if (document.getElementById(c).selectedIndex == 0)
		{
			highlight(document.getElementById(c), 1);
			myOption = -1;
		}
		else
		{
			highlight(document.getElementById(c), 0);
		}
	}
	if (myOption == -1) {
		alert("Please select an option for the required Addon");	
		return false;
	}
}
if(document.getElementById('tomail'))
{
	if (document.getElementById('tomail').checked) {
		myOption = -1;
		if (document.getElementById('mailshop').selectedIndex > 0) {
			myOption = 1;
		}
		if (myOption == -1) {
			alert("Please select address/mailing services");
			return false;
		}
	}
	if (document.getElementById('tomail').checked) {
		myOption = -1;
		for (i = 0; i < document.getElementsByName('mailshopType').length; i++)
		{
			if (document.getElementsByName('mailshopType')[i].checked) {
				myOption = i;
			}			
		}
		if (myOption == -1) {
			alert("Please select a Postage Type");
			return false;
		}
	}
}
/*
if (thisform.tomail.checked) {
	myOption = -1;
	if (thisform.mailshop.selectedIndex>0) {
		myOption = 1;
	}
	if (myOption == -1) {
		alert("Please select address/mailing services");
		return false;
	}
}
if (thisform.tomail.checked) {
	myOption = -1;
	for (i=thisform.mailshopType.length-1; i > -1; i--) {
		if (thisform.mailshopType[i].checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please select a Postage Type");
		return false;
	}
}
*/
// place any other field validations that you require here
// this line submits the form after validation
		if(el.form)
		{
			el.form.submit();
		}
}

String.prototype.trim = function() {
	// Strip leading and trailing white-space
	return this.replace(/^\s*|\s*$/g, "");
}

function clean(el)
{
	el.value = el.value.trim();	
}

function savestate(str)
{
	var output, i, d, f;
	output = '';
	values = '';
	d = document.getElementById('debug');
	f = eval("document.getElementById('" + str + "')");
	//d.innerHTML = "document.getElementById('" + str + "')"
	output = '<pre>';
	for(i = 0; i < f.length; i++)
	{
		if(f.elements[i].type == 'radio' || f.elements[i].type == 'checkbox' || f.elements[i].type == 'select-one' )
		{
			output = output + i + '. Name: ' + f.elements[i].name + ', Id: ' + f.elements[i].id + ', Value: ' + f.elements[i].id + '\n';
			if(f.elements[i].type == 'select-one')
			{
				values = values + f.elements[i].selectedIndex + '|';
			}
			else if (f.elements[i].checked)
			{
				values = values + '1|';
			}
			else
			{
				values = values + '0|';	
			}
		}
	}
	pgroupID = document.getElementById('pgroupID').value;
	prodIDgroup = document.getElementById('prodIDgroup').value;
	prodID = document.getElementById('prodID').value;
	output = output + '\n' + values + '</pre>';
	d.innerHTML = output;
}

function setstate(str)
{
	var new_pgroupID, new_prodIDgroup, new_prodID, d, output, i, j, varray;
	var fireOnThis, evObj;
	
	d = document.getElementById('debug');			
	new_pgroupID = document.getElementById('pgroupID').value;
	new_prodIDgroup = document.getElementById('prodIDgroup').value;
	new_prodID = document.getElementById('prodID').value;
	
	if ((pgroupID == new_pgroupID) && (prodIDgroup == new_prodIDgroup) && (prodID == new_prodID))
	{
		output =  '<pre>'
		f = eval("document.getElementById('" + str + "')");
		varray = values.split("|");
		j = 0;
		output = output + 'entering for...\n';
		for(i = 0; i < f.length; i++)
		{
			//output = output + i + '. starting loop...\n';
			//output = output + i + '. element is type: ' + f.elements[i].type + '\n';			
			if(f.elements[i].type == 'radio' || f.elements[i].type == 'checkbox' || f.elements[i].type == 'select-one' )
			{
				output = output + i + '. in type if...\n';
				output = output + i + '. name: ' + f.elements[i].name + ', id: ' + f.elements[i].id + ', value: ' + f.elements[i].id + '\n';
				if(f.elements[i].type == 'select-one')
				{
					output = output + i + '. in select-one if...\n';
					output = output + i + '. varray[j]: ' + varray[j] + ', j: ' + j + '\n';			
					if(varray[j] > 0)
					{
						output = output + i + '. varray[j] > 0...\n';
						f.elements[i].disabled = false;
						f.elements[i].selectedIndex = varray[j];
						output = output + i + '. firing change event...\n';
						fireOnThis = f.elements[i];
						evObj = document.createEvent('HTMLEvents');
						evObj.initEvent( 'change', true, true );
						fireOnThis.dispatchEvent(evObj);
					}
				}
				else
				{
					output = output + i + '. in radio/checkbox if...\n';
					output = output + i + '. varray[j]: ' + varray[j] + ', j: ' + j + '\n';			
					if(varray[j] == 1)
					{
						output = output + i + '. varray[j] == 1...\n';
						f.elements[i].disabled = false;
						//f.elements[i].checked = true;
						output = output + i + '. firing click event...\n';
						fireOnThis = f.elements[i];
						if( document.createEvent ) 
						{
							var evObj = document.createEvent('MouseEvents');
							evObj.initEvent('click', true, false);
							fireOnThis.dispatchEvent(evObj);
						} 
						else if( document.createEventObject )
						{
							fireOnThis.fireEvent('onclick');
							f.elements[i].checked = true;
						}
						if(f.elements[i].checked == false)
						{
							f.elements[i].checked = true;
						}

					}
					else
					{
						output = output + i + '. varray[j] != 1...\n';
						f.elements[i].checked = false;
					}
				}
				j++;
			}
		}
		output = output + values + '\n' + 'Product variables unchanged.\n';
		output = output + 'pgroupID: ' + new_pgroupID + ', prodIDgroup: ' + new_prodIDgroup + ', prodID: ' + new_prodID + '\n';
		output = output + 'varray.length: ' + varray.length + '\n';
		output = output + 'f.elements.length: ' + f.elements.length + '\n';
		output = output + '</pre>';
		d.innerHTML = output;
	}
}

function addnote(str)
{
	var x = document.getElementById('flags');
	if(x)
	{
		if(x.value.indexOf(str + "|") == -1)
		{
			x.value += str + "|";	
		}
	}
	
	
}

function remnote(str)
{
	var x = document.getElementById('flags');
	var i, a, newstr;
	if(x)
	{
		if(x.value.indexOf(str) > -1)
		{
			newstr = '';
			a = x.value.split("|");
			for(i=0; i < a.length; i++)
			{
				if((a[i].indexOf(str) == -1 && a[i].length > 0) || (a[i].length > 0 && (a[i].length != str.length)))
				{
					newstr += a[i] + "|";	
				}
			}
			x.value = newstr;
		}
	}
}

function toggle_vis(str, lstr)
{
	var el = document.getElementById(str);
	var el2 = document.getElementById(lstr);
	if(el.style.visibility == 'hidden')
	{
		el.style.visibility = 'visible';	
	}
	else
	{
		el.style.visibility = 'hidden';	
	}
	
	if(el.style.display == 'none')
	{
		el.style.display = 'block';
	}
	else
	{
		el.style.display = 'none';	
	}
	
	//alert('indexof ' + el2.innerHTML.indexOf("Show"));
	if(el2.innerHTML.indexOf("Show") > 0)
	{
		//alert('replacing show');
		el2.innerHTML = el2.innerHTML.replace("Show", "Hide");
	}
	else
	{
		//alert('replacing hide');
		el2.innerHTML = el2.innerHTML.replace("Hide", "Show");		
	}
}
// Kaosweaver Calendar Settings - do not remove
// by Paul Davis - http://www.kaosweaver.com
// KW_lang[English]
// KW_order[2,0,1]
// KW_del1[-]
// KW_del2[-]
// KW_dd[true]
// KW_cWidth[350]
// KW_fd[-1]

var sDate = new Array();
var mName = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var wName = new Array("Su","Mo","Tu","We","Th","Fr","Sa")
var cFontName = "Arial, Helvetica, sans-serif;"
var KW_color = new Array("#ffffff","#ffcccc","#999999","#ffffff","#ccffcc","#cccccc","#000000","#000000")
var KW_cl=0;
var KW_od=0;
var KW_tmo=0;
var KW_cWidth=350;
var KW_fd=-1;
var KW_ss=0;
var KW_sw=0;
var descx=-1;
var descy=-1;
var bwNN=(document.captureEvents)?1:0;
function popmousemove(e){descx=(bwNN)?e.pageX:event.x;descy=(bwNN)?e.pageY:event.y}
function KW_mouseInit(){
	if(bwNN)document.captureEvents(Event.MOUSEMOVE);document.onmousemove=popmousemove;
}
function m_class(m,d,y) { 
	this.month=m;this.day=d;this.year=y;this.output=this.year+"-"+this.month+"-"+this.day;
	var kd=new Date();this.special=checkDates(this.month,this.day,this.year)
	this.today=((kd.getMonth()+1)==this.month && kd.getDate()==this.day && kd.getFullYear()==this.year)
	var td=new Date(this.year, (this.month-1), this.day+KW_od);this.past=(KW_od==-1)?0:(kd>td)
	var tf=new Date(kd.getFullYear(),kd.getMonth(),kd.getDate()+KW_fd);
	var d1=new Date(this.year, (this.month-1), this.day);
	this.future=(KW_fd==-1)?0:(tf<d1);this.ss=(this.special && KW_ss);
	this.display=(this.past || this.future || this.ss);
}

// Kaosweaver End of Calendar Settings - do not remove
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function checkDates(m1,d1,y1) { //v2.1.5
	var rStr=false;for(var i=0;i<sDate.length;i++) {var tDate=sDate[i].split(",");
		if (tDate[2]=="*" || tDate[2]==y1) {if (tDate[1]==d1 && tDate[0]==m1)	rStr=true;
		}}return rStr;
}

function KW_doCalendar(obj,E,m,y) { //v2.6.0
  var d=new Date();f=0;d.setDate(1);if (!m && m!=0) {m=d.getMonth();f=KW_cl}
  if (f==1 && MM_findObj('KW_selectedMonth').value!=-1)
  m=MM_findObj('KW_selectedMonth').value-1;d.setMonth(m);
  if (!y) y=d.getFullYear();if (f==1 && MM_findObj('KW_selectedYear').value!=-1)
  y=MM_findObj('KW_selectedYear').value;d.setFullYear(y);dy=d.getDay();if (!E) E=0;
  if(E==1)dy=(dy==0)?6:dy-1;dP=new Date();dP.setDate(1);dP.setMonth(m);dP.setDate(0);
  pStart=dP.getDate()-dy+1;dStr=new Array();for (i=pStart;i<dP.getDate()+1;i++) { tmo=(KW_tmo)?"":i;
  tMonth=(m==0)?"12":m;tYear=(m==0)?y-1:y;dStr[dStr.length]=new m_class(tMonth,tmo,tYear);
  }EOM=false;for (i=1;!EOM;i++){d.setDate(i);if (m!=d.getMonth()) EOM=true; else {
  dStr[dStr.length]=new m_class((Number(m)+1),i,y);}}cnt=1;si=0;
  if(E==1)si=(d.getDay()==0)?6:d.getDay()-1;else si=d.getDay();	for (i=si;i<7;i++) {
  tMonth=(m==11)?"1":Number(m)+2;tYear=(m==11)?Number(y)+1:y; tmo=(KW_tmo)?"":cnt;
  dStr[dStr.length]=new m_class(tMonth,tmo,tYear); cnt++;}pM=(m==0)?11:m-1;
  pY=(m==0)?y-1:y;nM=(m==11)?0:Number(m)+1;nY=(m==11)?Number(y)+1:y;
  wStr="<ht"+""+"ml><he"+""+"ad><st"+""+"yle type=\"text/css\"><!--  body { background-color: "+KW_color[6]+"}\ntd {  font-family: "+cFontName+" font-size: 12px; }\n.tblHdr { font-weight: bold; color: "+KW_color[0]+"; background-color: "+KW_color[6]+" }\n.subTbl{ color: "+KW_color[0]+"; background-color: "+KW_color[7]+";  text-align: center}-->\n</st"+""+"yle>\n<ti"+""+"tle>"+mName[m]+", "+y+"</ti"+""+"tle>\n</he"+""+"ad>\n<bo"+""+"dy  topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" onLoad=\"window.focus()\">\n<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n<tr>\n<td bgcolor=\""+KW_color[6]+"\">\n<table width=\"100%\" border=0>\n"
  wStr+="<tr>\n<td align=center bgcolor=\""+KW_color[6]+"\" class=\"tblHdr\" colspan=\"4\"><a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+pM+"','"+pY+"');\" class=\"tblHdr\">&laquo</a>&nbsp;&nbsp;"+mName[m]+"&nbsp;&nbsp;<a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+nM+"','"+nY+"');\"  class=\"tblHdr\">&raquo</a></td>\n<td colspan=3 align=center class=\"tblHdr\"><a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+m+"','"+(y-1)+"');\" class=\"tblHdr\">&laquo</a>&nbsp;&nbsp;"+y+"&nbsp;&nbsp;<a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+m+"','"+(Number(y)+1)+"');\"  class=\"tblHdr\">&raquo</a></td>\n</tr>\n"
  wStr+="<tr>\n";for(wdn=0;wdn<7;wdn++)wStr+="<td class=\"subTbl\">"+wName[wdn]+"</td>\n";wStr+="</tr>\n"
  for (x=0;x<parseInt(dStr.length/7);x++) {	wStr+="<tr>\n";	for (y=0;y<7;y++) {
  yT=(E==1)?5:0;bC=(y==yT||y==6)?KW_color[2]:KW_color[3];
  if ((y==yT||y==6) && KW_sw && !dStr[x*7+y].display) dStr[x*7+y].display=true;
  if ((Number(m)+1)!=dStr[x*7+y].month) bC=KW_color[5]; if (dStr[x*7+y].special)
  bC=KW_color[4];if (dStr[x*7+y].today) bC=KW_color[1];
  a0=(KW_cl!=1)?"":"window.opener.MM_findObj('KW_selectedMonth',window.opener.document).value='"+dStr[x*7+y].month+"';window.opener.MM_findObj('KW_selectedYear',window.opener.document).value='"+dStr[x*7+y].year+"'; "
  a1=(dStr[x*7+y].display)?"":"<a href=\"javascript:window.opener.MM_findObj('"+obj+"',window.opener.document).value='"+dStr[x*7+y].output+"';"+a0+" window.close();\" >";
  a2=(dStr[x*7+y].display)?"":"</a>";
  wStr+="<td align=\"center\" bgcolor="+bC+">"+a1+dStr[x*7+y].day+a2+"</td>\n";
	}	wStr+="</tr>\n";}	wStr+="<tr><td colspan=7></td></tr></table></td></tr></table></bo"+""+"dy></ht"+""+"ml>";
	var screenX=(self.screenX)?self.screenX+20:window.screenLeft
	var screenY=(self.screenY)?self.screenY+70:window.screenTop
	var w =(descx==-1)?parseInt(screen.width/2-75):descx+screenX;
	var h=(descy==-1)?parseInt(screen.height/2-75):descy+screenY;
	if (isNaN(w)) w=descx+20
	if (isNaN(h)) h=descy+70		
	var look='width='+KW_cWidth+',height=155,left='+w+',top='+h;	popwin=window.open('','calendar',look);
	popwin.document.open();	popwin.document.write(wStr);	popwin.document.close();
}
function highlight(obj, state)
{
	var c = '#FFFFCC';
	if(obj.style)
	{
		if(state)
		{
			obj.style.borderColor=c;
			obj.style.backgroundColor=c;
		}
		else
		{
			obj.style.borderColor='';
			obj.style.backgroundColor='';
		}
	}
}

function checkConflict()
{
	//runs through known business rules conflict for adding and subtracting portions of an item
	
	//first section to prevent user from selecting both 2 sided uv coating and mail services
	var f = document.getElementById('form1');
	var e = f.elements;
	var uv = false;
	var mailshop = false;
	var i, j;
	i = 0;
	j = 0;
	
	//return true;
	for(i=0;i<e.length;i++)
	{
		if(e[i].options && e[i].selectedIndex > 0)
		{
			j = e[i].selectedIndex;
			//alert(e[i].options[j].text + ' ' + e[i].options[j].text.indexOf('UV 2'));
			if(e[i].options[j].text.indexOf('UV 2') > -1)
			{
				uv = true;	
				//alert(uv);
			}
				
		}
		if(e[i].id == 'tomail')
		{
			if(e[i].checked == true)
			{
				mailshop = true;	
			}
		}
	}
	if(uv && mailshop)
	{
		alert('The AddOns "UV 2 Sides" and "Mailing Services" cannot be selected together as UV coating prevents the printing of mailing addresses on the postcard');
		return false;
	}
	//end of uv coating, mailshop check
	
	//if we get here, there were no conflicts
	return true;
}
function openWin(theURL,winName,features, myWidth, myHeight, isCenter) { 
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.name = "pricing";
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function selectDefaults()
{
	if(document.getElementsByName('radTurnAround').length > 0)
	{
		if(document.getElementsByName('radTurnAround').length == 1)
		{
			document.getElementsByName('radTurnAround')[0].checked == true;
			addAddons(0);
		}			
	}
}
