function GetBadge(){
	// if file indicated by user doesn't exist, return "blank" file to flash variable, to make the movie still work
	var retVal;
	var obj=myGetElementById('txtBadgeNbr');
	var badge=obj.value.trim();
	var base = GetBase();
	if (base == "black") {
	    base = "silver";
	}
	if (base=='') base='blank';
	if (FileExists("./FLASH/" + badge + "_" + base+".png")){
		retVal= badge;}
	else{
		retVal= 'NOTAVLBL';}
	//alert(retVal);
	return retVal;
}


function GetBase(){
	var obj;
	obj=myGetElementById('ddlFinish');
	var myindex  = obj.selectedIndex;
	var sFinish = obj[myindex].value;
	var mBase;
	switch (sFinish){
		case 'GOLD ELECTROPLATE':
			mBase = 'gold';
			break;
		case 'NICKEL ELECTROPLATE':
			mBase = 'silver';
			break;
		case 'RHODIUM ELECTROPLATE':
			mBase = 'silver';
			break;
		case 'SIL-RAY':
			mBase = 'silver';
			break;
		case 'GOL-RAY W/SIL-RAY PANELS':
			mBase='song';
			break;
		case 'SIL-RAY W/GOL-RAY PANELS':
			mBase='gons';
			break;
        case 'BLACK':
            mBase = 'black';            break;
		default:
			mBase = 'gold';
	}

	//alert(mBase);
	return mBase;
}


function GetSeal(){
	// if file indicated by user doesn't exist, return "blank" file to flash variable, to make the movie still work
	var retVal= 'NOTAVLBLM';
	var obj=myGetElementById('txtCenter');
	if (obj==null){
		return '';
	}

	var seal=obj.value.trim().toUpperCase();
	var type = GetSealType();

	if (type=='') type='M';

	//match with finish:
	// for two-tones finishes, seal must match the panels, so we can use first letter of the finish name
	var b = GetBase().substring(0,1) ;

	if (b == "b") b = "s";
	
	if (FileExists("./FLASH/" + seal + type + b + ".png")){
	    retVal = seal + type;
		}
	else{
		if (FileExists("./FLASH/" + seal + b + ".png")){
		    retVal = seal;
		} else {
		retVal = 'NOTAVLBLM';
		}

        }

	if (seal=='' || seal=='-CLICK TO SEARCH-') retVal='BLANK' + type;

	return retVal;
}


function GetSealType(){
	var obj;
	obj=myGetElementById('ddlSealType');
	var myindex  = obj.selectedIndex;
	var sType = obj[myindex].value;

	return GetSealTypeByName(sType);
}


function ClickDropship(){
	//empty textboxes if un-checked
	var obj;
	obj=myGetElementById('chkDropship');
	if (obj.checked==false) {
		obj=myGetElementById("txtDropName");
		obj.value="";
		obj = myGetElementById("txtDropContact");
		obj.value='';
		obj = myGetElementById("txtDropAddress1");
		obj.value='';
		obj = myGetElementById("txtDropAddress2");
		obj.value='';
		obj = myGetElementById("txtDropCity");
		obj.value='';
		obj = myGetElementById("txtDropState")
		obj.value='';
		obj = myGetElementById("txtDropZip");
		obj.value='';
	}

	showhide('dropship_fields');
} //end func ClickDropship

function OpenDropshipHistory() {
    
    var WinSettings = "height=400,width=700";
    
    sList=window.open("DropShipAddress.aspx","list",WinSettings);


} //end funct OpenDropshipHistory

function OrderEntryOnLoad(){
	if (myGetElementById){
		//setupEnterAsTab(); -> not working too well
		var obj, obj2;
		// show/hide dropship fields depending of checkbox value (saved in session)
		obj = myGetElementById("dropship_fields");
		obj2=myGetElementById("hidDisplayDropship");
		obj.style.display = obj2.value;

		//show dropship button only if previous records exists in the database
		obj = myGetElementById("btnDropshipHist");
		obj2=myGetElementById("hidDisplayDropshipHistButton");
		obj.style.display = obj2.value;

		RefreshLayout();
        RefreshLeatherPic();

		}//endif myGetElementById

} //end func OrderEntryOnLoad


