// Admin Form Functions
// GO Admin Function Page
function goAdmin(pageLocation)
{
	//top.frames["mainFrame"].document.baseImage.src
	eval("top.frames['bottomFrame'].location.href=\"" + pageLocation + "\";")
}

// Launching Pages from the Admin Menu Screens

function changeCursorHand()
{
	document.body.style.cursor = "hand";
}

function changeCursorDefault()
{
	document.body.style.cursor = "default";
}

function validateFlyerStep1()
{
	if (document.forms[1].chkUSEINFORMATION.checked==true && document.forms[1].txtCompanyName.value != "")
	{
		alert("If you choose to use your 'on file' information, do not fill out the information fields.");
		return false;
	}
	else
	{
		if (document.forms[1].chkUSEINFORMATION.checked==false && document.forms[1].txtCompanyName.value == "" && document.forms[1].txtFirstName.value == "" && document.forms[1].txtLastName.value == "")
		{
			alert("If you choose not to use your 'on file' information then you must fill in all required fields below.");
			return false;
		}
		else
		{
			return;
		}
	}
}
function validateCatalog()
{
	if (document.forms[0].txtPRICERATIO1.value=="" || document.forms[0].txtPRICERATIO2.value=="" || document.forms[0].txtPRICERATIO3.value=="" || document.forms[0].txtITEMNUMBER.value == "" || document.forms[0].txtITEMSTYLENAME.value == "" || document.forms[0].cmbCATALOGCATEGORY.options[document.forms[0].cmbCATALOGCATEGORY.selectedIndex].value == "_none")
	{
		alert("Please provide an Item Number, Style Name and  Catalog Category in order to store this item. You must also specify the prices. All other fields are optional but will impact the visual display of the catalog item.");
		return false;
	}
	else
	{
		return;
	}
}

function validateEmailAFriend(frameNumber)
{
	if (document.forms[frameNumber].emailFROM.value=="" || document.forms[frameNumber].emailTO.value=="")
	{
		alert("Please make certain you put in your email and an email to send this to.");
		return false;
	}
	else
	{
		return;
	}
}

function validateCWSStep3()
{
	if (document.forms[1].catalogShow[1].checked && (document.forms[1].cmbCATEGORY1.options[document.forms[1].cmbCATEGORY1.selectedIndex].value=="_none" || document.forms[1].cmbCATEGORY2.options[document.forms[1].cmbCATEGORY2.selectedIndex].value=="_none" || document.forms[1].cmbCATEGORY3.options[document.forms[1].cmbCATEGORY3.selectedIndex].value=="_none"))
	{
		alert("If you choose to pick specific styles you must choose them from the drop down menus. Please review the form and click Next when ready.");
		return false;
	}
	else
	{
		return;
	}
}

function validateSignup()
{
	if (document.forms[0].txtFIRST_NAME.value=="" || document.forms[0].txtLAST_NAME.value=="" || document.forms[0].txtEMAIL_ADDRESS.value == "" || document.forms[0].txtADDRESS.value == "" || document.forms[0].txtZIP_POSTAL.value == "" || document.forms[0].txtCITY.value == "" || document.forms[0].txtSTATE_PROVINCE.value == "" || document.forms[0].cmbCOUNTRY.options[document.forms[0].cmbCOUNTRY.selectedIndex].value == "_none")
	{
		alert("You missed 1 or more required fields, please review the form and click Submit when finished.");
		return false;
	}
	else
	{
		return;
	}
}

function validateCategory()
{
	if (document.forms[0].txtTITLE.value == "")
	{
		alert("Please provide a name for this category.");
		return false;
	}
	else
	{
		return;
	}
}

// Launching Pages from the Admin Menu Screens
function submitAdminAction(pageName,fieldName,actionName,targeted)
{
	if(targeted == "self")
	{
		eval("window.location.href=\"admin_" + pageName + "_" + actionName + ".asp?id=\" + document.forms[0]." + fieldName + ".options[document.forms[0]." + fieldName + ".selectedIndex].value + \"\"");
	}
	else if(targeted == "newvalue")
	{
		eval("window.location.href=\"admin_" + pageName + "_" + actionName + ".asp?hiddenid=\" + document.forms[0].hdnID.options[document.forms[0].hdnID.selectedIndex].value + \"&id=\" + document.forms[0]." + fieldName + ".options[document.forms[0]." + fieldName + ".selectedIndex].value + \"\"");
	}
	else
	{
		eval("window.open('admin_" + pageName + "_" + actionName + ".asp?id=' + document.forms[0]." + fieldName + ".options[document.forms[0]." + fieldName + ".selectedIndex].value,null,'height=450,width=550,scrollbars=auto,menu=no');")
	}
}


