﻿// JScript File

/*
What it does : This file is intended to be used for those wizards where Logo / Graphic is to be placed on templates.
				For eg. id badges, business cards etc.
			   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, wizardy.asp
*/

/*
This section of functions are related to Graphic Section
*/
function showClipartWin(){
	var xurl;
	if (flag_Graphic_NewLibrary) {
		xurl='Clipart.asp'
		xwidth=565;
		xheight=525;	
	}
	else {
		xurl='getClipart.asp'
		xwidth=440;
		xheight=400;	
	}
	xleft = (screen.width - xwidth) / 2
	xtop = (screen.height - xheight) / 2
	xurl=xurl + '?DefaultClip='+flag_Graphic_DefaultClip + '&Themes2Show='+flag_Graphic_Themes2Show + '&WizardFlags_AutoID='+WizardFlags_AutoID
	xurl = xurl + '&compname='+currobj.CompName.value+'&subcatgid='+currobj.SubCatgId.value
	winhandle = window.open(xurl, 'hidden', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+', location=no, resizable=yes, scrollbars=no')
}

function showCustomLogoWin(){
	var tcompname = "";
	if (document.preview.CompName) {
		tcompname = document.preview.CompName.value
	}
	winhandle = window.open('getCustomLogo.asp?compname='+tcompname+'&RasterOnly=1', 'hidden', CenterThisWindow(440, 600) +', location=no, resizable=yes, scrollbars=yes')
}

function showCustomLogoWinSteps(){
	var tindex, tdh, tdw;
	tdh = 0;
	tdw = 0;
	tindex=-1;
	if (flag_GraphicField) {
		if (flag_GraphicField.length > 0) {
			tindex = getobjectno(flag_GraphicField)
			tdh = (2 * div_h[tindex]) / (xzoomper * 96)
			tdw = (2 * div_w[tindex]) / (xzoomper * 96)
		}
	}
	
	// Step upload process discontinued since it has has not been integrated in the artwork creation process -- RJ
	//if (flag_Graphic_ColorConv) {
		showCustomLogoWin()
	//}
	//else {
	//	winhandle_steps = window.open('/xp5/xp5_upload_artwork_step1.asp?index='+tindex+'&designHeight='+tdh+'&designWidth='+tdw+'&SpotColors='+flag_Graphic_Spot_Colors+'&ColorConv='+flag_Graphic_ColorConv, 'steps', CenterThisWindow(400,430) +', location=no, resizable=yes, scrollbars=no')
	//}
}

function CenterThisWindow(xwidth, xheight, xpercent){
	if (xpercent) {
		xwidth = screen.width * xpercent * 0.01
		xheight = screen.height * xpercent * 0.01
	}
	var xleft = (screen.width - xwidth) / 2;
	var xtop = (screen.height - xheight) / 2;
	return 'left='+xleft+', top='+xtop+', width='+xwidth+', height='+xheight;
}

function DeleteLogo() {
    FlashDeleteLogo()
}

