<!-- hide script from old browsers

//###################################################################################
//config_interface2.js
//SOAP Functions to connect to DirectSmile API and build custom form using only DOM
//Built by: Bill Hartman  April 4, 2009 - April XX, 2009
//###################################################################################

var xmlDoc=null;
var MyMsgComXML="";
//var doc = 'WMUMP001';

var p='wrprepress';
var u='wrprepress';


var domain = document.domain;
var proxydomain = domain.replace("customds.","");

document.domain=proxydomain;

var doc = parent.document.getElementById("prodID").innerHTML;
//var doc = document.parent.document.body.getElementById("prodID").innerHTML;    // MWS (suggested by Bill)

var imageholder = 'imgProd';
var previewframe = 'iframe1';


var DirectSmileDomain='customds.'+getParentZone(document.domain);			// 05/22/2009  MWS  i3
//var formname = parent.document.forms[0].id;  //Assumes this is the only form


var formname = 'customDS'; //Directly assign form name
var width = "100%";
var height = "300px";


// 05/15/2009  MWS  i3
var fileUploadControls="";


//###########################################################
//This function will add the input fields to the page via Dom
//###########################################################
function add(TEST_type, name, value, label, type) {


	//####################
	//Build our containers
	//####################


	switch(type){
		case "TextBox":
			var holderRow = parent.document.getElementById(formname).parentNode.parentNode.parentNode.insertRow(6);
			var fillerCell = holderRow.insertCell(0);
			var holderCell = holderRow.insertCell(1);
			fillerCell.style.width="10px";
			holderRow.setAttribute('id',"customrow");
		
			var nameLabel = parent.document.createElement('div'); 
			var nameText = parent.document.createElement('div'); 
		
			var linebreak = parent.document.createElement('br');
			var boldlabel = parent.document.createElement('b');
			boldlabel.innerHTML = label;
			nameText.appendChild(boldlabel);
			nameText.appendChild(linebreak);
		
			var nameInput = parent.document.createElement('input'); 
	
			//###########################################
			//Assign different attributes to the element.
			//###########################################
			nameInput.setAttribute('type', type);
			nameInput.setAttribute('id', name); 
			nameInput.setAttribute('value', value); 
			nameLabel.appendChild(nameText); 
			nameLabel.appendChild(nameInput); 
	
			//##########################
			//Append the element in page
			//##########################
			//parent.document.getElementById(formname).appendChild(nameLabel);
			holderCell.appendChild(nameLabel);
		
			break;

		case "FileSelector":

                        //
                        // 05/15/2009  MWS  i3
                        // Force user to enter a file before hitting preview!
                        // This code will build a list of Upload controls that will be validated for an entry at preview time
                        //
                        if (fileUploadControls.length>0) {
                            fileUploadControls+=",";
                        }
                        fileUploadControls+=name;
                        // i3


			var holderRow = parent.document.getElementById(formname).parentNode.parentNode.parentNode.insertRow(6);
			var fillerCell = holderRow.insertCell(0);
			var holderCell = holderRow.insertCell(1);
			fillerCell.style.width="10px";
			holderRow.setAttribute('id',"customrow");

			var nameLabel = parent.document.createElement('div'); 
			var nameText = parent.document.createElement('div'); 
		
			var linebreak = parent.document.createElement('br');
			var boldlabel = parent.document.createElement('b');
			boldlabel.innerHTML = label;
			nameText.appendChild(boldlabel);
			nameText.appendChild(linebreak);

			var nameInput = parent.document.createElement('iframe');
                        nameInput.id="UploadControl";		// 05/15/2009  MWS
			nameInput.src = "http://"+DirectSmileDomain+"/ajaxupload/?NAME=" + name;
			nameInput.frameBorder = 0;
			nameInput.setAttribute('height',75);
			nameInput.setAttribute('width',250);
			nameInput.setAttribute('scrolling','no');
			
			var hiddenInput = parent.document.createElement('input');
			hiddenInput.setAttribute('type','hidden');
			hiddenInput.setAttribute('id',name);
			
			
			nameLabel.appendChild(nameText);
			nameLabel.appendChild(nameInput);
			nameLabel.appendChild(hiddenInput);
			//##########################
			//Append the element in page
			//##########################
			//parent.document.getElementById(formname).appendChild(nameLabel);
			holderCell.appendChild(nameLabel);


			break;

		default:
			alert("Input type unknown: " & name);
	}
	


}