function SearchSeal(aff) {
        var url = webHost + "SearchSeal3.aspx";
      
    if (aff) {
        url = url + "?aff=" + aff;
    }
    window.open(url, "SearchSeal", "height=600,width=820,status=1,scrollbars=yes");
}  // end func SearchSeal


function RefreshTotalPrice(){
    if (myGetElementById) {
		
		var obj;
		var nPU, nPT, nQ, cQ, nRP, nBP, nSP, nEP, nL, val;
		
		//badge qty
		obj=myGetElementById("txtQty");
		cQ=obj.value;
		
		
		obj=myGetElementById("txtBaseCost");
		val=obj.value;
		nRP = (val == '' ? 0 : parseFloat(CurrencyToNumber(val)));
		//total cost
		SetValueInTextBox("txtBaseCostTotal", "$" + (nRP * cQ).toFixed(2));

		obj=myGetElementById("txtBackCost");
		val=obj.value;
		nBP = (val == '' ? 0 : parseFloat(CurrencyToNumber(val)));
		//back qty & total cost
		SetValueInTextBox("txtBackCostTotal", nBP == 0 ? '' : "$" + (nBP * cQ).toFixed(2));
		SetValueInTextBox("txtCostQtyBack", nBP == 0 ? '' : cQ);

		obj=myGetElementById("txtSealCost");
		val=obj.value;
		nSP=(val=='' ? 0 : parseFloat(CurrencyToNumber(val)));
        //seal qty&total cost
		SetValueInTextBox("txtSealCostTotal", nSP == 0 ? '' : "$" + (nSP * cQ).toFixed(2));
		SetValueInTextBox("txtCostQtySeal", nSP == 0 ? '' : cQ);
		
		
		obj=myGetElementById("txtEnamelCost");
		val=obj.value;
		nEP = (val == '' ? 0 : parseFloat(CurrencyToNumber(val)));
		//enamel qty&total cost
		SetValueInTextBox("txtEnamelCostTotal", nEP == 0 ? '' : "$" + (nEP * cQ).toFixed(2));
		SetValueInTextBox("txtCostQtyEnamel", nEP == 0 ? '' : cQ);
		

        nL=0;
        obj=myGetElementById("txtLeatherCost");
        if (obj){
		    val=obj.value;
		    nL=(val=='' ? 0 : parseFloat(CurrencyToNumber(val)));
        }

		nPU=nRP+nBP+nSP+nEP;

		obj=myGetElementById("txtPricePerUnit");
		obj.value="$" + nPU.toFixed(2);
		
		
		obj=myGetElementById("txtCostQty");
		obj.value=cQ;
		nQ = parseInt((cQ=='')?'0':cQ);
		nPT = nQ*nPU;
		obj=myGetElementById("txtPriceTotal");
		obj.value="$" + nPT.toFixed(2);
		obj=myGetElementById("lblMultiplyByQty");
		if (obj) obj.innerText=(nQ==0)?'':'X';


		
		
		//leather qty
		obj = myGetElementById("txtQtyL");
		cQ = obj.value;
		obj = myGetElementById("txtCostQtyL");
		obj.value = (cQ=='0') ? '' : cQ ;
		nQ = parseInt((cQ == '') ? '0' : cQ);
		nPTL = nQ * nL;
		SetValueInTextBox("txtLeatherCostTotal", nPTL == 0 ? '' : "$" + nPTL.toFixed(2));
		
		obj = myGetElementById("txtPriceTotal");
		obj.value = "$" + (nPT+nPTL).toFixed(2);
		obj = myGetElementById("lblMultiplyByQtyL");
		if (obj) obj.innerText = (nQ == 0) ? '' : 'X';


		
		
	} //endif myGetElementById
}// end function RefreshTotalPrice

function SetValueInTextBox(id,val){
    var obj = myGetElementById(id);
    if (obj) {
        obj.value = val;
    }
}