function placelogo_template(yindex, secondparam, xname, lastparam){
var hindex, oshacaution, logouploaded, grayscale

	//alert("placelogo_template")
	if (flag_Graphic_ColorConv==true){
//		alert("placelogo_template1")
		if (currobj.signtype){
//			alert("placelogo_template2")
			hindex=getobjectno("headerimg")
			if (hindex!=-1) {
				if (div_text[hindex].toUpperCase().indexOf('OSHA-CAUTION-RADIATION')>=0){
					oshacaution=true
				}
			}

			if (currobj.signtype.value == 'OSHA' && oshacaution){
				grayscale=true	//When placing logo for the firsttime then set it to true
				convert_logo_color(yindex, xname, lastparam, grayscale)
			}else if (currobj.SubCatgId.value=='OSHA' && lastparam==1 || currobj.SubCatgId.value=='ANSI' && lastparam==1 || currobj.SubCatgId.value=='SAFETYFLOORSTAND' && lastparam==1 || currobj.SubCatgId.value=='FACILITY' && lastparam==1 || currobj.SubCatgId.value=='FACILITYLABEL' && lastparam==1 || currobj.SubCatgId.value=='PARKING_CUSTOM' || currobj.SubCatgId.value=='PARKING_CUSTOM2'){	//only uploaded logo will be color converted
				grayscale=true	//When placing logo for the firsttime then set it to true
				convert_logo_color(yindex, xname, lastparam, grayscale)
			}else if (currobj.catgid.value == '520'){
				if (currobj.templateXML.value.substring(0,2)=="S0" || currobj.templateXML.value.substring(0,3)=="SV0" && ssColors.length>0){
					grayscale=true	//When placing logo for the firsttime then set it to true
					convert_logo_color(yindex, xname, lastparam, grayscale)
				}else{
					changeLibSymbol(xname)
				}
			}else{
				changeLibSymbol(xname)
			}

		} else {
//			alert("placelogo_template...A1")
			if (currobj.MultiColorDesign.value){
//				alert("placelogo_template...A2")
				changeImage(yindex, secondparam, xname, xname, lastparam);
			}else{
//				alert("placelogo_template...A3")
				grayscale=true	//When placing logo for the firsttime then set it to true
				convert_logo_color(yindex, xname, lastparam, grayscale)

			}
		}
	}else{
//		alert("placelogo_template...B1")
		var tflag = false;
		if (document.preview.cbLogoTrans) {
//			alert("placelogo_template...B2")
			if (document.preview.cbLogoTrans.checked) {
//				alert("placelogo_template...B3")
				tflag = true;
				grayscale=false	    
				convert_logo_color(yindex, xname, lastparam, grayscale)
			}
		}
//		alert("placelogo_template...B4")
		if (!tflag) {
//			alert("placelogo_template...B5")
			changeImage(yindex, secondparam, xname, xname, lastparam);
		}
	}
//	alert("placelogo_template...C1")
	ChangeLogoImageName(xname)
//	alert("placelogo_template...C2")
}

function ChangeLogoImageName(ytext) {
	if (document.preview.LogoImageName) {
		document.preview.LogoImageName.value = ytext
	}
}

function AfterConvertLogo() {
	//Special treatment for logos for Quill's 2 color wizards such as business cards,
	//envelopes etc.
	if (Color_SchemeID.toUpperCase().indexOf('2COLOR') >= 0) {
		ChangeColor2(document.preview.hcolorno2.value, 2)
	}
}

