// JavaScript Document

function doLogin( theObj ) {
		thePW = base64_encode( getObj(theObj).value );
		eval(JJPage.doNow("do=cpass&thepw=" + thePW)); 
		getObj(theObj).value = ""; }

function doPreview() {
	SetInner('preImage', ' ' );
	theImage = "<img src=\"sjdb/small/s_" + CurrentPID + ".jpg\" width=\"75\" height=\"75\" border=\"0\">";
	theStatusL = "<a href=\"javascript:AddItem('" + CurrentPID + "', 'one',0)\">Buy Now</a>";
	theStatus = getObj('pStatus').value;
	SetInner('preImage', theImage );
	SetInner('preModel',getObj('pModel').value);
	SetInner('preDescL',getObj('pDescL').value);
	SetInner('preDescR',getObj('pDescR').value);
	if ( getObj('pDescR').value == "" ) { getObj('preDescR').parentNode.style.width = "0%"; getObj('preDescL').parentNode.style.width = ""; } 
	else { getObj('preDescR').parentNode.style.width = "50%"; getObj('preDescL').parentNode.style.width = "";}
	SetInner('prePrice',"$" + cent(getObj('pPrice').value));
	SetInner('preColors',JJPage.doNow( "do=colnames&method=true&thestr=" + GetChecked('pColor[]') ) );
	switch ( theStatus ) {
		case "Normal" : { break }
		case "Soon" : { theStatusL = "Coming Soon"; break }
		case "Out" : { theStatusL = "Sold Out"; break }
		case "Discontinued" : { theStatusL = "Discontinued"; break }
		case "PreOrder" : { theStatusL = "PreOrder"; break } } 
	SetInner( 'preBuyNow', theStatusL ); }

function fillProduct(theVar) { eval( JJPage.doNow( "do=gproduct&pid=" + theVar ) ); getObj('curPID').value = theVar; doPreview(); }

function submitProduct( doUpdate ) {
	if ( doUpdate ) { startStr = "do=uproduct&cpid=" + CurrentPID + "&"; } else { startStr = "do=nproduct&"; }
	theStatus = getObj('pStatus').value;
	if ( !getObj('pModel').value ) { alert("Please enter a Model"); return; } else { theModel = urlencode(getObj('pModel').value); }
	if ( !getObj('pDescL').value ) { alert("Please enter a Description"); return; } else { theDescL = urlencode(getObj('pDescL').value); }
	theDescR = urlencode(getObj('pDescR').value);
	if ( !getObj('pPrice').value ) { alert("Please enter a Price"); return; } else { thePrice = getObj('pPrice').value; }
	if ( getObj('pCategory').value == "null" ) { alert("Please choose a Category"); return; } else { theCat = getObj('pCategory').value; }
	theLarge = "&plarge=" + Number(getObj('pLarge').checked);
	theColors = "&pcolors=" + urlencode(GetChecked('pColor[]'));
	theWeight = "&pweight=" + Number(getObj('pWeight').value);
	finalStr = startStr + "pstatus="+theStatus + "&pmodel=" + theModel + "&pdescl=" + theDescL + "&pdescr=" + theDescR + "&pprice=" + thePrice + theLarge + theColors + theWeight + "&thecat=" + theCat;
	SetInner('errorDIV',JJPage.doNow( finalStr ) );
	if ( !doUpdate ) { doPLoad('nproduct'); } }

function submitCategory() {
	if ( getObj("cName").value == "" ) { return; }
	var fullqry = "do=ncat&method=true";
	var cName = urlencode(getObj("cName").value);
	fullqry = fullqry + "&cname=" + cName;
	JJPage.addReq( 'errorDIV', fullqry, finishCat );
	getObj("cName").value = ""; }

function submitPage() {
	if ( getObj("newPage").value == "" ) { return; }
	var fullqry = "do=npage&method=true";
	var pName = urlencode(getObj("newPage").value);
	fullqry = fullqry + "&pname=" + pName;
	JJPage.addReq( 'errorDIV', fullqry, finishNPage );
	getObj("newPage").value = ""; }

function submitLarge(tbName, theObj, theList ) {
	if ( getObj(theObj).value == "" ) { return; }
	var fullqry = "do=nlarge&thetb=" + tbName;
	var lItem = urlencode(getObj(theObj).value);
	fullqry = fullqry + "&item=" + lItem;
	fullqry = fullqry + "&parent=" + CurrentLPID;
	add2List(theList,theObj, JJPage.doNow( fullqry ) );
	getObj(theObj).value = ""; }

function deleteCategory( cID ) {
	var fullqry = "do=dcat&method=true";
	fullqry = fullqry + "&cID=" + cID;
	JJPage.addReq( 'errorDIV', fullqry, finishCat ); }

function getListing( theDiv , theBE , theVar ) {
	doLoading( theDiv );
	var fullqry = "do=" + theBE;
	try { fullqry += "&thevar=" + theVar; } catch(e) {} 
	JJPage.addReq( theDiv, fullqry , showResult ); }

function submitColor() {
	var fullqry = "do=ncolor&method=true";
	var cName = urlencode(getObj("cName").value);
	fullqry = fullqry + "&cname=" + cName;
	JJPage.addReq( 'errorDIV', fullqry, finishColor );
	getObj("cName").value = ""; }