function RefreshPrice(){

	var url='OrderEntryRefresh.aspx?refresh=price';
	var obj;

	obj=myGetElementById('txtBadgeNbr');
	url+= '&b=' + obj.value;

	obj=myGetElementById("ddlBack");
	if (obj) {
		url+= '&bck=' + obj[obj.selectedIndex].value;
	}

	obj=myGetElementById("ddlFinish");
	url+= '&f=' + obj[obj.selectedIndex].value;

    
	obj=myGetElementById("ddlSealType");
	//url+= '&s=' + GetSealType();
	var sealType=(obj.style.display=='none' ? "PLAIN" : obj[obj.selectedIndex].value);
	url+= '&s=' + sealType;

	obj=myGetElementById("ddlLetterType");
	url+= '&e=' + obj[obj.selectedIndex].value;

    obj=myGetElementById("ddlLeather");
    if (obj){
	    url+= '&l=' + obj[obj.selectedIndex].value;
	}

	//for FB pass the attachment as well
	obj = myGetElementById("ddlFBStyles");
	if (obj) {
	    obj = myGetElementById("ddlAttachment");
	    url += '&fbatt=' + obj[obj.selectedIndex].value;
	}
	
	xmlhttp = null;
	
	wrapXMLHTTPRequest(url, 'RefreshPrice_Ready');
} //end func RefreshPrice