function convert_logo_color(yindex, xname, lastparam, grayscale, ychangecolor){
  var urlstr
  var changecolorno
	
	changecolorno="3"
	
    //Vj - In case of Image object deleted
    if (typeof(xname) == "undefined") {
        return;
    }

	if (currobj.catgid.value==115){
		changecolorno=xlogocolorno;
	}

	if (flag_Graphic_ColorConv==false){
		return
	}
	
	if (xname.toLowerCase().indexOf('null.gif')>=0 || xname.toLowerCase().indexOf('logo/null_')>=0){
		return
	}
	if (xname.toLowerCase().indexOf('addimage.gif')>=0 || xname.toLowerCase().indexOf('logo/addimage_')>=0){
		return
	}
	if (xname.toLowerCase().indexOf('asset-tag-logo')>=0){	//exclude seeded logo
		return
	}
	if (xname.toLowerCase().indexOf('asset-tag-logo')>=0){	//exclude seeded logo
		return
	}
	
	GenAppendString()
	if (ychangecolor) {
		xchangecolor=ychangecolor
	}
	else {
		if (currobj.catgid.value==117 || currobj.catgid.value==115){
			//hcolorno3 changed to ["hcolorno"+changecolorno]
			if (currobj["hcolorno"+changecolorno].value.toUpperCase() == 'FFFFFF') { 
				currobj["hcolorno"+changecolorno].value = 'FFFFFE'; 
			}
			xchangecolor=currobj["hcolorno"+changecolorno].value
			
			//alert(grayscale +'\n'+xtranscolor +'\n'+xchangecolor)

		}else if (currobj.catgid.value==77){	//Parking Permit
			if (document.preview.LogoColorFlag) {
				if (document.preview.LogoColorFlag.value.toUpperCase() == 'C') {
					currobj.hcolorno2.value=currobj.hcolorno2.value.split('#').join('')
					if (currobj.hcolorno2.value.toUpperCase() == 'FFFFFF') { 
						xchangecolor='FFFFFE'
					}else{
						xchangecolor=currobj.hcolorno2.value
					}
				}else{
					currobj.hcolorno0.value=currobj.hcolorno0.value.split('#').join('')
					if (currobj.hcolorno0.value.toUpperCase() == 'FFFFFF') { 
						xchangecolor='FFFFFE'
					}else{
						xchangecolor=currobj.hcolorno0.value
					}
				}
			}
		}else{
			if (currobj["hcolorno" + xlogocolorno].value.toUpperCase() == 'FFFFFF') { currobj["hcolorno" + xlogocolorno].value = 'FFFFFE'; }
			xchangecolor=currobj["hcolorno" + xlogocolorno].value
		}
		
		if (xchangecolor.toUpperCase()=='FFFFFF'){
			if (currobj.catgid.value==117 || currobj.catgid.value==115){
				xtranscolor=currobj.hcolorno3.value
				xchangecolor=currobj.hcolorno2.value
//alert(xtranscolor +'\n'+xchangecolor)
			}else if (currobj.catgid.value==77){	//Parking Permit

			}else{
				xtranscolor=currobj.hcolorno1.value
				xchangecolor=currobj.hcolorno2.value
			}
		}
	}

	div_transcolor[yindex] = '#' + xtranscolor
	if (document.preview.cbLogoTrans) {
		if (!document.preview.cbLogoTrans.checked) {
			div_transcolor[yindex] = ""
		}
	}

	//Special treatment for logos for Quill's 2 color wizards such as business cards,
	//envelopes etc.
	if (Color_SchemeID.toUpperCase().indexOf('2COLOR') >= 0) {
		var xrectexist = false;
		for (var n=1; n<num_divs; n++) {
			if (div_contents[n]){
				if (div_contents[n].toLowerCase().indexOf('rectangle') >= 0 ){
					xrectexist = true;
				}
			}
		}
		if (xrectexist) {
			xchangecolor = document.preview.hcolorno1.value  //color1 being black
		}else {
			xchangecolor = document.preview.hcolorno2.value
		}
	}

	div_imagecolor[yindex] = '#' + xchangecolor

	var xlogotrans = "0"
	if (document.preview.cbLogoTrans) {
		if (document.preview.cbLogoTrans.checked) {
			xlogotrans = "1"  
		}
	}

	if (grayscale) {
		grayscale=true
	}else {
		grayscale=false
	}

	if (currobj.catgid.value == 514){
		yindexA=getobjectno('company')
		xchangecolor=currobj["hcolorno"+div_color[yindexA]].value
		if (currobj["hcolorno" + div_color[yindexA]].value.toUpperCase() == 'FFFFFF') { currobj["hcolorno" + div_color[yindexA]].value = 'FFFFFE'; }
		xchangecolor=currobj["hcolorno"+div_color[yindexA]].value
	}
	if (currobj.catgid.value == 12){
		yindexA=getobjectno('textline1')
		xchangecolor=currobj["hcolorno"+div_color[yindexA]].value
		if (currobj["hcolorno" + div_color[yindexA]].value.toUpperCase() == 'FFFFFF') { currobj["hcolorno" + div_color[yindexA]].value = 'FFFFFE'; }
		xchangecolor=currobj["hcolorno"+div_color[yindexA]].value
	}
	urlstr = '/xp5/ConvertLogo.asp?parsheet=&imagenum='+yindex + '&logo=1&fname='+xname+'&transcolor='+ div_transcolor[yindex].split('#').join('')
	urlstr = urlstr +'&changecolor='+xchangecolor + '&appendstr='+xappendstr+'&grayscale='+grayscale + '&upload='+lastparam+'&logotrans='+xlogotrans
	//102307xwin1 = window.open(urlstr, "win1", "width=500,height=400,left=3000, top=6000")
	//102307IsPopupBlocker(xwin1)
	//alert(urlstr)
	
	var resptext=CallPage(urlstr + '&xmlhttp=1')
	
	applyConvertedLogo(resptext)

	if (currobj.catgid.value.toLowerCase()==12 && currobj.SubCatgId.value.toLowerCase()=='visitorpass'){
		yindex=getobjectno('textline1')		//companyname
		if (yindex != -1){
			div_hidden[yindex] = true;
			FlashShowHideObject(yindex);
			changeText(div_text[yindex], yindex)
		}
		yindex=getobjectno('LOGOIMAGE')		//LOGO
		if (yindex != -1){
            //show flash object code here
            div_hidden[yindex]=false
            FlashShowHideObject(yindex);
		}
	}
}