//######################################################################
//This function will open an XML document that contains the input fields
//######################################################################





function parseXML(){
	//####################
	//Set up our variables
	//####################
	var URL = "";
	var SessionID = '';
	var DocKey = "";


        // 05/15/2009  MWS  i3
        fileUploadControls="";

	//##############################################
	//Set the Domain of the DS Server ex: domain.com
	//##############################################
	SetConstants(domain);

	//########################################
	//Do a SOAP Call to authenticate a session
	//########################################
	try{		
		SessionID = Authenticate(u,p);	
	}catch(e){
		alert("DirectSmile Interface error: (Authenticate) " + e.message);
		return;
	}

	//#################################################
	//Do a SOAP Call to get the XML of the Configurator
	//#################################################
	var url = GetDocDataInterfaceURL(SessionID, doc)

	url = url.replace("10.0.0.155", domain);


//
// 07/09/2009  MWS  
//             Wrap new HTML AJAX request for Safari/SeaMonkey/IE
//             It looks like Firefox has a problem with this method
//             so the original code is left in tact inside the if block
//
var mygetrequest=new ajaxRequest();
if (mygetrequest.overrideMimeType)
 mygetrequest.overrideMimeType('text/xml');       // Override for Firefox
mygetrequest.open("GET", url, false);             // False=Synchronus call
mygetrequest.send(null);                          // Send AJAX request

if (!mygetrequest.responseXML) {
	try{
		//#################	
		//Internet Explorer
		//#################
  		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}catch(e){
		try{
			//#############################
 			//Firefox, Mozilla, Opera, etc.
			//#############################
			xmlDoc=document.implementation.createDocument("" ,"" , null);
		}catch(e){
			alert("DirectSmile Interface error: (Load XML) " + e.message);
			return;
		}
	}	

	try{
		xmlDoc.async=SessionRunAsync;
	}catch(e){
		alert("Sorry.  Your browser will not work with our personalization tool.  Please use Microsoft Internet Explorer 6.0 (or higher) or Mozilla Firefox 3.0 (or higher).  Code:1001");
		return 0;
	}
	try{
		xmlDoc.load(url);
	}catch(e){
		//alert("error:" + e);
		alert("Sorry.  Your browser will not work with our personalization tool.  Please use Microsoft Internet Explorer 6.0 (or higher) or Mozilla Firefox 3.0 (or higher).  Code:1002");
		return 0;
	}
}
else {
    xmlDoc=mygetrequest.responseXML;
}
// End MWS  07/09/2009


	if(xmlDoc.getElementsByTagName("DataInterfaceItem").length> 0){
		//##################
		//Change View to PDF
		//##################

		
		

		//##################################
		//Iterate through all elements & add
		//##################################
//  MWS 06/03/2009  		for(i=0; i<xmlDoc.getElementsByTagName("DataInterfaceItem").length; i++){

//  MWS 06/03/2009  Reverse placement of personalization inputs so they appear correctly on page
		for(i=xmlDoc.getElementsByTagName("DataInterfaceItem").length-1; i>-1; i--){
			add(
				xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("ItemTypeName").value,
				xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value,
				xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Value").value,
				xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("DisplayName").value,
				xmlDoc.getElementsByTagName("DataInterfaceItem")[i].getElementsByTagName("Display")[0].attributes.getNamedItem("DisplayTypeName").value
			);
		}


		//########################
		//Build the preview button
		//########################
		var holderRow = parent.document.getElementById(formname).parentNode.parentNode.parentNode.insertRow(parent.document.getElementById(formname).parentNode.parentNode.parentNode.rows.length-3);
		var fillerCell = holderRow.insertCell(0);
		var holderCell = holderRow.insertCell(1);
		fillerCell.style.width="10px";

		var nameLabel = parent.document.createElement('div'); 
		var nameInput = parent.document.createElement('img'); 
		//    nameInput.setAttribute('src', '/wmu/images/preview.jpg');     MWS  06/03/2009
		nameInput.setAttribute('src', 'images/preview.jpg');             // MWS  06/03/2009
		nameInput.setAttribute('id', 'previewbtn'); 
		nameInput.style.cursor = "pointer";
		nameInput.onclick = function() { GetDocument(); };
		nameLabel.appendChild(nameInput); 

		//parent.document.getElementById(formname).appendChild(nameLabel);
		holderCell.appendChild(nameLabel);

		//######################
		//Build the progress bar
		//######################
		var progTable = parent.document.createElement('table');
		progTable.setAttribute('width','200');
		progTable.setAttribute('bgColor','#FFFFFF');
		progTable.setAttribute('id','progressBarHolder');
		var progTR = progTable.insertRow(0);
		var progTDbar = progTR.insertCell(0);
		var progTDfiller = progTR.insertCell(1);

		progTDbar.bgColor = "#FF0000";
		progTDbar.width = "1%";
		progTDbar.id = "progressBar";
		progTDbar.innerHTML = "&#160;";

		progTDfiller.bgColor = "#EEEEEE";
		progTDfiller.innerHTML = "&#160;";

		progTable.style.display = "none";
		
		parent.document.getElementById(formname).appendChild(progTable);

		//####################
		//Build Preview Window
		//####################
		
		var ifrm = parent.document.createElement("iframe");
		ifrm.setAttribute("name", 'Doc in the box');
		ifrm.setAttribute("id", previewframe);
		ifrm.setAttribute("frameBorder", "yes");
		ifrm.frameBorder = 0;
		ifrm.src = "";
		ifrm.style.width = width;
		ifrm.style.height = height;
			
		parent.document.getElementById(imageholder).parentNode.appendChild(ifrm);
		parent.document.getElementById(previewframe).style.display="none";
			

	}

//  MWS 06/03/2009  if(parent.document.getElementById("ProductDetail52_DSDocID").value.length > 0){   

        //  MWS  06/03/2009  Replace hardcode element with softcoded one as name can vary 
        //                   from college to college
        var dsDocId=getElementContaining(parent.document,0,"_DSDocID");



//  MWS        if(parent.document.getElementById("ProductDetail52_DSDocID").value.length > 0){   
        if(dsDocId && dsDocId.value.length > 0){   
		DocStatus = ParseDocStatusXML(GetDocStatus(Authenticate(u,p), dsDocId.value));
		if (DocStatus.PDFUrl != '') parent.document.getElementById(previewframe).src = DocStatus.PDFUrl.replace('10.0.0.155',DirectSmileDomain);  // MWS i3  05/22/2009 replace('10.0.0.155','customds.laloupecards.com');
		parent.document.getElementById("imgProd").style.display="none";
		parent.document.getElementById(previewframe).style.display="inline";

	}
}