function RefreshPrice_Ready(){

	if (xmlhttp.readyState==4)
		{// 4 = "loaded"
		
		if (xmlhttp.status==200)
			{// 200 = "OK"
			//alert(xmlhttp.responseText);
			//responseText is in the form: RP#BP#SP#EP (retail, back, seal, enamel prices)
			var prices=xmlhttp.responseText.split("#",5);
			var RP, BP, SP, EP, L, str, obj;
			RP=(prices[0]=='' ? 0.00 : parseFloat(prices[0]));
			BP=(prices[1]=='' ? 0.00 : parseFloat(prices[1]));
			SP=(prices[2]=='' ? 0.00 : parseFloat(prices[2]));
			EP=(prices[3]=='' ? 0.00 : parseFloat(prices[3]));
            L=(prices[4]=='' ? 0.00 : parseFloat(prices[4]));
    
			obj=myGetElementById('txtBaseCost');
			obj.value="$" + RP.toFixed(2);
   
			obj=myGetElementById("ddlBack");
			str=obj[obj.selectedIndex].value;
			obj=myGetElementById('txtBackCostDesc');
			obj.value=((BP==0) ? '' : str + ' BACK'); 
			obj=myGetElementById('txtBackCost');
			obj.value=((BP==0) ? '' :"$" + BP.toFixed(2)) ;

			//no charge when no seal selected
			obj = myGetElementById("txtCenter");
			if (obj && obj.value == "")
			    SP = 0;
			obj=myGetElementById("ddlSealType");
			str=obj[obj.selectedIndex].value;
			obj=myGetElementById('txtSealCostDesc');
			obj.value=((SP==0) ? '' : str + ' SEAL'); 
			obj=myGetElementById('txtSealCost');
			obj.value=((SP==0) ? '' :"$" + SP.toFixed(2));

			obj = myGetElementById("ddlLetterType");
			if (obj) {
			    str = obj[obj.selectedIndex].value.trim();
			}
			obj=myGetElementById('txtEnamelCostDesc');
			obj.value=((EP==0) ? '' : str + ' ENAMEL'); 
			obj=myGetElementById('txtEnamelCost');
			obj.value = ((EP == 0) ? '' : "$" + EP.toFixed(2));
			

			obj=myGetElementById('txtLeatherCostDesc');
			if (obj){
			    obj.value=((L==0) ? '' : 'LEATHER ACCESSORY'); 
                obj=myGetElementById('txtLeatherCost');
			    obj.value=((L==0) ? '' :"$" + L.toFixed(2));
			}
			RefreshTotalPrice();
		}
	else
		{
		//alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
	
}//end func RefreshPrice_Ready


function ShowControls(strControls, bShow){
	var arControls=strControls.split(",");
	for (var i=0; i<arControls.length; i++) {
		obj=myGetElementById(arControls[i]);
		if (obj != null) {
		    obj.style.display = (bShow ? "" : "none");
		} //end if obj!=null
		} //end for 
}  // end function ShowControls



function RefreshLayout(){
	var url='OrderEntryRefresh.aspx?refresh=laysize';
	var obj = myGetElementById('txtBadgeNbr');
	url+= '&b=' + obj.value;
	xmlhttp=null;
	wrapXMLHTTPRequest(url, 'RefreshLayout_Ready');

} //end function RefreshLayout

function RefreshLayout_Ready(){
	if (xmlhttp.readyState==4)
		{// 4 = "loaded"
		
		if (xmlhttp.status==200)
			{// 200 = "OK"
			//alert(xmlhttp.responseText);
			//responseText is a string of 1 and 0s, each representing the fact that corresponding control is visible or not
			//order: line1..6, back, center
			// and then: semicolon width semicolon height semicolon always_hard(0/1) semicolon no_dap(0/1) semicolon text_sep (0/1)
			var response=xmlhttp.responseText;
			var result1=response.split(";",6);
			
			//size
			obj=myGetElementById("txtBadgeSize");
			
			if (obj){
				if (parseFloat(result1[1])>0 && parseFloat(result1[2])>0)
					obj.value="Dimensions (w x h):     " + result1[1] + "'' X " + result1[2] +"''";
				if (parseFloat(result1[1])==0 && parseFloat(result1[2])>0)
					obj.value="Dimension (h):     " + result1[2] + "''";
				if (parseFloat(result1[1])>0 && parseFloat(result1[2])==0)
					obj.value="Dimension (w):     " + result1[1] + "''";
				if (parseFloat(result1[1])==0 && parseFloat(result1[2])==0)
					obj.value="";
			}
			
			
			//lines
			var result=result1[0].split("",9);
			var controls1='';  //will store the name of controls wich must be made visible (separated by comma)
			var controls0='';  //will store the name of controls wich must be made invisible (separated by comma)
			var obj;
   
			//lines
			var j=0;   // re-number lines labels
			for (var i=1;i<=6;i++){
				eval('controls' + result[i-1] + '+="lblLine' + i + ',txtLine' + i +',divLine' + i +',"');
				if (result[i-1]=='0') {
					obj=myGetElementById('txtLine' +i);
					obj.value='';
				} else {
					j = j + 1;
					obj=myGetElementById('lblLine' +i);
					if (obj) {
	                    if (document.all) {
					        obj.innerText = 'LINE ' + j;
					        } else {
					        obj.textContent = 'LINE ' + j;
					        }
					    }
				}
				
				
			}
			//no font if no lines
			if (response.substring(0,6)=='000000') {
				controls0+= 'lblFont,ddlFont,';
			}
			else {
				controls1+= 'lblFont,ddlFont,';
			}
 
			//back
			eval('controls' + result[6] + '+="lblBack,ddlBack,divBack,"');
			// emptyback if no back
			if (result[6]=='0'){
				obj=myGetElementById('ddlBack');
				if (obj!=null) {obj.value='';}
			}

			
			//center
			eval('controls' + result[7] + '+="lblCenter,txtCenter,lblSealType,ddlSealType,hSearchSeal,searchSeal,divSeal,"');
			
			
			//empty seal values if no seal
			if (result[7]=='0'){
				obj=myGetElementById('txtCenter');
				if (obj != null) { obj.value = ''; }


}

            // disable SOFT ENAMEL option if always_hard=1

            if (result1[3] == "1") {
                disableSelectOption("ddlLetterType", "SOFT (REGULAR)", true);
                selectOption("ddlLetterType", "HARD");
            } else {
                disableSelectOption("ddlLetterType", "SOFT (REGULAR)", false);
            }
            
            // disable CURVED option if no_Dap=1
            if (result1[4] == "1") {
                disableSelectOption("ddlShape", "CURVED", true);
                selectOption("ddlShape", "FLAT");
            } else {
                disableSelectOption("ddlShape", "CURVED", false);
            }


            //text separators: visible only for circular panels
            eval('controls' + result1[5] + '+="lblTextSep,ddlTextSep,divTextSep,"');
            //empty text sep value if it doesn't apply
            if (result1[5] == "0")
                selectOption("ddlTextSep", "NONE");

    //check if it's a valid model
    obj = myGetElementById("txtBadgeNbr");
    if (obj) {
        if (obj.value != "") {
            if (response.substring(8, 9) == "-")
                alert("The model you selected is not recognized by the Visualbage online ordering system.  This may mean that the model number is entered incorrectly or that the item is not set-up for online ordering yet.  Please process your order and we will call if you if we have any questions.");
        }
    }

    
			ShowControls(controls1,true);
			ShowControls(controls0,false);

			

			//refresh validators
			OrderEntryValidators();
			
			//layouts should be refreshed when changing badge number, therefore we need to refresh everything else
			SetDefaultValues();
			RefreshCatalogImageLink();
			
			RefreshNote();
			RefreshPrice();
			BuildFlash();
			
			//show line help icons -> just for the first available line
			refreshQMarkLines();
			
		}
	else
		{
		//alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
}// end function RefreshLayout_Ready


function RefreshCatalogImageLink(){
	var h='';
	var strCheck=new Array(3);
	var obj=myGetElementById('txtBadgeNbr');
	
	strBadge=obj.value;
	
	strCheck[0] = "IMAGES/" + strBadge + ".jpg";
	strCheck[1] = "IMAGES/" + strBadge.toUpperCase() + ".jpg";
	strCheck[2] = "IMAGES/" + strBadge.toLowerCase() + ".jpg";
		
	if (strBadge=='') {
		h=''
	}else {

		for (var i=0;i<3;i++){
		  if (FileExists(strCheck[i])){
			h=strCheck[i];
			break;
		  }//end if fileexists

		}//end for

	}//end if

	
	if (h==''){
		ShowControls('linkSample',false);
	}else{
	  obj=myGetElementById('linkSample');
	  if (obj){
	  	  obj.href=h;
	      ShowControls('linkSample',true);
	     }
	}

	
} //end function RefreshCatalogImageLink

function BuildFlash(){

    UCaseAll();
    
	var mFont='sans';
	var mColor="black";
	var sBadgeStyle=GetBadge();
	var mBase=GetBase();
	var	obj=myGetElementById("ddlFont");
	if (obj!=null){
		mFont=obj[obj.selectedIndex].value.trim();
		mFont=(mFont=='ROMAN'?'roman':'block');
		}
	obj=myGetElementById('ddlColor');
	if (obj!=null){
		mColor=obj==null?'black':obj.value.trim().toLowerCase();
		}
	for (var i=1;i<=6;i++){
		obj=myGetElementById('txtLine' + i);
		eval('t'+i +'=obj==null? "": obj.value.trim()');
		}
	SealStr=GetSeal();
	//url="Badge.swf?badge=" + sBadgeStyle + "&base=" + mBase + "&textfont=" + mFont + "&textcolor=" + mColor + "&text1=" + urlencode(t1) + "&text2=" +urlencode(t2) + "&text3=" + urlencode(t3) + "&text4=" + urlencode(t4) + "&text5=" + urlencode(t5) + "&text6=" + urlencode(t6) + "&seal=" + SealStr + "&refresh=1&basePath=Flash/";

	obj = myGetElementById('ddlTextSep');
	if (obj != null) {
	    tsep = obj == null ? '' : obj.value.trim();
	}
	
    url="badge.aspx?badge=" + sBadgeStyle + "&base=" + mBase + "&textfont=" + mFont + "&textcolor=" + mColor + "&text1=" + urlencode(t1) + "&text2=" +urlencode(t2) + "&text3=" + urlencode(t3) + "&text4=" + urlencode(t4) + "&text5=" + urlencode(t5) + "&text6=" + urlencode(t6) + "&seal=" + SealStr + "&textsep=" + tsep ;
//    alert(url);
    setFlash(url);	
	
} //end func BuildFlash

function SetDefaultValues() {
 
	//default back: SHELL
	var obj=myGetElementById('ddlBack');
	if (obj.style.display!='none' && obj.value.trim()==''){
	 obj.value='SHELL';
	}

if ($("#nodefaults").val()=="1")
    return;

	
	//default enamel: SOFT (REGULAR)
	obj=myGetElementById('ddlLetterType');
	if (obj.style.display!='none' && obj.value.trim()==''){
	 obj.value='SOFT (REGULAR)';
	}
	
	//default letter color: BLACK
	obj=myGetElementById('ddlColor');
	if (obj.style.display!='none' && obj.value.trim()==''){
	 obj.value='BLACK';
	}
	
	//default font:BLOCK
	obj=myGetElementById('ddlFont');
	if (obj.style.display!='none' && obj.value.trim()==''){
	 obj.value='BLOCK';
	}
} //end func SetDefaultValues

function RefreshDefaultShape(){
	var url='OrderEntryRefresh.aspx?refresh=defshape';
	var obj=myGetElementById('ddlAttachment');
	url+= '&att=' + encodeURIComponent(obj.value.trim());
	obj = myGetElementById('txtBadgeNbr');
	url += '&b=' + encodeURIComponent(obj.value.trim());
	
	xmlhttp=null;
	wrapXMLHTTPRequest(url, 'RefreshDefaultShape_Ready');

} //end function RefreshDefaultShape

function RefreshDefaultShape_Ready(){
	if (xmlhttp.readyState==4)
		{// 4 = "loaded"
		if (xmlhttp.status==200)
			{// 200 = "OK"
			//alert(xmlhttp.responseText);
			var shape=xmlhttp.responseText.trim();
			obj=myGetElementById('ddlShape');
			obj.value=shape;
       }
	else
		{
		//alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
} //end func RefreshDefaultShape_Ready()


function debug(str){
return;
  var obj=myGetElementById('lblDebug');
  obj.innerHTML=str;
  
} //end func debug



function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}



function OrderEntryValidators(){

    //no validation on buildbadge page
    var obj=myGetElementById("NOVALIDATION");
    if (obj) {
        //nothing, terminate function
        return;
    }    
    
 	    frmvalidator = new Validator(document.forms[0].name);
 	    frmvalidator.clearAllValidations(); 
	    frmvalidator.EnableMsgsTogether();



 
 obj=myGetElementById("txtBadgeNbr");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("txtBadgeNbr","req","Please enter a Badge Number");
		}
	}
	
 obj=myGetElementById("txtQty");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("txtQty","req","Please enter the Quantity");
		frmvalidator.addValidation("txtQty","numeric","Please enter a valid Quantity");
		}
	}
 
 obj=myGetElementById("ddlBack");
  if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlBack","dontselect=0","Please select Badge Back");
		}
	}
 
 obj=myGetElementById("ddlFinish");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlFinish","dontselect=0","Please select Badge Finish");
		}
	}

	// no font validation when FB mode
	obj = myGetElementById("ddlFBStyles");
	if (obj == null) {
	    obj = myGetElementById("ddlFont");
	    if (obj != null) {

	        if (obj.style.display != 'none') {
	            frmvalidator.addValidation("ddlFont", "dontselect=0", "Please select Badge Font");
	        }
	    }
	}
	