var popUpsBlocked=false
function IsPopupBlocker(wintest){
 
	if(wintest==null || typeof(wintest)=="undefined"){
		popUpsBlocked = true
	}else{
		popUpsBlocked = false
	}
	if(popUpsBlocked){
		alert('We have detected that you are using popup blocking software.\nPlease disable the POP-UP BLOCKER and try again\nor\nPlease contact your system administrator. ');
	}
	return popUpsBlocked
}


//The changeimage function always call following function after placing image on the
//template
function userdefinedafterchange(yindex){
	if (div_fields[yindex].toLowerCase()=='hdrspanish' ||div_fields[yindex].toLowerCase()=='headerimg'){
		//do nothing for headers
	}else{	
		if (flag_Textreduction_logo_insert==true) {
			//Make visible to the previously hidden logo
			div_hidden[yindex]=false

			adjustTextsizes(yindex, '-')
			
			if (currobj.SubCatgId.value=='GRAPHICAREA'){	//For Graphic area signs set valign=bottom after logo is selected
				if (currobj.areaSignBorder){
					if (currobj.areaSignBorder.value=='1'){
						VAlignAll(1,'')
						backgroundimage = backgroundimage.toLowerCase().split('_b.gif').join('.gif');
						
                        if (backgroundimage.substring(0,5).toLowerCase() == '/xp2/' || backgroundimage.substring(0,5).toLowerCase() == '\\xp2\\'){
                            //
                        }
                        else {
                            backgroundimage = '/xp2/clipart/' + backgroundimage	
                        }
                        Flash_Update_BackImage(backgroundimage)
                        
					}
				}
			}
		}
		if (currobj.signtype){
 			if (currobj.SubCatgId.value=='PARKING_CUSTOM' || currobj.SubCatgId.value=='PARKING_CUSTOM2'){
			} else if (currobj.signtype.value.toUpperCase() != 'OSHA' || currobj.signtype.value.toUpperCase() != 'ANSI' || currobj.signtype.value.toUpperCase() != 'FACILITY' || currobj.signtype.value.toUpperCase() != 'FACILITYLABEL' || currobj.signtype.value.toUpperCase() != 'PROJ'){
				yesSymbol(yindex)
			}
		}
	}
}

xcounter = 0
xappendstr = "0000"
function GenAppendString() {
	xcounter++;
	if (xcounter < 10) xappendstr = "000" + xcounter;
	else if (xcounter < 100) xappendstr = "00" + xcounter;
	else if (xcounter < 1000) xappendstr = "0" + xcounter;
	else if (xcounter < 10000) xappendstr = "" + xcounter;
}

//======Text reduction controlled by the flag flag_Textreduction_logo_insert=======

var oplusminus='+'
var plusminus='+'