function GetDocument(){

// 05/15/2009
//alert('preview 2');
//alert(document.getElementById('UploadControl')==null);   //.getElementsByTagName("span").length);
//alert(window.frames["UploadControl"].document.getElementById("UploadStatusLabel").innerHtml);

		var progressbar = parent.document.getElementById("progressBarHolder");

		progressbar.style.display="block";
		progressbar.style.zIndex="1000";				// 06/29/2009  MWS

		var URL = "";
		var SessionID = '';
		var DocKey = "";
		var DocStatus	= new Object();

                //
                // Temporary Hack
                // 05/05/2009  MWS
                // Clear "ErrorMessage" Window during AJAX call because it may still be displaying messages 
                // such as:
                // 1.  Click preview before adding to cart
                // 2.  Item xyz was added to your cart
                //
                // Currently the text box id is hardcoded but probably should be softcoded in the future
                // in case the StoreFront interface changes
                //

                var ErrorMsg=getElementContaining(parent.document,0,"_ErrorMessage");    // 06/03/2009  MWS
		if(ErrorMsg){
			ErrorMsg.innerHTML = "&nbsp;";
		}

                // 06/03/2009  MWS
		//if(parent.document.getElementById("ProductDetail52_ErrorMessage")){
	        //    parent.document.getElementById("ProductDetail52_ErrorMessage").innerHTML = "&nbsp;";
                //}


		//###############
		//Build MsgComXML
		//###############
		MyMsgComXML = '<?xml version="1.0" encoding="utf-8"?>';
		MyMsgComXML += '<COMMAND>';
		MyMsgComXML += '<Parameters>';
		MyMsgComXML += '<FandV FieldName="OUTPUT" FieldValue="PDFPreview"/>';
		MyMsgComXML += '<FandV FieldName="WATERMARK" FieldValue="SAMPLE"/>';
		MyMsgComXML += '</Parameters>';
		MyMsgComXML += '<StaticFields>';
		for(var i=0; i<xmlDoc.getElementsByTagName("DataInterfaceItem").length; i++){
// 06/22/09  MWS	MyMsgComXML += 	'<FandV FieldName="'+ xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value + '" FieldValue="' + parent.document.getElementById(xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value).value + '"/>';
                        MyMsgComXML += 	'<FandV FieldName="'+ xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value + '" FieldValue="' + emptyStringCheck(escapeXMLValue(parent.document.getElementById(xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value).value)) + '"/>';    // 06/22/09  MWS  Escape XML characters
		}
		MyMsgComXML += '</StaticFields>';
		MyMsgComXML += '</COMMAND>';


		//#####################
		//Build Final MsgComXML
		//#####################
		FinalMsgComXML = '<?xml version="1.0" encoding="utf-8"?>';
		FinalMsgComXML += '<COMMAND>';
		FinalMsgComXML += '<Parameters>';
		FinalMsgComXML += '<FandV FieldName="CIRCULATION" FieldValue="00000000001"/>';   // 06/03/2009  MWS  Add Circulation parameter -- final value to be filled in by Order Power routine
		FinalMsgComXML += '<FandV FieldName="OUTPUT" FieldValue="PDF"/>';
		FinalMsgComXML += '<FandV FieldName="JPGCOMPRESSION" FieldValue="100"/>';
		FinalMsgComXML += '<FandV FieldName="IMPPREVIEW" FieldValue="1"/>';               // 06/03/2009  MWS  Add Imposition Preview
		FinalMsgComXML += '</Parameters>';
		FinalMsgComXML += '<StaticFields>';
		for(var i=0; i<xmlDoc.getElementsByTagName("DataInterfaceItem").length; i++){
// 07/29/09  MWS        FinalMsgComXML += '<FandV FieldName="'+ xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value + '" FieldValue="' + parent.document.getElementById(xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value).value.replace(",","[[comma]]") + '"/>';
			FinalMsgComXML += '<FandV FieldName="'+ xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value + '" FieldValue="' + emptyStringCheck(escapeXMLValue(parent.document.getElementById(xmlDoc.getElementsByTagName("DataInterfaceItem")[i].attributes.getNamedItem("Name").value).value.replace(",","[[comma]]"))) + '"/>';
		}
		FinalMsgComXML += '</StaticFields>';
		FinalMsgComXML += '</COMMAND>';
		
		SetConstants(domain);	
		try{
			SessionID = Authenticate(u,p);
		}catch(e){
			alert("DirectSmile Interface error: (Render Authenticate) " + e.message);
			return;
		}





		var ResultValue = StartDoc(SessionID, doc, MyMsgComXML);

		DocStatus = ParseDocStatusXML(ResultValue);

		DocKey = DocStatus.Key


                //  MWS  06/03/2009  Replace hardcoded document Id with softcoded one
                var dsDocId=getElementContaining(parent.document,0,"_DSDocID");
                var dsXmlId=getElementContaining(parent.document,0,"_DSFinalXML");

//		if(parent.document.getElementById("ProductDetail52_DSDocID")){
		if(dsDocId){
//			parent.document.getElementById("ProductDetail52_DSDocID").value = DocKey;
			dsDocId.value = DocKey;
			//The below line does a replacement because of a special character issue with .NET
//			parent.document.getElementById("ProductDetail52_DSFinalXML").value = FinalMsgComXML.replace(/</gi,"~~~~~~~~~~");
			dsXmlId.value = FinalMsgComXML.replace(/</gi,"~~~~~~~~~~");
		}

		while (DocStatus.LastProgressPercent != 100)
		{

			DocStatus = ParseDocStatusXML(GetDocStatus(SessionID, DocKey));
			if(DocStatus.LastProgressPercent<=0){
				DocStatus.LastProgressPercent = 1;
			}
			parent.document.getElementById("progressBar").width = DocStatus.LastProgressPercent + "%";

		}

		if (DocStatus.PDFUrl != '') parent.document.getElementById(previewframe).src = DocStatus.PDFUrl.replace('10.0.0.155',DirectSmileDomain);  // MWS i3  05/22/2009 replace('10.0.0.155','customds.laloupecards.com');

                var dsDocURL=getElementContaining(parent.document,0,"_DSDocURL");   // MWS i3  07/16/2009
                dsDocURL.value=DocStatus.PDFUrl.replace('10.0.0.155',DirectSmileDomain);  // MWS i3  07/16/2009


		if(MyMsgComXML != ""){
			parent.document.getElementById("imgProd").style.display="none";
			parent.document.getElementById(previewframe).style.display="inline";
		}

		progressbar.style.display="none";
		
		scrollUp();

}