obj=myGetElementById("ddlSealtype");
if (obj != null) {
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlSealType","dontselect=0","Please select Seal Type");
		}
	}
 
 obj=myGetElementById("ddlLetterType");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlLetterType","dontselect=0","Please select Enamel Type");
		}
	}
	
 obj=myGetElementById("ddlAttachment");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlAttachment","dontselect=0","Please select an Attachment");
		}
	}
	
 obj=myGetElementById("ddlShape");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlShape","dontselect=0","Please select Badge Shape");
		}
	}
	
 obj=myGetElementById("ddlColor");
 if (obj!=null){
	if (obj.style.display!='none'){
		frmvalidator.addValidation("ddlColor","dontselect=0","Please select Letter Color");
		}
	}
	
 for (var i=1;i<=6;i++){
	obj=myGetElementById("txtLine" + i);
	if (obj!=null){
		if (obj.style.display!='none'){
			frmvalidator.addValidation("txtLine" + i,"req","Please type  Line " + i + " or type '(leave blank)'");
			}
		}
 }

obj=myGetElementById("txtSpecialInstructions")
if (obj) 
	frmvalidator.addValidation("txtSpecialInstructions","maxlen=200","Maximum length of Special Instructions is 200 characters.");


frmvalidator.setAddnlValidationFunction("DoCustomValidation"); 

}