// Global Form Functions
function cancelAdmin()
{
	window.history.go(-1);
}

function callUpload(uploadFieldName,formNumber)
{
	if(formNumber != 1 && formNumber != 2)
	{
		eval("window.open(\"/_inc/_upload/upload_file.aspx?formnumber=0&fieldname=" + uploadFieldName + "\",\"\",\"height=250,width=350,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left=0,top=0\")")
	}
	else if(formNumber == 1)
	{
		eval("window.open(\"/_inc/_upload/upload_file.aspx?formnumber=1&fieldname=" + uploadFieldName + "\",\"\",\"height=250,width=350,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left=0,top=0\")")
	
	}
	else if(formNumber == 2)
	{
		eval("window.open(\"/_inc/_upload/upload_file.aspx?formnumber=2&fieldname=" + uploadFieldName + "\",\"\",\"height=250,width=350,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left=0,top=0\")")
	
	}
}

function launchRTFEditor(editFieldName)
{
	eval("window.open(\"/_inc/_rtfeditor/rtfeditor.asp?editFieldName=" + editFieldName + "\",\"\",\"height=500,width=600,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=0,toolbar=0,left=0,top=0\")")
}

function submitReportRange(pageName)
{
	eval("window.open('admin_" + pageName + "_report.asp?action=range&date1=' + document.forms[0].txtDate1.value + '&date2=' + document.forms[0].txtDate2.value,null,'height=300,width=400,menu=no');")
}

function submitReportFromLast(pageName)
{
	eval("window.open('admin_" + pageName + "_report.asp?action=last&date1=' + document.forms[0].hdnDate.value,null,'height=300,width=400,menu=no');")
}

function showMenuCWS(whichMenu)
{
	eval(whichMenu+".style.visibility = \"visible\";");
}

function showMenu(whichMenu)
{
	hideAllExcept(whichMenu);
	eval(whichMenu+".style.visibility = \"visible\";");
}

function hideMenu(whichMenu)
{
	eval(whichMenu+".style.visibility = \"hidden\";");
}

function hideAllExcept(whichMenu)
{
	if (whichMenu != "catalog")
	{
		catalog.style.visibility = "hidden";
	}
	if (whichMenu != "corporate")
	{
		corporate.style.visibility = "hidden";
	}
	if (whichMenu != "marketing")
	{
		marketing.style.visibility = "hidden";
	}
	if (whichMenu != "customer")
	{
		customer.style.visibility = "hidden";
	}
}


// BEGIN - Functions for the Add/Remove Case Studies in a Portfolio Administration Interface

function deleteOption(object,index) {
    object.options[index] = null;
}

function addOption(object,text,value) {
    var defaultSelected = true;
    var selected = true;
    var optionName = new Option(text, value, defaultSelected, selected)
    object.options[object.length] = optionName;
}

function copySelected(fromObject,toObject) {
    for (var i=0, l=fromObject.options.length;i<l;i++) {
        if (fromObject.options[i].selected)
            addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
    }
    for (var i=fromObject.options.length-1;i>-1;i--) {
        if (fromObject.options[i].selected)
            deleteOption(fromObject,i);
    }
}

function copyAll(fromObject,toObject) {
    for (var i=0, l=fromObject.options.length;i<l;i++) {
        addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
    }
    for (var i=fromObject.options.length-1;i>-1;i--) {
        deleteOption(fromObject,i);
    }
}

function selectAllValues()
{
  List = document.forms[0].cmbUsedWebLinks;
  for (i=0;i<List.length;i++)
  {
     List.options[i].selected = true;
  }
  document.forms[0].submit();
}	

function moveup(list) {
	var daflag = false
	for (var i = 0; i <= list.options.length-1; i++) {
		if (!list[i].selected) {
			daflag = true
		}
		if (list[i].selected && daflag) {
			list.insertBefore(list[i],list[i-1])
		}
	}
}
function movedown(list) {
	var daflag = false
	for (var i = list.options.length-1; i >= 0; i--) {
		if (!list[i].selected) {
			daflag = true
		}
		if (list[i].selected && daflag) {
			list.insertBefore(list[i],list[i+2])
		}
	}
}

function catalogSwatch(swatchID,catalogID,swatchFLAG,formNUMBER)
{
	if (swatchFLAG == 1)
	{
		eval("document.forms["+formNUMBER+"].action = \"catalog.asp?swatchid=" + swatchID + "&id=" + catalogID + "\";");
		eval("document.forms["+formNUMBER+"].submit();");
	}
	else if (swatchFLAG == 0)
	{
		eval("document.forms["+formNUMBER+"].action = \"catalog.asp?id=" + catalogID + "\";");
		eval("document.forms["+formNUMBER+"].submit();");
	}
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;

return unescape(dc.substring(begin + prefix.length, end));
}