function scrollUp(){
	var offy;
	if(parent.document.pageYOffset) {
		offy = parent.document.pageYOffset;
	} else if(parent.document.documentElement && parent.document.documentElement.scrollTop){
		offy = parent.document.documentElement.scrollTop;
	} else {
		offy = parent.document.body.scrollTop;
	}

	if(offy <= 150) return;

	parent.window.scrollBy(0, -10);
	setTimeout("scrollUp()", 0);
}


// 05/22/2009  MWS
//
// Get Next Higher Zone in Domain
// Ex. store.yahoo.com returns yahoo.com
//
function getParentZone(domain) {

    var domainPieces=domain.split('.');

    var parentZone=domain;

    if (domainPieces.length>2) {
        parentZone="";
        for (var i=1; i<domainPieces.length; i++) {
            if (i>1)
                parentZone+=".";
            parentZone+=domainPieces[i];
        }
    }
    return parentZone;
}


// 06/03/2009  MWS
//
// Dynamically retrieve an element ID containing specified value
//

        function getElementContaining(doc,formName,ctlName) {
            for(var i=0; i<doc.forms[formName].length; i++) {
                var x=doc.forms[formName].elements[i];
                if (x.id.indexOf(ctlName)>0) {
                    return x;
                }
            }
            return "";
        }


// 06/22/2009  MWS
//
// Escape XML special characters
//
function escapeXMLValue(value) {

    if (value!=null) {
        value=value.replace("&","&amp;").replace("\"","&quot;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;");
    }

    return value;
}



// 07/09/2009  MWS
// http://www.javascriptkit.com/jsref/ajax.shtml
//
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}



// 07/16/2009  MWS
// Do not allow an empty string to be 
// sent to the custom graphic processor
//
function emptyStringCheck(value){
  if (value.length==0)
    return ' ';
  else
    return value;
}



//########
//Do Work!
//########

parseXML();




// end hiding script from old browsers -->