function setFlash(theSrc)
{
	var obj=myGetElementById("hidSWF");
    if (obj)  obj.value=theSrc;

  $("#imgBadgePreview").attr('src',theSrc)
     
    
}

function cancelClicked(){
var answ=confirm('Click OK to end this data entry and lose any recently entered data. Click Cancel to return to the screen with no loss of data.');

if (answ)
{
    if (frmvalidator){
        frmvalidator.setAddnlValidationFunction(""); 

	    frmvalidator.clearAllValidations();
	    return true;
	    }
	else{
	    return false;
	}
}else{
	return false;
}
}



function DefaultEnamelType(){
	var obj;
	obj=myGetElementById('ddlFinish');
	var myindex  = obj.selectedIndex;
	var sFinish = obj[myindex].value;
	var sType;
	switch (sFinish){
		case "COTE D'OR":
			sType = 'HARD';
			break;
		case 'GOL-RAY W/SIL-RAY PANELS':
			sType = 'HARD';
			break;
		case 'SIL-RAY W/GOL-RAY PANELS':
			sType = 'HARD';
			break;
		case 'SIL-RAY':
			sType = 'HARD';
			break;
		case 'GOL-RAY':
			sType = 'HARD';
			break;
		default:
			sType = 'SOFT (REGULAR)';
	}

	
	//default enamel
	obj=myGetElementById('ddlLetterType');
	if (obj.style.display!='none'){
	 obj.value=sType;
	}
}


