// JavaScript Document
function stripSpaces(string) {
	var tempValue = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++){
		tempValue += splitstring[i];
	}
	return tempValue;
}

function validateField(field) {
	if (stripSpaces(field) == "" || stripSpaces(field) == null) {
		return false;
	}
	return true;
}
function img_on(imgName) {
    if (document.images) {
        document [imgName].src = "images/"+imgName+"On.gif";
    }
}
function img_off(imgName) {
    if (document.images) {
        document [imgName].src = "images/"+imgName+"Off.gif";
    }
}
function doLogout(url) {
    //document.main.action = url + document.main.action;
    document.main.logoutButton.value= "click";
    document.main.submit();
}
function checkDataChanged() {
    if (dataChanged) {
        if (!confirm("You have unsaved changes on this page. Are you sure you want to leave this page?")) {
            return false;
        }
    }
    return true;
}
function copyIsbnList() {
    if (document.main.isbnList) {
        var mi = document.main.isbnList;
        var li = document.login.isbnList;
        var mq = document.main.usedQtyList;
        var lq = document.login.quantityList;
        for (var i = 0; i < mi.length; i++) {
            li[i].value = mi[i].value;
            lq[i].value = mq[i].value;
        }
    }
}
function doPagerOffset(x) {
    document.main.pagerOffset.value = x;
    document.main.submit();
}
function selectOrderHistory() {
	document.main.searchType.value = document.main.orderSearchType.value;
	document.main.selectCriteria.value = document.main.orderStatusSelect.value
	document.main.sortOrders.value=document.main.orderSort.value;
	document.main.pagerOffset.value = 0;
    document.main.submit();
}
function sortOrderHistory() {
	document.main.searchType.value = document.main.orderSearchType.value;
	document.main.selectCriteria.value = document.main.orderStatusSelect.value	
	document.main.sortOrders.value=document.main.orderSort.value;
    document.main.submit();
}
function doTitleLookup(ca,order,page) {
    if (checkDataChanged()) {
        window.location = "search.jsp?sellTitleLookup=true&catalogNumber="+ca+"&orderId="+order+"&currentPage="+page;
    }
}
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function pageOnLoad(showRequest,userid){
	if (showRequest == true) {
		var url = "emailRequest.jsp?userid="+userid;
		MM_openBrWindow(url,'emailRequest','status=yes,scrollbars=yes,resizable=yes,width=400,height=300');
	}
}
function closeWindow() { 
	window.close(self);
}
function redirectPage(jsp) {
	//replacing '&amp;' with '&' for firefox browser 
	window.location.replace(jsp.replace(/&amp;/g,"&"));
}
function goTo(url) {
	window.location = url;
}
function goToNewWindow(url) {
	window.open(url);
}
function toggleThumbs(){
	document.main.toggleImgFlag.value = "click";
    document.main.submit();
}
function setItemsPerPage(val){
	document.main.pageItemCount.value = val;
	doPagerOffset(0);
}
function refreshSession() {
	frames['refreshFrame'].window.location.href = "accountStatement3.jsp";
}

/**
	Stores id of pop-up window that is currently being displayed.
*/
var currentPopUp = null;

/**
	This method will return the position of an element.
		el - Element to return the position of
		sProp - The name of the position to return (eg. Left, Top, Right, Bottom)
		returns - integer position of the element's sProp offset
*/
function getPos(el, sProp) {
	var iPos = 0;
	
	while(el != null) {
  		iPos += el["offset" + sProp];
		el = el.offsetParent;
	}
  
	return iPos;
}

/**
	This method displays the element at popUpName with respect
	to the element at referenceName.
		referenceName - the element to use as a reference for where to
						display the pop-up element.
		popUpName - the element to be displayed as a pop-up.
		returns - null
*/
function show(referenceName, popUpName) {
	reference = document.getElementById(referenceName);
	popUp = document.getElementById(popUpName);

	if(popUp) {
    	popUp.style.display = 'inline';
	    popUp.style.pixelLeft = getPos(reference, "Left") + 5;
    	popUp.style.pixelTop = getPos(reference, "Top") + 0;
	}
  
	if((popUp != currentPopUp) && currentPopUp) {
    	currentPopUp.style.display = 'none';
	}

	currentPopUp = popUp;
}

/**
	This method does the same as the above show(a, b) method,
	except it will also hide all <select> drop-down menus on
	the page so they do not overlap the popup box.
*/
function showWOSelectBoxes(referenceName, popUpName) {
	var dropDowns = document.getElementsByTagName("select");
	for(var i = 0; i < dropDowns.length; i++) {
		dropDowns[i].style.display = "none";
	}
	
	show(referenceName, popUpName);
}

/**
	This method will hide all pop-up elements on the page.
		el - Element to hide (this parameter is not needed, but
			 was left in in case multiple pop-ups need to be displayed
			 and only certain ones hidden).
		returns - null
*/
function hide(el) {
	show(null);
}

/**
	This method does the same as the above hide(a) method,
	except it will also re-show all <select> drop-down menus
	that were hidden by the showWOSelectBoxes(a, b) method.
*/
function hideWOSelectBoxes(el) {
	var dropDowns = document.getElementsByTagName("select");
	for(var i = 0; i < dropDowns.length; i++) {
		dropDowns[i].style.display = "inline";
	}
	
	hide(el);
}

function PopUp(x,y,z) {
	var desc=x;
	var image=y;
	var queryStr=z;
	var winpop = "<html>\n<head>\n";
	winpop += "<title>" + desc + "</title>";
	winpop += "</head><body>";
	winpop += "<h2>" + desc + "</h2><br>";
	winpop += "<img src='" + image + "'>";
	winpop += "</body></html>";
	winpopup=window.open('',"MyPopup",'toolbar=false');
	winpopup.document.open() // start of popup window
	winpopup.document.write (winpop) // writes html in the page
	winpopup.document.close() // ends of popup window
	winpopup.focus() //brings popup window to the top. 
}
