//all javascripts that are SITE SPECIFIC, and probably cannot be reused in other site, go in this file

//alert('site.js up');

function addMainCluster(){
	//alert('in addCCImodule');
	//document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="487" height="522" title="fmc">');
   //document.write('<param name="movie" value="images/fmc_home.swf"> <param name="quality" value="high">');
    //document.write('<embed src="images/fmc_home.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="487" height="522"></EMBED></OBJECT>');
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="487" height="522" title="fmc">');
    document.write('<param name="movie" value="images/fmc_home.swf" /> <param name="quality" value="high" />');
	//alert('<param name=FlashVars value="topicID='+topicID+'&topicTxt='+topicTxt+'" />');
	document.write('<param name=FlashVars value="topicID='+topicID+'&topicTxt='+topicTxt+'" />');
    document.write('<embed src="images/fmc_home.swf" FlashVars="topicID='+topicID+'&topicTxt='+topicTxt+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="487" height="522"></EMBED></OBJECT>');
}

function addMasthead(){
	//alert('in addCCImodule');
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="635" height="119"> ');
    document.write('<param name="movie" value="/images/fmc_masthead.swf" /> <param name="quality" value="high" />');
    document.write('<embed src="/images/fmc_masthead.swf" quality="high" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="635" height="119"></EMBED></OBJECT>');
}

function runSearch(){
	searchObj=findObjectPath("searchTxt");
	txt=searchObj.value;
	if(txt==""){
		alert("Please enter search text");
	}else{
		window.location="search-results.php?txt="+txt;
	}
}

function showTopic(goPage){
	//alert('showCity');
	/*if(goPage==null){
		//if parameters are void, assume this call is coming from the dropdown list
		goPage=window.document.cityLocate.citySelect.options[window.document.cityLocate.citySelect.selectedIndex].value;
	}*/
	if(goPage!='none' && goPage!=null){window.location=goPage;}
}

function listTopics(letter){
	//alert('listCities');
	//close all but the current city div
	allLetters=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','ALL');
	//allLetters=new Array('A','B');
	for(curLoc in allLetters){
		curLetter=allLetters[curLoc];
		divObj=findObjectPath("div_"+curLetter);
		if(curLetter==letter){
			//alert('found letter match');
			divObj.style.display='block';
		}else{
			if(divObj!=null && divObj.style.display!='none'){divObj.style.display='none';}
		}
	}
	fixIEBug();
}

function goSelectPage(selectList){
	//alert('in goSelectPage');
	menuObj=findObjectPath(selectList);
	goPage=menuObj.options[menuObj.selectedIndex].value;
	if(goPage!="none"){window.location=goPage;}
	fixIEBug();
}
	

//FMC FUNCTIONS
function ckBoxDivToggle(formID,ckID){
	//alert('checkboxDivToggle');
	//alert(radioID);
	ckBox=document.forms[formID][ckID];
	//alert(ckBox.checked);
	switch(ckBox.checked){
		case true:
			//alert("curState=1");
			toggleFolder(ckID+'_div','block');
			break;
		
		case false:
			//alert("curState=0");
			toggleFolder(ckID+'_div','none');
			break;
	}
}


function toggleFolder(objID,folderState){
	//alert("in toggleFolder");
	tg=findObjectPath(objID);
	if(tg!=null){
		//alert(tg.style.display);
		tg.style.display=folderState;
		//Defeat IE6 fixed bug by opening and closing the last div
		x = document.getElementById('defeatIEBug');
		currentStyle = x.style.display;
		newStyle = (currentStyle == 'none') ? 'block' : 'none';
		x.style.display = newStyle;
		x.style.display = currentStyle;
	}
	fixIEBug();
}



//CCI TRAINING FUNCTIONS

function addCCImodule(){
	//alert('in addCCImodule');
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
	document.write('width="740" height="460" id="module" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="/cci/mods/'+swFile+'.swf?rand='+randNum+'" />');
	document.write('<param name=FlashVars value="'+swList+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#FFFFFF" />');
	document.write('<embed src="/cci/mods/'+swFile+'.swf?rand='+randNum+'" FlashVars="'+swList+'" ');
	document.write('quality="high" bgcolor="#FFFFFF" width="740" height="460" name="module" align="middle" allowScriptAccess="sameDomain" ');
	document.write('type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}


function selectQType(qNum,area){
	pathPrefix=getPathPrefix(area,1)
	qTypeObj=findObjectPath('qType_'+qNum,area);
	qType=qTypeObj.options[qTypeObj.selectedIndex].value;
	//open or close input divs according to qType selection
	tfObj=findObjectPath('tfDiv_'+qNum,area);
	tfObj.style.display=(qType=='True/False')?'block':'none';
	mcObj=findObjectPath('mcDiv_'+qNum,area);
	mcObj.style.display=(qType=='Multiple Choice')?'block':'none';
	//update the question type text
	if(qType=='None'){color='#830000';}else{color='#174917';}
	changeText('statDiv_'+qNum,qType,color,area);
	//alert('going to fixIEBug');
	fixIEBug();
}


//TRADE CENTER FUNCTIONS

/*function prodImgSearch(selectRef,area){
	pathPrefix=getPathPrefix(area,1)
	selectObj=findObjectPath(selectRef,area);
	search=qTypeObj.options[qTypeObj.selectedIndex].value;
	//open or close input divs according to qType selection
	tfObj=findObjectPath('tfDiv_'+qNum,area);
	tfObj.style.display=(qType=='True/False')?'block':'none';
	mcObj=findObjectPath('mcDiv_'+qNum,area);
	mcObj.style.display=(qType=='Multiple Choice')?'block':'none';
	//update the question type text
	if(qType=='None'){color='#830000';}else{color='#174917';}
	changeText('statDiv_'+qNum,qType,color,area);
	//alert('going to fixIEBug');
	fixIEBug();
}*/

function addPOSASAP(){
	//alert('in addPOSASAP');
	document.write('<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0"');
	document.write('<ID="posasap" name="posasap" width=760 height=440> <param name=src value="posasap.dcr?rand='+randNum+'">');
	document.write('<param name=sw1 value="'+swList+'">');
	document.write('<param name=swRemote value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\' ">');
	document.write('<param name=swStretchStyle value=fill>');
	document.write('<PARAM NAME=bgColor VALUE=#FFFFFF> <PARAM NAME=name VALUE="posasap">');
	document.write('<embed src="posasap.dcr?rand='+randNum+'" bgColor=#FFFFFF name="posasap" swLiveConnect=TRUE  width=760 height=440 sw1="'+swList+'" ');
	document.write('swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\' " swStretchStyle=fill');
	document.write('type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/"></embed>');
	document.write('</object>');
}


function selectImgType(area){
	pathPrefix=getPathPrefix(area,1)
	imgTypeObj=findObjectPath('imgType',area);
	imgType=imgTypeObj.options[imgTypeObj.selectedIndex].value;
	//open or close title div according to selection
	divObj=findObjectPath("img_title",area);
	//dont show the title box for user logos OR any direct folder uploads
	divObj.style.display = (imgType!='user_logos' && imgType.indexOf('_folder')!=0) ? 'block' : 'none';
	//show PRODUCT PHOTOS category selection (for product photo library only, NOT products DB)
	divObj=findObjectPath("product_img_category",area);
	divObj.style.display = (imgType=='product_photos') ? 'block' : 'none';
	//show SERVING PHOTOS category selection 
	divObj=findObjectPath("serving_img_category",area);
	divObj.style.display = (imgType=='serving_photos') ? 'block' : 'none';
	//show the associated products div for serving photo uploads
	divObj=findObjectPath("img_assocProds",area);
	divObj.style.display = (imgType=='serving_photos') ? 'block' : 'none';
	//alert('going to fixIEBug');
	fixIEBug();
}


function imgLibSubmit(area){
	//alert("in imgLibSubmit");
	pathPrefix=getPathPrefix(area,1)
	//check to make sure an image has been selected for upload
	if(!pathPrefix.tableForm.imgUpload__new.value){
		alert("Please select an image file to upload.");
		pathPrefix.tableForm.imgUpload__new.focus();
		return;
	}
	//make sure an image type has been selected
	imgTypeObj=findObjectPath('imgType',area);
	imgType=imgTypeObj.options[imgTypeObj.selectedIndex].value;
	if(imgType=="none"){
		alert("Please select an image type");
		pathPrefix.tableForm.imgType.focus();
		return;
	}
	//check for title - NOT REQUIRED FOR USER LOGOS OR DIRECT FOLDER UPLOADS
	if(imgType!="user_logos" && imgType.indexOf('_folder')!=0 && !pathPrefix.tableForm.imgName.value){
		alert("Please enter a title/description");
		pathPrefix.tableForm.imgName.focus();
		return;
	}
	//check for PRODUCT PHOTOS image category selection
	imgCatObj=findObjectPath('product_imgCategory',area);
	imgCat=imgCatObj.options[imgCatObj.selectedIndex].value;
	newImgCat=pathPrefix.tableForm.product_newCategory.value;
	if(imgType=="product_photos" && imgCat=="none" && !newImgCat){
		alert("Please select an image category");
		pathPrefix.tableForm.imgCategory.focus();
		return;
	}
	//check for SERVING PHOTOS mage category selection
	imgCatObj=findObjectPath('serving_imgCategory',area);
	imgCat=imgCatObj.options[imgCatObj.selectedIndex].value;
	newImgCat=pathPrefix.tableForm.serving_newCategory.value;
	if(imgType=="serving_photos" && imgCat=="none" && !newImgCat){
		alert("Please select an image category");
		pathPrefix.tableForm.imgCategory.focus();
		return;
	}
	//check the associated products - NOTE that no product associations is ok, as long as there is an image category - SERVINGS ONLY
	if(imgType=="serving_photos"){assocProdUpdate(area);}
	//now show the warning div
	//alert("going to uploadWarning again");
	scriptPrefix=getPathPrefix(area,0)
	scriptPrefix.uploadWarning();
	//finally, submit the page
	//alert("submitting image");
	pathPrefix.tableForm.submit();
}


function assocProdUpdate(area){
	//alert('in assocProdUpdate');
	pathPrefix=getPathPrefix(area,1);
	framePrefix=getPathPrefix(area,0);
	assocProdString="";
	allProds=framePrefix.frames['iframeProdList'].document.getElementsByTagName('input');
	for(i=0;i<allProds.length;i++){
		if(allProds[i].checked){
			//tilda separate values
			if(assocProdString!=""){assocProdString+="~";}
			assocProdString+=allProds[i].name;
		}
	}
	//alert(assocProdString);
	//alert(pathPrefix.tableForm.db__assocProds);
	//now attach any value found for associated products to the hidden input element 'db__assocProds'
	pathPrefix.tableForm.db__assocProds.value=assocProdString;
	//alert(pathPrefix.tableForm.db__assocProds.value);
	return true;
}

//ORDER FORM FUNCTIONS

function modifyOrder(area,itemID,updateQty){
	//FIRST MAKE SURE THERE IS CURRENTLY NO VALIDATOR OBJECT TO GET IN OUR WAY (setup in submitOrder)
	validate=0;
	//alert('in modifyOrder');
	openDivList=captureOpenDivs(area);
	//if we are not updateing Qty, assume that we are removing any qty for the current item
	if(updateQty==0 || updateQty==null){
		itemQty='remove';
	}else{
		pathPrefix=getPathPrefix(area,1);
		itemQty=pathPrefix.tableForm['qty_'+itemID].value;
		//make sure there is some qty value
		if(itemQty=="" || itemQty=="0"){
			alert('Please enter a quantity before adding an item to your cart') ;
			return;
		}
		//now make sure this item qty is a numberic value
		 var charpos=itemQty.search("[^0-9]");
		 if(itemQty.length > 0 && charpos >= 0){
			alert('Please enter a numeric quantity');
			return;
		}
		//lastly, make sure the value is not too great
		maxQty=pathPrefix.tableForm['maxQty_'+itemID].value;
		if(parseInt(itemQty)>parseInt(maxQty)){
			alert('Sorry, you cannot order more than '+maxQty+' of this item') ;
			return;
		}
	}
	//alert(itemQty);
	pathPrefix.tableForm.action=pathPrefix.tableForm.action+'?itemID='+itemID+'&itemQty='+itemQty+"&openDivs="+openDivList;
	pathPrefix.tableForm.submit();
}

function submitOrder(){
	//alert('in submitOrder');
	//first make sure there is at least one item being ordered
	if(parseInt(document.tableForm.orderCount.value)<=0){
		alert('You must order at least one item to continue');
		return;
	}
	//create the validator object to check the input fields
	validate=new Validator("tableForm");
	validate.addValidation("orderName","req","An order name is required");
	validate.addValidation("name","req","Your name is required");
	validate.addValidation("store","req","Store name is required");
	validate.addValidation("address","req","Your address is required");
	validate.addValidation("city","req","Your city is required");
	validate.addValidation("state","req","Your state is required");
	validate.addValidation("zip","req","Your zip code is required");
	//validate.addValidation("email","req","Your email address is required");
	//validate.addValidation("email","email","A valid email address is required");
	validate.addValidation("deliverBy","req","A delivery deadline is required");
	//now invoke the validator
	if(document.tableForm.validateNow()){
		//set up variables for submission and submit the form for processing\
		//document.tableForm.orderType.value=curPanel;
		//document.tableForm.route.value='orderSubmitted';
		document.tableForm.action="/orders/order_process.php";
		//document.tableForm.action="/orders/order_process.php?route=orderSubmitted&orderType="+curPanel;
		document.tableForm.submit();
	}
	//kill the validation object
	validate=0;
}


function orderShippedGate(){
	//alert('in orderShippedGate');
	//first make sure a shipment tracking number was entered
	if(!document.tableForm.shipTracking.value){
		alert('You must first enter a shipment tracking number before confirming order shipment.');
		document.tableForm.shipTracking.focus();
		return;
	}else{
		decision=confirm('Please confirm that this order has shipped.');
		if(decision==true){
			//set up variables for submission and submit the form for processing\
			//document.tableForm.orderID.value=orderID;
			document.tableForm.route.value='orderShipped';
			document.tableForm.action='/orders/order_process.php';
			document.tableForm.submit();
		}
	}
}


function removeOrder(removeBtn,orderID,userType){
	//alert("in removeOrder");
	decision=confirm('Are you sure you want to remove this order?');
	if(decision==true){
		if(userType=='qc'){
			decision=confirm('Alert the RBM that this order has been approved for printing?');
		}else if(userType='print'){
			decision=confirm('Alert the RBM that this order has been printed and shipped?');
		}else if(userType=='admin'){
			decision=confirm('Alert the RBM that this order has been printed and shipped?');
		}
		if(decision==true){
			window.location='/orders/order_process.php?route=orderRemovedNotify_'+userType+'&orderID='+orderID;
		}else{
			window.location='/orders/order_process.php?route=orderRemoved&orderID='+orderID;
		}
	}else{
		//uncheck the checkox if the user decided not to remove the record
		//document.tableForm[removeBtn].checked=false;
	}
}


//alert('site.js up');
var popPOD=0;
var popLogin=0;
function loginPOD(){
	//alert('in loginPOD');
	//open login screen - NOTE< podUserID and podPassword must be set in whatever page is calling this script
	url='http://67.53.22.27/DSF/Default.aspx?_ctl0%3Aemail='+podUserID+'&_ctl0%3Apassword='+podPassword+'&_ctl0%3AButtonLogin=%20Login%20&_ctl0%3ACheckBoxSaveLogin=0&__EVENTTARGET=0&__EVENTARGUMENT=0';
	if(popLogin){popLogin.close(); popLogin=0;}
	popLogin=window.open(url,'POD_Login','width=100,height=100,left='+parseInt((screen.width - 100)/2)+',top='+parseInt((screen.height - 100)/2)+',resizable=0,scrollbars=0');
	popLogin.blur();
	//open loading screen
	if(screen.width>900){
		width=900;
		height=640;
	}else{
		width=780;
		height=580;
	}
	winLeft=parseInt((screen.width - 900)/2);
	winTop=parseInt((screen.height - 640)/2);
	if(popPOD){popPOD.close(); popPOD=0;}
	popPOD=window.open('','Print_On_Demand','width='+width+',height='+height+',left='+winLeft+',top='+winTop+',resizable=1,scrollbars=1');
	popPOD.document.open();
	popPOD.document.write('<html><head></head><body><table width="100%" height="100%" align="center"><tr><td align="center" style="padding:180px;">Loading Print On Demand<br />One Moment Please</tr></table></body>');
	popPOD.document.close();
	popPOD.focus();
	setTimeout('openPOD()',2400);
}

function openPOD(){
	//alert('in openPOD');
	popPOD.location='http://67.53.22.27/DSF/Default.aspx?'+podLinkVars;
	//close the login popup
	if(popLogin&&!popLogin.closed){
		popLogin.close();
		popLogin=0;
	}
}


function openIndexLink(type,accessArea,linkData){
	//alert('in openIndexLink');

	switch(type){
		case "select":
			if(document.tableForm[linkData].options[document.tableForm[linkData].selectedIndex].text!="Select One"){
				linkData=document.tableForm[linkData].options[document.tableForm[linkData].selectedIndex].value;
				if(linkData && linkData!="title"){
					closePopup();
					//document.tableForm.accessArea.value=accessArea;
					//document.tableForm.linkVars.value=linkData;
					//document.tableForm.submit();
					top.goNavFrame(accessArea,'useRouter',1,linkData);
				}
			}
			break;
			
		case "selectFromPop":
			if(popWin.document.tableForm[linkData].options[popWin.document.tableForm[linkData].selectedIndex].text!="Select One"){
				linkData=popWin.document.tableForm[linkData].options[popWin.document.tableForm[linkData].selectedIndex].value;
				if(linkData && linkData!="title"){
					closePopup();
					//document.tableForm.accessArea.value=accessArea;
					//document.tableForm.linkVars.value=linkData;
					//document.tableForm.submit();
					top.goNavFrame(accessArea,'useRouter',1,linkData);
				}
			}
			break;
	
		case "url":
			//document.tableForm.accessArea.value=accessArea;
			//document.tableForm.linkVars.value=linkData;
			//document.tableForm.submit();
			top.goNavFrame(accessArea,'useRouter',1,linkData);
			break;
	
		case "urlFromPop":
			closePopup();
			//document.tableForm.loginArea.value=loginArea;
			//document.tableForm.linkVars.value=linkData;
			//document.tableForm.submit();
			top.goNavFrame(accessArea,'useRouter',1,linkData);
			break;
			
		case "selectPop":
			//create a popup window with the appropriate select list for the current index item
			goURL('/marketing_materials/mm_popup.php?popType=selectList&recordID='+linkData,'popup',540,160,1,1)
			return;
			break;
	}
}


//RECG FUNCTIONS

function showCity(query){
	//alert('showCity');
	if(query==null){
		//if parameters are void, assume this call is coming from the dropdown list
		query=window.document.cityLocate.citySelect.options[window.document.cityLocate.citySelect.selectedIndex].value;
	}
	if(query!='none'){
		window.location='locate.php?'+query;
	}
}


function listCities(letter){
	//alert('listCities');
	//close all but the current city div
	allLetters=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
	//allLetters=new Array('A','B');
	for(curLoc in allLetters){
		curLetter=allLetters[curLoc];
		divObj=findObjectPath("div_"+curLetter);
		if(curLetter==letter){
			//alert('found letter match');
			divObj.style.display='block';
		}else{
			if(divObj!=null && divObj.style.display!='none'){divObj.style.display='none';}
		}
	}
	fixIEBug();
}