function UCaseAll()
{
// CSS text-transform changes only the display, not the actual characters...
var uCaseObj=new Array("txtBadgeNbr","txtLine1","txtLine2","txtLine3","txtLine4","txtLine5","txtLine6");
var obj;
for (i=0;i<uCaseObj.length;i++){
    obj=myGetElementById(uCaseObj[i]);
    if (obj) obj.value=obj.value.toUpperCase();
}

}


function RefreshNote() {
    var div = myGetElementById("divFactoryNotes");
    if (!div) {
        return;
    }

    $('#divFactoryNotes').empty();
    $('#divFactoryNotes').css("visibility","hidden");
    
    var pageUrl = "OrderEntryRefresh.aspx?refresh=bnote";
    var obj=myGetElementById('txtBadgeNbr');
	pageUrl+= '&b=' + obj.value;

	$.ajax(
    {
        url: pageUrl,
        cache: false,
        success: function(message) {            
            if (message != "") {
                $('#divFactoryNotes').append("Factory Notes:<br />" + message);
                $('#divFactoryNotes').css("visibility", "visible");
            }

        }
    });

}


function RefreshLeatherPic(){
var obj1=myGetElementById('spanLeatherPic');
if (obj1) obj1.innerHTML="";

var obj=myGetElementById('ddlLeather');
if (obj) {
    var myindex  = obj.selectedIndex;
	var sLeather = obj[myindex].value;
    if (FileExists("./PNG/" + sLeather + ".png")){
        obj1.innerHTML="<img src=\"w3ShowImage.aspx?img=" + sLeather + ".png&f=PNG/&h=100&maxw=100\" alt=\"\">";
        }
    }

    var qty;
    obj = myGetElementById("txtQtyL");
    if (obj) {
        qty = Number(obj.value);
        // default qty to 1
        if ((qty == 0) && (sLeather != "")) {
            obj.value = 1;
        }
        if (sLeather == "")
            obj.value = 0;
    }
}


function DoCustomValidation()
{
    //they must select a leather item if they select GLUE IN attachment
  var obj=myGetElementById("ddlAttachment");
  if (obj){
    var myindex  = obj.selectedIndex;
	var sAtt = obj[myindex].value;
	
	if (sAtt=='GLUE IN LEATHER'){
	    obj=myGetElementById("ddlLeather");
	    myindex  = obj.selectedIndex;
	    var sLea = obj[myindex].value;
	    //alert(sLea);
	    if (sLea==''){
	        alert("You selected GLUE IN LEATHER option, please select the LEATHER ACCESSORY model number");
	        return false;
	    }
	}
  }

  //they must type a qty if they selected a leather item
  obj = myGetElementById("ddlLeather");
  if (obj) {
      myindex = obj.selectedIndex;
      var s = obj[myindex].value;

      if (s != '') {
          obj = myGetElementById("txtQtyL");
          if (obj) {
              if (obj.value == "0" || obj.value == "") {
                  alert("Please type the quantity for LEATHER ACCESSORY");
                  return false;
              }
          }
      }

  }

  //if seal is selected, seal type is mandatory
  obj = myGetElementById("txtCenter");
  if (obj) {
      if (obj.value!="") {
          obj = myGetElementById("ddlSealType");
          if (obj.selectedIndex == 0) {
              alert("Please select the seal type");
              return false;
          }
      }
  }

  var ret = true;

  // for NP + PIN as attachment -> show a warning message
  var obj = myGetElementById('txtBadgeNbr');
  var b = obj.value;
  obj = myGetElementById("ddlAttachment");
  att = obj[obj.selectedIndex].value;

  var sURL = "DealerAjax.aspx?r=NPCheck&b=" + urlencode(b) + "&att=" + urlencode(att);
  $.ajax({
        async: false,
        type: 'GET',
        url: sURL,
        success: function(data) {
        //callback
        if (data!="") {
            ret= confirm("Nameplates are usually produced FLAT with CLUTCH backs. Are you sure you want to select " + att + " as attachment?");
        };
    } });

    
    return ret;
}