function deleteColor( cID ) {
	var fullqry = "do=dcolor&method=true";
	fullqry = fullqry + "&cID=" + cID;
	JJPage.addReq( 'errorDIV', fullqry, finishColor ); }

function updateCategory( cID ) {
	var fullqry = "do=ucat&cid=" + cID + "&cname=" + urlencode(getObj("cName" + cID).value);
	JJPage.addReq( 'errorDIV', fullqry, finishCat ); }

function uploadImg( fID , theObj , theForm , theCB ) {
	imgForm = getObj(theForm);
	if ( !fID ) { imgForm.fid.value = CurrentPID; }
	var theValue = getObj(theObj).value; 
	var theExt = theValue.substr(theValue.lastIndexOf('.'));
	if ( theValue == "" ) { alert("Please choose an image"); return; }
	if ( theExt != ".jpg" ) { alert("JPEG (.JPG) files only"); return; }
	imgForm.target = "upload_target";
	imgForm.submit();
    pollUpload(theCB);
	return; }

function submitHeader() {
	if ( getObj("hName").value == "" ) { return; }
	var fullqry = "do=nheader&method=true";
	var hName = urlencode(getObj("hName").value);
	fullqry = fullqry + "&hname=" + hName;
	JJPage.addReq( 'errorDIV', fullqry, finishHeader );
	getObj("hName").value = ""; }

function deleteHeader( hID ) {
	var fullqry = "do=dheader&method=true";
	fullqry = fullqry + "&hID=" + hID;
	JJPage.addReq( 'errorDIV', fullqry, finishHeader ); }

function updateHeader( hID ) {
	var fullqry = "do=uheader&hid=" + hID + "&hname=" + urlencode(getObj("hName" + hID).value);
	JJPage.addReq( 'errorDIV', fullqry, finishHeader ); }

function loadPData( theObj ) { CurrentPageID = theObj.value; if ( CurrentPageID ) { getObj('pName').value = theObj.options[theObj.selectedIndex].text; getListing('pOrderDIV','gporder' , CurrentPageID ); getObj('pageID').value = CurrentPageID; } }

function loadLData( theObj ) { CurrentLPID = theObj.value; if ( CurrentLPID ) { getListing('lOrderDIV','gllist' , CurrentLPID ); getListing('iOrderDIV','gilist' , CurrentLPID ); } }

function saveOrder( ) {
	if ( CurrentPageID == 0 ) { alert("Choose a page order to modify first."); return; }
	theOrder = urlencode(GetMulti('pOrder' , 1 ));
	theName = getObj('pName').value;
	var fullqry = "do=upage&pid=" + CurrentPageID + "&porder=" + theOrder + "&pname=" + theName;
	JJPage.addReq( 'errorDIV', fullqry, finishNPage ); }

function saveLOrder( ) {
	if ( CurrentLPID == 0 ) { alert("Choose a product order to modify first."); return; }
	theOrder = urlencode(GetMulti('lOrder' , 1 ));
	theName = getObj('pName').value;
	var fullqry = "do=ulpage&pid=" + CurrentPageID + "&porder=" + theOrder + "&pname=" + theName;
	JJPage.addReq( 'errorDIV', fullqry, finishNPage ); }

function deletePage( ) {
	if ( CurrentPageID == 0 ) { alert("Choose a page to delete first."); return; }
	if ( !confirm("Are you Sure?") ) { return; }
	var fullqry = "do=dpage&pid=" + CurrentPageID;
	JJPage.addReq( 'errorDIV', fullqry, finishDPage ); }

function removeOrder() {
	theObj = getObj('pOrder');
	if ( theObj.length <= 0 ) {return;}
	theIndex = theObj.selectedIndex; theItem = theObj[theIndex].value;
	if ( theItem[0] == 'h' ) { sel2sel( 'pOrder', 'pHeaders' ); } else { sel2sel( 'pOrder', 'pProducts' ); } if (theIndex) { theObj.selectedIndex = theIndex - 1 } else { theObj.selectedIndex = 0; } }

function finishCat( vDiv, theResult ) { showResult( vDiv, theResult ); getListing('categoryTDIV','gcat'); }
function finishHeader( vDiv, theResult ) { showResult( vDiv, theResult ); getListing('headerTDIV','gheader'); }
function finishColor( vDiv, theResult ) { showResult( vDiv, theResult ); getListing('colorTDIV','gcolor'); }
function finishNPage( vDiv, theResult ) { showResult( vDiv, theResult ); }
function finishDPage( vDiv, theResult ) { doPLoad('pages'); showResult( vDiv, theResult ); }

function checkCFile() { if (fileDone == 0) { pollUpload("checkCFile"); return; } fileDone = 0; getListing('colorTDIV','gcolor'); }
function checkImageU() { if (fileDone == 0) { pollUpload("checkImageU"); return; } fileDone = 0; showResult('outputDIV',myUQry); }
function checkChecked() { if (fileDone == 0) { pollUpload("checkChecked"); return; } fileDone = 0; showResult('outputDIV',theResult); }