function viewDataSheet()

{

	if (document.forms[0].cmbDataSheet.options[document.forms[0].cmbDataSheet.selectedIndex].value == "none")

	{

		alert("Please make a selection and then click the View Data Sheet button.");

	}

	else if (document.forms[0].cmbDataSheet.options[document.forms[0].cmbDataSheet.selectedIndex].value == "Not Available")

	{

		naDataSheet()

	}

	else if (document.forms[0].cmbDataSheet.options[document.forms[0].cmbDataSheet.selectedIndex].value != "none" && document.forms[0].cmbDataSheet.options[document.forms[0].cmbDataSheet.selectedIndex].value != "Not Available")

	{

		window.open("http://www.bulkmolding.com/datasheets/informational/BMC_" + document.forms[0].cmbDataSheet.options[document.forms[0].cmbDataSheet.selectedIndex].value + ".pdf");

	}

}

function viewMaterialSafetySheet()

{

	if (document.forms[0].cmbMaterialSafety.options[document.forms[0].cmbMaterialSafety.selectedIndex].value == "none")

	{

		alert("Please make a selection and then click the View Material Safety Data Sheet button.");

	}

	else if (document.forms[0].cmbMaterialSafety.options[document.forms[0].cmbMaterialSafety.selectedIndex].value == "Not Available")

	{

		naDataSheet()

	}

	else if (document.forms[0].cmbMaterialSafety.options[document.forms[0].cmbMaterialSafety.selectedIndex].value != "none" && document.forms[0].cmbMaterialSafety.options[document.forms[0].cmbMaterialSafety.selectedIndex].value != "Not Available")

	{

		window.open("http://www.bulkmolding.com/datasheets/material_safety/BMC_" + document.forms[0].cmbMaterialSafety.options[document.forms[0].cmbMaterialSafety.selectedIndex].value + ".pdf");

	}

}

function naDataSheet()

{

	alert("We are sorry, but this type of Data Sheet is not available yet.");

}

function showDataSheet(dsname)

{

	window.open("http://www.bulkmolding.com/datasheets/informational/BMC_" + dsname + ".pdf");

}

// Check for market cookie, if present do nothing, else show popup
function presentMarketing(marketingName)
{
	window.open("http://www.bulkmolding.com/lettertoeditor_10012008.htm","","height=420,width=620,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=250,top=100");
	
	//This is the page we will redirect to if all system requirements are met
	//if (getCookie("BulkMolding_" + marketingName) == null)
	//{
	//window.open("http://www.hepcatmedia.com/bmc/marketing/popup_question.asp");
	//window.open("http://www.bulkmolding.com/marketing/announcement.htm","","height=300,width=400,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=250,top=100");
	//This is the setting of the cookie that will alert the course to whether you are from a web or a cd-rom
	//expDate=new Date();              //day*hr*mn*sc*mili
	//expDate.setTime(expDate.getTime()+(7*24*60*60*1000)); // sets expires to 7 days from now.
	//var cookieExpires="expires=" + expDate.toGMTString();
	//eval("document.cookie = \"BulkMolding_" + marketingName + " = 1; " + cookieExpires + ";\"")
	//}
}

var popUpWin=0;
function popUpWindow(URLStr, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+'');
}

function activateMarketing()
{
	opener.document.location.href = "npe2003.htm";
	self.close();
}

function navigationSwap(objImage,state,imgType)
{
		if(state=='_off')
		{
			document.body.style.cursor = 'default';
		}
		else
		{
			document.body.style.cursor = 'hand';			
		}
		if(imgType=='png')
		{
			objImage.src = "images/" + objImage.name + state + ".png";
		}
		else if(imgType=='jpg')
		{
			objImage.src = "images/" + objImage.name + state + ".jpg";
		}
}

function libraryLaunch(pagevalue)
{
	
	window.open("/_uploads/pdf/" + pagevalue + ".pdf");	
}

function tutorialLaunch(pagevalue)
{
	
	window.open("/_uploads/" + pagevalue + ".html");	
}

function productInfLaunch(pagevalue)
{
	
	window.open("/datasheets/informational/BMC_" + pagevalue + ".pdf");	
}

function productMSLaunch(pagevalue)
{
	
	window.open("/datasheets/material_safety/BMC_" + pagevalue + ".pdf");	
}