function disableSelectOption(selectId, optionValue, disable) {
    obj = myGetElementById(selectId);
    if (obj) {
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].value == optionValue) {
                if (disable) {
                    obj[i].setAttribute("disabled", "true");
                } else {
                    obj[i].removeAttribute("disabled");
                }
            }
        }

    }
}

function selectOption(selectId, optionValue) {
    obj = myGetElementById(selectId);
    if (obj) {
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].value == optionValue) {
                obj.selectedIndex = i;
            }
        }

    }
}


function refreshQMarkLines() {
    var bFound = false;
    for (var i = 1; i < 7; i++) {
        obj1 = myGetElementById("qMarkLine" + i);
        obj2 = myGetElementById("divLine" + i);
        if ((obj1 != null) && (obj2 != null)) {
            if (obj2.style.display == "") {
                obj1.style.display = (bFound ? "none" : "");
                if (!(bFound))
                    bFound = true;
            }
        } //end if obj!=null
    } //end for
}

function leaveBlank(chk,index) {
    var obj = myGetElementById("txtLine" + index);
    var LV_BLANK = "(LV.BLANK)";
    if (obj) {
        if (chk.checked==true) {
            obj.value = LV_BLANK;
        } else {
        if (obj.value == LV_BLANK)
            obj.value = "";
        }
    }
}
function adjustSealType() {

    if (opener) {
        var obj = myGetElementById('ddlSealType', opener);
    } else {
        var obj = myGetElementById('ddlSealType', window);
    }
    if (obj == null) {
        return false;
    }
    var crtSealT = obj.value;
        
    
    
    var seal = myGetElementById("txtCenter");
    if (!seal)  
        return false;
    var center = seal.value.toUpperCase();

    var sealType = "";

    if ((center.length>3) && (Right(center, 2) == 'AP') || (Right(center, 2) == 'AB')) {
        sealType = Right(center, 2);
    }
    
    if ((sealType=="") && ((Right(center, 1) == 'P') || (Right(center, 1) == 'E') || (Right(center, 1) == 'M'))) {
        sealType = Right(center, 1);
    }

    
    if (crtSealT != sealType) {
        obj.value = GetSealTypeById(sealType);
        
        RefreshPrice();
    }

}

function copyFBStyleToTxt() {
    var obj = myGetElementById('ddlFBStyles');
    if ((obj) && (obj.selectedIndex)) {
        b = obj[obj.selectedIndex].value.trim();
        obj = myGetElementById("txtBadgeNbr");
        obj.value = b.toUpperCase();
    }
}
function ChangeLeatherQty() {
    
    obj = myGetElementById("txtQtyL");
    if (obj) {
        cQ = obj.value;
        if (cQ == 0) {
            obj = myGetElementById("ddlLeather");
            if (obj) {
                obj.selectedIndex = 0;
            }
           
        }
    }
    RefreshLeatherPic();
    RefreshTotalPrice();
}


function SearchLeatherNew(aff) {
    var url = "Leather.aspx?vb=1";
    if (aff) {
        url = url + "&aff=" + aff;
    }

    var obj = myGetElementById("txtBadgeNbr");
    if (obj && obj.value!="") {
        url += "&b=" + obj.value;
    }
    window.open(url, "SearchLeather", "height=770,width=800,status=1,scrollbars=yes");
}  // end func SearchLeatherNew