function adjustTextsizes(yindex, plusminus){
	var xindex

	//don't apply text resizing rules on the materials page
	if (document.preview.MaterialPage){	
		return;
	}

	if (oplusminus==plusminus){ return }
	xindex=getobjectno("group1")
	if (xindex==-1) {
		xindex=getobjectno("group")
	}

	if (xindex!=-1) {

 		if ( (currobj.catgid.value==78 && currobj.SubCatgId.value.toLowerCase()=='mailing') || (currobj.catgid.value==512 && currobj.SubCatgId.value.toUpperCase()=='ADDRESSSTANDARD') ){

			if (plusminus=='-'){	//set group X = backW-logow and W = W-logoW
				div_x[xindex]=parseFloat(div_x[xindex]) + parseFloat(div_w[yindex])*2
				div_w[xindex]=parseFloat(div_w[xindex])-parseFloat(div_w[yindex])-3	//leave some gap between text and symbol
			} else {
				div_x[xindex]=parseFloat(div_x[xindex]) - parseFloat(div_w[yindex])*2
				div_w[xindex]=parseFloat(div_w[xindex])+parseFloat(div_w[yindex])+3
			}
			oplusminus=plusminus
			changeDivLocation(xindex)
			changeDivSize(xindex)
			moveobject(xindex, 0, 0)

 		} else if ( currobj.catgid.value==9 && (currobj.SubCatgId.value.toUpperCase()=='CORRIDOR' || currobj.SubCatgId.value.toUpperCase()=='CORRIDOR2')){

			if (plusminus=='-'){	//set group X = backW-logow and W = W-logoW
				div_w[xindex]=parseFloat(div_w[xindex])-parseFloat(div_w[yindex])-3	//leave some gap between text and symbol
			} else {
				div_w[xindex]=parseFloat(div_w[xindex])+parseFloat(div_w[yindex])+3
			}
			oplusminus=plusminus
			changeDivLocation(xindex)
			changeDivSize(xindex)
			moveobject(xindex, 0, 0)

		}else if (currobj.textReductiondir.value=='top' || currobj.signtype.value=='MULTICOLORLABEL' || currobj.signtype.value=='FACILITY' || currobj.signtype.value=='FACILITYLABEL' || currobj.signtype.value=='FACILITYFLOORSTAND' || currobj.signtype.value=='PROJH' || currobj.signtype.value=='SAFETYFLOORSTAND'){
			if (plusminus=='-'){	//set group X = backW-logow and h = h-logoh
				div_y[xindex]=div_y[xindex] + div_h[yindex]*2
				div_h[xindex]=parseFloat(div_h[xindex])-parseFloat(div_h[yindex])
			} else {
				div_y[xindex]= parseFloat(div_y[xindex])-parseFloat(div_h[yindex]*2)
				div_h[xindex]=parseFloat(div_h[xindex])+parseFloat(div_h[yindex])
			}
			oplusminus=plusminus
			changeDivLocation(xindex)
			changeDivSize(xindex)
			moveobject(xindex, 0, 0)

 		}else if (currobj.SubCatgId.value=='PARKING_CUSTOM' || currobj.SubCatgId.value=='PARKING_CUSTOM2'){
			if (plusminus=='-'){
				div_y[xindex]=div_y[xindex]+ div_h[yindex]*2
				div_h[xindex]=parseFloat(div_h[xindex])-parseFloat(div_h[yindex])
			} else {
				div_y[xindex]= parseFloat(div_y[xindex])-parseFloat(div_h[yindex]*2)
				div_h[xindex]=parseFloat(div_h[xindex])+parseFloat(div_h[yindex])
			}
			oplusminus=plusminus
			changeDivLocation(xindex)
			changeDivSize(xindex)
			moveobject(xindex, 0, 0)
 		
		}else if (currobj.signtype.value=='OSHA' || (currobj.signtype.value=='ANSI') || currobj.textReductiondir.value=='right'){
		    //change this to check subcatgid
		    //textReductiondir for graphic signs
			if (plusminus=='-'){
				//set group X = backW-logow and W = W-logoW
				div_w[xindex]=parseFloat(div_w[xindex])-parseFloat(div_w[yindex])-3
					//leave some gap between text and symbol
			} else {
				div_w[xindex]=parseFloat(div_w[xindex])+parseFloat(div_w[yindex])+3
			}
			oplusminus=plusminus
			changeDivLocation(xindex)
			changeDivSize(xindex)
			moveobject(xindex, 0, 0)
		}
	}
}

/* Graphic Section Ends */

function resizeobject(x, y) {
	yindex=getobjectno(flag_GraphicField)
	if (yindex == -1){
		return
	}
	currobjnum=yindex
	FlashResizeImage(x, y)
}

function AssignLogoColor(ynum) {
	var yindex=getobjectno(flag_GraphicField)
	if (yindex <= 0) {
		return;
	}
	ycolor = document.preview["hcolorno" + ynum].value
	if (ycolor.indexOf("FFFFFF") < 0) {
		//after the logo is placed once, then gray scale should be set to false.
		var tgrayscale = false
		convert_logo_color(yindex, div_text[yindex], "0", tgrayscale, ycolor.split('#').join(''))
	}
}

function showGraphicGallery(){
	var xwidth = 780;
	var xheight = 600;
	var xleft = (screen.width - xwidth) / 2;
	var xtop = (screen.height - xheight) / 2;
	xurl = 'Gallery.asp?Graphictype=Logo'
	winhandle = window.open(xurl, 'logogallery', CenterThisWindow(xwidth, xheight) + ', location=no, resizable=yes, scrollbars=yes')
}