﻿/*
What it does:  This file is intended to be used for those wizards where Numbering2 flag
               is set to true. It is conditionally included on the wizard page.
               This file will help us keep minimum functions within the wizard.asp page.

Referred by : wizarda.asp
*/

//Numbering2 Specific function starts
xnumber=0
function GetNumbering(ystnum, yprefix, ysuffix, yminlen, ypadtype, ybarcode, ybarcodefonts, ynochk) {
	var xchkdigit, k;
	xtextnumber = ystnum 
	xnetlen = parseInt(yminlen) 
	if (xtextnumber.length > xnetlen ) {
		xtextnumber = xtextnumber.substring(0, 4)
	}
	
	xtmpstr = ""
	for(k=1;k<=(xnetlen-xtextnumber.length);k++) {
		if (ypadtype == 1) xtmpstr = xtmpstr + "0";
		else  xtmpstr = xtmpstr + ""; 
	}
	if (yprefix.length  + ysuffix.length > 5) {
		xtextnumber = yprefix + xtmpstr + xtextnumber   
	}
	else {
		xtextnumber = yprefix + xtmpstr + xtextnumber + ysuffix
	}

	if (ybarcode) {
		if (ybarcodefonts.indexOf("39") >= 0) {
			if (!ynochk) {
				xchkdigit = generateCheckDigit(xtextnumber)
				xtextnumber = "*" + xtextnumber + xchkdigit + "*"
			}
			else {
				xtextnumber = "*" + xtextnumber + "*"
			}
		}
		else {
			xtextnumber = "*" + xtextnumber + "*"
		}
	}
	return xtextnumber;
}

function ShowHideNumEntry(yindex) {
    FlashShowHideNumEntry(yindex)
}

function ChangeNumbering(objnum, yprefix_suffix) {
	var tmpfont=null
	okflag = true;
	if (objnum <= 0) return;
	if (isNaN(currobj["ffstartnumber"].value) || parseInt(currobj["ffstartnumber"].value) < 0) {
		alert("Improper Start Number value !")	
		okflag = false;
	}
	if (!okflag) return;
	
	if (currobj.ffstartnumber.value.length > currobj.ffminlength.value) {
		currobj.ffminlength.value = currobj.ffstartnumber.value.length
	}
	
	if (currobj.ffprefix.value.length > 0) {
		currobj.ffsuffix.maxLength = 0
	}
	else {
		currobj.ffsuffix.maxLength = 5
	}

	if (currobj.ffsuffix.value.length > 0) {
		currobj.ffprefix.maxLength = 0
	}
	else {
		currobj.ffprefix.maxLength = 5
	}

	if (yprefix_suffix) {
		if (yprefix_suffix == "Prefix") {
			if (currobj.ffprefix.maxLength == 0) {
				alert('You can either specify "Prefix" or "Suffix" but not both.\nYou can enter a maximum of 5 characters for either "Prefix" or "Suffix".')
			}
		}
		else if (yprefix_suffix == "Suffix") {
			if (currobj.ffsuffix.maxLength == 0) {
				alert('You can either specify "Prefix" or "Suffix" but not both.\nYou can enter a maximum of 5 characters for either "Prefix" or "Suffix".')
			}
		}
	}
	
	xbctype = false

	xbarcodefonts= div_font[objnum] 
	
	xminlength = currobj.ffminlength.value
	xpadtype = currobj.ffpadtype.checked
	xstartnumber = currobj["ffstartnumber"].value
	xprefix = currobj["ffprefix"].value
	xsuffix = currobj["ffsuffix"].value
	xnochk = true
	xhuman = true

	if (currobj.numbering_font){
		xbarcodefonts=currobj.numbering_font.options[currobj.numbering_font.selectedIndex].value
	}

	tmpfont=xbarcodefonts
	if (xbctype) {
		if (xbarcodefonts.indexOf("39") >=0 ) {
			xprefix = currobj["ffprefix"].value.toUpperCase()
			xsuffix = currobj["ffsuffix"].value.toUpperCase()
		}
	} else {
		tmpfont="Code39OneText"
	}
	
	xincrdecr = true
	xincrdecrby = 1
	xtimes = 1
	xangle = 1
	xprompt = "ENTER NUMBER HERE"
	xtext = GetNumbering(xstartnumber, xprefix, xsuffix, xminlength, xpadtype, xbctype, xbarcodefonts, xnochk);

	if (xbarcodefonts.substring(0, 4).toUpperCase()!='CODE') {
		xtext = xtext.split("*").join("")
	}
	
	//vaibhav 210809
	
	//when we hide and then reshow numbering, it was displaying blank
    //	if (currobj.ffnonumber.checked) {
    //		xtext = ""
    //	}
		
	div_text[objnum] = xtext
	if (currobj.NUMBERING){
		currobj.NUMBERING.value=xtext
	}
	div_prompt[objnum] = xprompt
	div_font[objnum] = xbarcodefonts
	
	var yindex
	yindex=getobjectno('HRNUMBER')
	if (yindex!=-1){
		changeText(xtext, yindex)
	}

    Flash_Change_Numbering(xtext)

}

function ValidateNumbering(yval, yindex) {
	yval = document.preview.ffminlength.value
	if (parseInt(yval) > 5) {
		alert('The maximum number of digits can be 5 for Starting #.')
		document.preview.ffminlength.value = '5'
	}

	if (currobj.ffstartnumber.value.length > currobj.ffminlength.value) {
		currobj.ffminlength.value = currobj.ffstartnumber.value.length
	}
	
	if (parseInt(yval) < 1) {
		document.preview.ffminlength.value = '1'
	}
	ChangeNumbering(yindex)
}

function showHideLayers(divname,vis) {
// example: showHideLayers('divname')
	xobj = document.all[divname].style;
	if (vis=='show') {
		xobj.visibility='visible';
		xobj.display='block';
	} else if (vis=='hide') {
		xobj.visibility='hidden';
		xobj.display='none';
	} else {
		if (xobj.visibility=='visible') {
			xobj.visibility='hidden';
			xobj.display='none';
		}
		else {
			xobj.visibility='visible';
			xobj.display='block';
		}
	}
}

//Numbering2 Specific function ends
