// JavaScript Document

function printAgent(iCeleb,id)
{
	window.open('printagent.php?cid=' + iCeleb + '&id=' + id,'Print_Agent','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printManager(iCeleb,id)
{
	window.open('printmng.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printPR(iCeleb,id)
{
	window.open('printpr.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printLawyer(iCeleb,id)
{
	window.open('printlawyer.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printFanClub(iCeleb,id)
{
	window.open('printfanclub.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printOffice(iCeleb,id)
{
	window.open('printoffice.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printPublicist(iCeleb,id)
{
	window.open('printpublicist.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function printComAgent(iCeleb,id)
{
	window.open('printcomagent.php?cid=' + iCeleb + '&id=' + id,'Print_Manager','top=0,toolbars=1,menubar=yes,width=600,height=650');
}
function savePage(theForm)
{
	Celebrity.formAction.value = 'Save';
	Celebrity.submit();
}
function submitPurchase(theForm)
{
	if(theForm.txtCelebrity.value == "")
	{
		alert("Please enter the celebrity name");
		theForm.txtCelebrity.focus();
		return false;
	}
	if(theForm.txtBestKnown.value == "")
	{
		alert("Please enter what they are know for");
		theForm.txtBestKnown.focus();
		return false;
	}
	if(!theForm.chkAutoGraph.checked && !theForm.chkLetter.checked && !theForm.chkTalent.checked &&
		!theForm.chkPersonal.checked && !theForm.chkPublic.checked && !theForm.chkScriptStory.checked && 
		!theForm.chkFanClub.checked && !theForm.chkOther.checked)
		{
			alert("Please select a reason for the request");
			return false;
		}
	if(theForm.chkOther.checked && theForm.txtOther.value == "")
	{
		alert("The Other field was left blank");
		theForm.txtOther.focus();
		return false;
	}
	if(theForm.txtHowHear.value == "")
	{
		alert("Please select how you found us.");
		theForm.txtHowHear.focus();
		return false;
	}		
	return true;	
	
}
function calculateCost()
{
	var iNumRequests=0;
	var cTotal=0;
	var iNumOrders = frmOrder.NumOrders.value;
	
	if(frmOrder.chkAutoGraph.checked)
		iNumRequests += 1;
	
	if(frmOrder.chkLetter.checked)
		iNumRequests += 1;
		
	if(frmOrder.chkTalent.checked)
		iNumRequests += 1;
		
	if(frmOrder.chkPersonal.checked)
		iNumRequests += 1;
	
	if(frmOrder.chkPublic.checked)
		iNumRequests += 1;
		
	if(frmOrder.chkScriptStory.checked)
		iNumRequests += 1;
		
	if(frmOrder.chkFanClub.checked)
		iNumRequests +=1;
		
	if(frmOrder.chkOther.checked)
		iNumRequests +=1;

	if(iNumRequests > 1)
	{
		cTotal = 9.95;
		cTotal += (5.95 * (iNumRequests -1))
	}
	else
	{
		cTotal = 9.95;
		
	}
	
	frmOrder.txtCost.value = cTotal.toFixed(2);
	frmOrder.txtMarked.value = iNumRequests;
}

function purchaseAdd(theForm)
{
	frmOrder.Action.value = "Add";
	frmOrder.submit();
}

function clear_value()
{
	obj = window.event.srcElement;
    obj.setAttribute("persistValue","");
 
}
function lookupItem(obj)
{
	var sCurValue = obj.getAttribute("persistValue").toLowerCase();
	var bFound = false;
    var iIndex = obj.selectedIndex;
    var iNumOptions = obj.options.length;
    var iPos = 0;
    // Repeat until found or end of list is reached
    while ((!bFound) && (iPos < iNumOptions))
    {
    	// Do comparisons in lowercase
        bFound = (obj.options[iPos].text.toLowerCase().indexOf(sCurValue)==0) ;
        if (bFound)
        iIndex = iPos;
        iPos++;
     }
        if (bFound)
         // Updated listbox
         obj.selectedIndex = iIndex;
}

function divert_entry()
{
	obj = window.event.srcElement;
    //debugger;
    if  (obj.getAttribute("persistValue") == null)
    	obj.setAttribute("persistValue","");                           
    var iKey;
    var eAny_Event = window.event;
               
    iKey = eAny_Event.keyCode;
    if(iKey >=96 && iKey <=105)
    {
		iKey = iKey - 48;
	}
	var sChr = String.fromCharCode(iKey);
				
    if (iKey == 13)
    {
    	obj.setAttribute("persistValue","");
		Celebrity.submit();
        return true;
    }
    if (iKey == 8)
    {	
		sDelete_Chr = obj.getAttribute("persistValue");
        obj.setAttribute("persistValue", sDelete_Chr.substring(0,sDelete_Chr.length - 1));
        sChr = '';
    }
    
	obj.setAttribute("persistValue",obj.getAttribute("persistValue") + sChr);
    lookupItem(obj);
    if(((iKey > 33 && iKey < 255) || (iKey == 8)) && ((iKey != 40) && (iKey != 38)))
		eAny_Event.returnValue = false;
}
function display_sub(iCtrl)
{
	var ctrlToFind = "dls_MainMenu__ctl" + iCtrl + "_div_MenuItems";
	var divControl = document.all.item(ctrlToFind);
	divControl.className= "shwMenu";
}
function hide_sub(iCtrl)
{
	var ctrlToFind = "dls_MainMenu__ctl" + iCtrl + "_div_MenuItems";
	var divControl = document.all.item(ctrlToFind);
	divControl.className= "hdnMenu";
}	

function continueShopping()
{
	cart.action= "http://celebritycontacts.com/?page_id=47";
	cart.submit();
}

function secureCheckout()
{
	if(cart.NumItems.value==0 || cart.NumItems.value=="")
	{
		alert("The shopping cart is empty.");
		return false;
	}
	else
	{
		cart.action = "http://celebritycontacts.com/?page_id=63";
		cart.submit();
	}
}
function sendEMail()
{
		fillorders.action = "fillorder.php";
		fillorders.submit();
}

function viewResponse(iOrder)
{
	window.open('viewemailresponse.php?Order=' + iOrder,'View_EMail_Response','toolbar=0, menubar=1, width=605,height=600,scrollbars=1,left=5,top=0');
		
}

function ViewOrder(theForm)
{
	var iID;
	var iContact;
	var iDetailID;
	
	if(theForm.Celebrity.value == '')
	{
		alert('You must select a celebrity to view');
		theForm.Celebrity.focus();
	}
	else
	{
		iID = theForm.id.value;
		iContact = theForm.Celebrity.value;
		iDetailID = theForm.OrderDetail.value;
		
		window.open('viewcelebrity.php?id=' + iID + '&Celebrity=' + iContact + "&DetailID=" + iDetailID,'View_Contact',							
					'toolbar=0,menubar=1,width=900,height=600,scrollbars=1,left=5,top=0');
	}
}
function openViewOrder(iID,iCount)
{
	var sName;
	var AllValid=true;
	var iContact;
	var iDetailID;
	
	for (i=0; i < fillorders.elements.length; i++)
	{	
		sName = fillorders.elements[i].name;
		if(sName =='Celebrity' + iCount)
		{
			if(fillorders.elements[i].value == '')
			{
				alert('You must select a celebrity to view');
				fillorders.elements[i].focus();
				AllValid=false;
				break;
			}
			else
			{
				iContact = fillorders.elements[i].value;
			}
		}
		if(sName == 'OrderDetail' + iCount)
		{	
			iDetailID = fillorders.elements[i].value;
		}
	}
	
	if(AllValid)
	{
		window.open('viewcelebrity.php?id=' + iID + '&Celebrity=' + iContact + "&DetailID=" + iDetailID,'View_Contact',				'toolbar=0,menubar=1,width=900,height=650,scrollbars=1,left=5,top=0');
	}
}

function openEdit(iID)
{
	window.open('celebrity.php?id=' + iID,'View_Contact','toolbar=0,menubar=1,width=900,height=650,scrollbars=1,left=5,top=0');
}
function validCustomer()
{
	if(CustomerInfo.txtName.value == "")
	{
		alert('Please enter a name');
		CustomerInfo.txtName.focus();
		return false;
	}
	if(CustomerInfo.txtStreet.value == "")
	{
		alert('Please enter an address');
		CustomerInfo.txtStreet.focus();
		return false;
	}
	
	if(CustomerInfo.txtCity.value == "")
	{
		alert('Please enter a city');
		CustomerInfo.txtCity.focus();
		return false;
	}
	if(CustomerInfo.txtState.value == "")
	{
		alert('Please enter a state');
		CustomerInfo.txtState.focus();
		return false;
	}
	if(CustomerInfo.txtZip.value == "")
	{
		alert('Please enter a zip code');
		CustomerInfo.txtZip.focus();
		return false;
	}
	if(CustomerInfo.txtEmail.value == "")
	{
		alert('Please enter an email address');
		CustomerInfo.txtEmail.focus();
		return false;
	}
	return true;

}

function homePage()
{
	window.location = "http://www.celebritycontactfinders.com";
}
function loadFrame()
{
    if(window.parent==window)
	{
		location.href = 'index.html';
	}
}