var text;

var arrItems = new Array();

var message_array = new Array(2);
message_array[0] = "We hope to make this website available to you in your own language someday. We therefore request that you tell us your language preferences";

currentIndx=0;

sideImages=new Array();

sideImages[0]='images/archiesmadhouse.jpg';

sideImages[1]='images/carol.jpg';

sideImages[2]='images/gruffalo.jpg';

sideImages[3]='images/TomJerry.jpg';

sideImages[4]='images/covers.jpg';

sideImages[5]='images/1885003889.jpg';

sideImages[6]='images/m_TRUST.jpg';

sideImages[7]='images/lglp0788.gif';

sideImages[8]='images/lglp0617.jpg';

imagesPreloaded = new Array(9);

for (var i = 0; i < sideImages.length ; i++) {

	imagesPreloaded[i] = new Image(175,225)

	imagesPreloaded[i].src=sideImages[i]

}

function newImage() {

// Makes a random, whole number between 0 and 3

	//currentIndx=Math.round(Math.random()*7)
	//if(document.theImage) document.theImage.src=imagesPreloaded[currentIndx].src
}

function openLogo()
{
var attributes = 'toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars=1,resizable=1,width=550,height=600,left=0,top=0';
sealWin=window.open('http://www.ccavenue.com/verifySeal.jsp?ClientID=M_dogearse_4626','win',attributes);
self.name = 'mainWin';
}

String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

function resizeScreen() {
	
	var winW = 630, winH = 460;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
		winW = window.innerWidth-16;
		winH = window.innerHeight-16;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		winW = document.body.offsetWidth-20;
		winH = document.body.offsetHeight-20;
		}
	}
	//alert('winW = '+winW+' and winH='+winH);
	window.resizeTo(winW,winH);
}

function showUserInfo(userID)
{
var attributes = 'toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars=1,resizable=0,width=500,height=500,left=0,top=0';
sealWin=window.open('userInfo.jsp?userID='+userID ,'win',attributes);
self.name = 'mainWin';
}

function showPostageInfo(countryID)
{
var attributes = 'toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars=1,resizable=0,width=760,height=500,left=0,top=0';
sealWin=window.open('postageInfo.jsp?countryID='+countryID ,'win',attributes);
self.name = 'mainWin';
}

function openModal(url) {

var sFeatures = "width=780,height=550,menubar=0,status=0,location=0,toolbar=0,scrollbars=1,resizable=0";
var win = window.open(url, 'openmodal', sFeatures);
}

function speakToUser(messageIndex) {
	
	text =  "<html>\n<head>\n<title>User Assist</title>\n<body>\n";
	text += message_array[messageIndex];
	text += "</body>\n</html>\n";
	setTimeout('windowProp(text)', 500); 		// delay 0.5 seconds before opening
}

function windowProp(text) {
newWindow = window.open('','newWin','width=300,height=40');
newWindow.document.write(text);
setTimeout('closeWin(newWindow)', 8000);	// delay 5 seconds before closing
}

function closeWin(newWindow) {
newWindow.close();				// close small window and depart
}

function hideElement(elementName){

	var element = document.getElementById(elementName);
	element.style.visibility="visible";
}

function changeLabels(){

	var element;

	switch(parseInt(document.all.selItemType.value)) {
		
		case 2:	alert('audiovisuals');
				element = document.getElementById('divISBN');
				element.style.visibility="hidden";
				element = document.getElementById('divYOR');
				element.style.visibility="visible";
				break;
		case 3:alert('movies');break;
		default:break;
	
	}
}

function calculateInsurance(){

	var totalCost = parseInt(document.frmItems.totalCost.value);
	
	var insureAmt = 0.0;
	
	if(document.frmItems.cinsure.checked){
		
		insureAmt = (totalCost/100)*2.67;
		insureAmt = Math.round(insureAmt*100)/100;
		totalCost = totalCost + insureAmt;
		
	} else {
	
		insureAmt = 0.0;
		totalCost = totalCost + insureAmt;
	}
	
	document.frmItems.insureCharge.value = insureAmt;
	getTotalCost();

}

function getTotalCost() {

	//this function checks if the buyer has opted to pay by credit card
	//and, if so, adds a 2% surcharge
	
	var totalCost = parseInt(document.frmItems.totalCost.value)
					+parseInt(document.frmItems.insureCharge.value);
	var ccSurcharge = 0.0;
	var payMode = document.frmItems.selBuyPay.options[document.frmItems.selBuyPay.selectedIndex].value;
	if(payMode=='853') {
		ccSurcharge = Math.round(0.02*totalCost*100)/100;
		document.frmItems.ccSurcharge.value = ccSurcharge;
		totalCost = totalCost + ccSurcharge;
	} else {
		ccSurcharge = 0.0;		
		document.frmItems.ccSurcharge.value = ccSurcharge;
		totalCost = totalCost + ccSurcharge;
	}
	var ccsDiv = document.getElementById('divCCS');
	ccsDiv.innerHTML = "Credit Card Surcharge : Rs. "+ccSurcharge;
	var tcDiv = document.getElementById('divTC');
	tcDiv.innerHTML = "Total Cost of your purchases : Rs. "+totalCost;
}

function getShippingCost(element){
	
	//This function arrives at the total cost of the item by obtaining the shipping cost
	//and adding it to the asking price of the item
	
	var elementName = element.name;
	var elementPrefix = elementName.substring(elementName.indexOf('_')+1, elementName.length);
	//alert(elementPrefix);
	var selectedShipping = element.options[element.selectedIndex].text;
	var shippingCost = parseInt(selectedShipping.substring(selectedShipping.indexOf('. ')+1, selectedShipping.length-1));
	//alert(shippingCost);
	var itemCost = parseInt(document.getElementById('itemCost_'+elementPrefix).value);
	//alert(itemCost);
	var totalCost = itemCost + shippingCost;
	//alert(totalCost);
	var tCostDiv = document.getElementById('tCostDiv_'+elementPrefix);
	//alert(tCostDiv);
	tCostDiv.innerHTML = "<b>Total Price of Item:</b> Rs. "+totalCost;
	var htotalCost = document.getElementById('totalCost_'+elementPrefix);
	htotalCost.value = totalCost;
	//alert(htotalCost.value);
}

function checkEmail(){
	var emailMsg = document.frmEmail.txtEmailMsg.value;
	var emailDetected;
	emailDetected = false;
	if(emailMsg.indexOf('@')> 0
		|| emailMsg.indexOf('hotmail')> -1
		|| emailMsg.indexOf('gmail')> -1
		|| emailMsg.indexOf('rediffmail')> -1
		|| emailMsg.indexOf('yahoo')> -1
		|| emailMsg.indexOf('.com')> -1
		|| emailMsg.indexOf('[at]')> -1
		|| emailMsg.indexOf('[dot]')> -1
		|| emailMsg.indexOf('indiatimes')> -1
		|| emailMsg.indexOf('rediff')> -1
		|| emailMsg.indexOf('email')> -1
		|| emailMsg.indexOf('hot male')> -1) {
		
			emailDetected = true;
		}
	if(emailDetected) {
		alert("An attempt to contact this user by bypassing Dogears Etc. has been detected.\nPlease modify your message");
	} else {
		document.frmEmail.submit();
	}
}

function getReqSearches() {
	
	document.frmReqSrch.submit();
}

function validateAnswer(){

	var sName = "";
	var sBook = "";
	var sText = "";
	
	var errorMsg = "";
	
	sName = document.frmQ.answer_user.value;
	if(sName=='') 
		errorMsg += "\n- your name";
		
	sBook = document.frmQ.answer_book.value;
	if(sBook=='') 
		errorMsg += "\n- the name of the book";

	sText = document.frmQ.answer_text.value;
	if(sText=='') 
		errorMsg += "\n- the description of the book";
		
	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {

		document.frmQ.submit();
	}	
}

function validateRegistration() {
	
	var sPass = "";
	var sPassConf = "";
	var sName = "";
	var sAdd = "";
	var sLand = "";
	var sEmail = "";
	var sTel = "";
	
	var errorMsg = "";
	
	sName = document.frmReg.txtName.value;
	if(sName=='') 
		errorMsg += "\n- Your Name";

	sAdd = document.frmReg.txtAddress.value;
	if(sAdd=='') 
		errorMsg += "\n- Your Address";

	sLand = document.frmReg.txtLand.value;
	if(sLand=='') 
		errorMsg += "\n- The Nearest Landmark";

	sTel = document.frmReg.txtTelNo.value;
	if(sTel=='') 
		errorMsg += "\n- Your Tel/Mobile No.";

	sEmail = document.frmReg.txtEmail.value;
	if(sEmail==''||echeck(sEmail)==false) 
		errorMsg += "\n- A valid E-mail Address";

	if(document.frmReg.txtUsrPass){
		
		sPass = document.frmReg.txtUsrPass.value;
		sPassConf = document.frmReg.txtConfirm.value;
		
		if(sPass=='' || sPass!=sPassConf)
			errorMsg += "\n- Password";
	}
	
	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {
		
		if(!document.frmReg.chkDisc.checked){
			
			alert('You must agree to the User Agreement before being registered.');
			//return false;
			
		} else {
					
			document.frmReg.submit();
			
		}
	
	}
	
}

function goBuy() {
		
	var payMode = document.frmItems.selBuyPay.options[document.frmItems.selBuyPay.selectedIndex].value;
	if(payMode=='-1') {
		alert('Please choose a mode of payment.');
	} else {
		document.all.frmItems.submit();
	}	
}

function validateChange() {
	
	var sLogin = "";
	var sOldPass = "";
	var sNewPass = "";
	var sPassConf = "";

	var errorMsg = "";
	
	sLogin = document.frmChng.user_login.value;
	if(sLogin==''||echeck(sLogin)==false) 
		errorMsg += "\n- Your User Login [email id]";

	sOldPass = document.frmChng.old_password.value;
	if(sOldPass=='') 
		errorMsg += "\n- Your Old Password";

	sNewPass = document.frmChng.new_password.value;
	if(sNewPass=='') 
		errorMsg += "\n- Your New Password";

	sPassConf = document.frmChng.confirm_new.value;
	if(sPassConf=='') 
		errorMsg += "\n- Your Password Confirmation";

	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {
		
			document.frmChng.submit();
	}
	
}

function changeAction(frmName, frmAction){
	
	alert('The page will reload to make sub-categories available.\nClick on the button below to proceed.');
	var formElement = eval(frmName);
	formElement.action = frmAction;
	//alert('here now');
	formElement.submit();

}

function requestItem() {

	var sName = "";	
	var category = "";
	var subcat = "";
	var lang = "";
	var cond = "";
	var price = "";
	
	category = document.frmReq.selCat.options[document.frmReq.selCat.selectedIndex].value;
	subcat = document.frmReq.selSubCat.options[document.frmReq.selSubCat.selectedIndex].value;
	lang = document.frmReq.selLang.options[document.frmReq.selLang.selectedIndex].value;
	cond = document.frmReq.selCondition.options[document.frmReq.selCondition.selectedIndex].value;
	
	price = document.frmReq.txtPrice.value;
	
	var errorMsg = "";
	
	sName = document.frmReq.txtTitle.value;
	if(sName==''||sName.length<=1) 
		errorMsg += "\n- Title";
	
	/*
	if(category=='-1') 
		errorMsg += "\n- Item Category";
		
	if(subcat=='-1') 
		errorMsg += "\n- Item Sub-Category";
		
	if(lang=='-1') 
		errorMsg += "\n- Language of Item";
	*/
	
	if(cond=='-1') 
		errorMsg += "\n- Condition of Item";
	
	if(price=='0.0'||price=='') 
		errorMsg += "\n- Price Offered";
	
	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		
	} else {
		
			document.frmReq.submit();
			
	}
	
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

 		 return true;					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

function getTitles(firstAlpha) {
	document.frmAlpha.first_alpha.value=firstAlpha;
	document.frmAlpha.search_type.value='1';
	document.frmAlpha.submit();
}

function getAuthors(firstAlpha) {
	document.frmAlpha.first_alpha.value=firstAlpha;
	document.frmAlpha.search_type.value='2';
	document.frmAlpha.submit();
}

function getBooksFor(firstAlpha) {
	document.frmPub.first_alpha.value=firstAlpha;
	document.frmPub.search_type.value='3';
	document.frmPub.submit();
}

function validateBrowse() {
	
	var sTitle = "";
	var sISBN = "";
	var sAuth = "";
	var sLang = "";
	var sKeys = "";
	
	if(document.frmBrowse.txtTitle)	{
		sTitle = document.frmBrowse.txtTitle.value;
	}
	
	if(document.frmBrowse.txtISBN)	{
		sISBN = document.frmBrowse.txtISBN.value;
	}
	
	if(document.frmBrowse.txtAuthor)	{
		sAuth = document.frmBrowse.txtAuthor.value;
	}
	
	if(document.frmBrowse.txtKeyword)	{
		sKeys = document.frmBrowse.txtKeyword.value;
	}
	
	if(document.frmBrowse.selLang)	{
		sLang = document.frmBrowse.selLang.options[document.frmBrowse.selLang.selectedIndex].value;
	}
	
	/*
	if(document.frmBrowse.selCat)	{
		sCat = document.frmBrowse.selCat.options[document.frmBrowse.selCat.selectedIndex].value;
	}
	
	if(document.frmBrowse.selSubCat)	{
		sSub = document.frmBrowse.selSubCat.options[document.frmBrowse.selSubCat.selectedIndex].value;
	}
	 && sLang=='-1' && sCat=='-1' && sSub=='-1'
	*/
	if(sTitle=='' && sISBN=='' && sAuth=='' && sKeys=='' && sLang=='-1'){ 
	
		alert('Please enter at least one value');
		
	} else {
		
		document.frmBrowse.submit();
				
	}
}

function sendEmail() {
	
	var sTo = "";
	var sFrom = "";
	var sText = "";
	
	var errorMsg = "";
	
	sTo = document.frmReco.txtEmailTo.value;
	if(sTo==''||echeck(sTo)==false) 
		errorMsg += "\n- A Valid \'To\' Address";

	sFrom = document.frmReco.txtSender.value;
	if(sFrom==''||echeck(sFrom)==false) 
		errorMsg += "\n- A Valid  \'From\' Address";

	sText = document.frmReco.txtEmailMsg.value;
	if(sText=='') 
		errorMsg += "\n- Email Text";

	
	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {
		
		document.frmReco.submit();
				
	}
}

function contactDE() {
	
	var sText = "";
	var sFrom = "";	
	var errorMsg = "";
	
	sFrom = document.frmContact.txtSender.value;
	if(sFrom==''||echeck(sFrom)==false) 
		errorMsg += "\n- A Valid \'From\' Address";

	sText = document.frmContact.txtEmailMsg.value;
	if(sText=='') 
		errorMsg += "\n- Email Text";

	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {
		
		
		document.frmContact.submit();
				
	}
}

function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
 
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}

/*==========Navigation Functions============*/

function goHome(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'home';//ACTION_HOME
	formElement.subaction.value = '';
	formElement.submit();
}

function contactUs(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'contact';//ACTION_CONTACT
	formElement.submit();
}

function enterRegInfo(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'register';//ACTION_REGISTER
	formElement.submit();
}

function showDisclaimer(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'disclaimer';//ACTION_DISC
	formElement.subaction.value = 'terms_conditions';//SUBACTION_TERM_COND
	formElement.submit();
}

function showUserAgree(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'disclaimer';//ACTION_DISC
	formElement.subaction.value = 'user_agreement';//SUBACTION_USER_AGR
	formElement.submit();
}

function showPrivPolicy(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'disclaimer';//ACTION_DISC
	formElement.subaction.value = 'privacy_policy';//SUBACTION_PRIV_POL
	formElement.submit();
}

function showSecurity(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'disclaimer';//ACTION_DISC
	formElement.subaction.value = 'security';//SUBACTION_SECURITY
	formElement.submit();
}

function about(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'about_us';//ACTION_ABOUT_US
	formElement.submit();
}

function reports(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'reports';//ACTION_REPORTS
	formElement.subaction.value = 'form';//SUBACTION_FORM
	formElement.submit();
}

function faq(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'faq';//ACTION_FAQ
	formElement.subaction.value = 'form';//SUBACTION_FORM
	formElement.submit();
}

function quickFaq(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'faq';//ACTION_FAQ
	formElement.subaction.value = 'process';//SUBACTION_PROCESS
	formElement.submit();
}

function browse(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'browse';//ACTION_BROWSE
	formElement.submit();
}

function sell(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'sell';//ACTION_SELL
	formElement.submit();
}

function sellMult(formName)
{
	var formElement = eval(formName);
	formElement.action.value = 'sell';//ACTION_SELL
	formElement.subaction.value = 'multiple';//SUBACTION_MULT
	formElement.submit();
}

function request(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'request';//ACTION_REQUEST
	formElement.submit();
}

function viewRequest(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'request_list';//ACTION_LIST
	formElement.submit();
}

function recommend(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'recommend';//ACTION_RECOMMEND
	formElement.submit();
}

function recommendThisBook(bookID) {
	document.frmItems.action.value = 'recommend';//ACTION_RECOMMEND
	document.frmItems.subaction.value = 'form';//SUBACTION_FORM
	document.frmItems.resource_id.value = bookID;
	document.frmItems.submit();
}

function viewForum(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'forum';//ACTION_FORUM
	formElement.subaction.value = 'view_category';//SUBACTION_VIEW_CAT
	formElement.submit();
}

function viewTopics(formName, topicID) {
	
	var formElement = eval(formName);
	formElement.action.value = 'forum';//ACTION_FORUM
	formElement.subaction.value = 'view_topic';//SUBACTION_VIEW_TOPIC
	formElement.category_id.value = topicID;
	formElement.submit();
}

function viewThread(formName, threadID) {
	
	var formElement = eval(formName);
	formElement.action.value = 'forum';//ACTION_FORUM
	formElement.subaction.value = 'view_thread';//SUBACTION_VIEW_THREAD
	formElement.thread_id.value = threadID;
	formElement.submit();
}

function notify(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'notify';//ACTION_NOTIFY
	formElement.submit();
}

function catalogBooks(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'catalog';//ACTION_CATALOG
	formElement.subaction.value = 'show';//SUBACTION_SHOW	
	formElement.submit();
}

function catalogItem() {

	var itemType = document.frmCatalog.selItemType.options[document.frmCatalog.selItemType.selectedIndex].value;
	
	var errorMsg = "";
	
	//Strip ISBN of dashes
	var isbn = document.frmCatalog.txtISBN.value;
	
	if(itemType=='833') {
		//following validation only for books
				
		if(isbn=='') {
			
			errorMsg += "\n- A Valid ISBN";
			//return false;
		} else {
			//alert(isbn);
			isbn = stripDashes(isbn);
			//alert(isbn);
			document.frmCatalog.txtISBN.value = isbn;
		}
		
	}
	
	var itemName = document.frmCatalog.txtTitle.value;
	if(itemName=='') 
		errorMsg += "\n- Title";
		
	var publisher = document.frmCatalog.txtPub.value;
	if(publisher=='') 
		errorMsg += "\n- Publisher";
		
	var yop = document.frmCatalog.txtYOP.value;
	if(yop=='') 
		errorMsg += "\n- Year of Publication";
	
	var auth1 = document.frmCatalog.txtAuthor1.value;
	var auth2 = document.frmCatalog.txtAuthor2.value;
	var auth3 = document.frmCatalog.txtAuthor3.value;
	if(auth1==''&auth2==''&auth3=='') 
		errorMsg += "\n- Author";
		
	var itemDesc = document.frmCatalog.txtDesc.value;
	if(itemDesc=='') 
		errorMsg += "\n- Description of Item";
		
	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {
	
		//document.frmSell.subaction.value='cancel';//SUBACTION_CANCEL
		document.frmCatalog.submit();
		
	}
}

function cancelCatalog() {

	document.frmCatalog.action.value = 'catalog';//ACTION_CATALOG
	document.frmCatalog.subaction.value = 'cancel';//SUBACTION_CANCEL
	formElement.submit();
}

function partner(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'partner';//ACTION_PARTNER
	formElement.submit();
}

function question(formName) {

	var formElement = eval(formName);
	formElement.action = "/servlet/AppControl.MiscServlet";
	formElement.action.value = 'answer';//ACTION_ANSWER
	formElement.subaction.value = 'list';//SUBACTION_LIST
	formElement.submit();
}

function viewGradClub(formName) {

	var formElement = eval(formName);
	formElement.action = "/GradControlServlet";
	formElement.action.value = 'grad_club';//ACTION_GRADCLUB
	formElement.subaction.value = 'show';//SUBACTION_SHOW
	formElement.submit();
}

function loginUser(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'login';//ACTION_LOGIN
	formElement.subaction.value = 'view';//SUBACTION_VIEW
	formElement.submit();
}

function logOff(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'log_out';//ACTION_LOGOUT
	formElement.submit();
}

function submitRegInfo(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'register';//ACTION_REGISTER
	formElement.subaction.value = 'submit';//SUBACTION_SUBMIT
	formElement.submit();
}

function cancelRegInfo(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'register';//ACTION_REGISTER
	formElement.subaction.value = 'cancel';//SUBACTION_CANCEL
	formElement.submit();
}

function validateRegForm(formName){

	var formElement = eval(formName);
	var password = formElement.txtUsrPass.value;
	var confirmp = formElement.txtConfirm.value;
	
	if (!password.equals(confirmp)) {
		alert('passwords do not match');
		//return false;
	}
	
}

function submitValidn(formName) {

	var formElement = eval(formName);
	formElement.action.value = 'login';//ACTION_LOGIN
	formElement.subaction.value = 'submit';//SUBACTION_SUBMIT
	formElement.submit();
}

function proceedSale(){
	
	var itemType = document.frmSell.selItemType.options[document.frmSell.selItemType.selectedIndex].value;
	
	var errorMsg = "";
	
	//Strip ISBN of dashes
	var isbn = document.frmSell.txtISBN.value;
	
	if(itemType=='833') {
		//following validation only for books
				
		if(isbn=='') {
			
			errorMsg += "\n- A Valid ISBN";
			//return false;
		} else {
			//alert(isbn);
			isbn = stripDashes(isbn);
			//alert(isbn);
			document.frmSell.txtISBN.value = isbn;
		}
		
	}
	
	var itemName = document.frmSell.txtTitle.value;
	if(itemName==''||itemName.length<=1) 
		errorMsg += "\n- Title";
		
	var publisher = document.frmSell.txtPub.value;
	if(publisher=='') 
		errorMsg += "\n- Publisher";
		
	var yop = document.frmSell.txtYOP.value;
	if(yop=='') 
		errorMsg += "\n- Year of Publication";
	
	var auth1 = document.frmSell.txtAuthor1.value;
	var auth2 = document.frmSell.txtAuthor2.value;
	var auth3 = document.frmSell.txtAuthor3.value;
	if(auth1==''&auth2==''&auth3=='') 
		errorMsg += "\n- Author";
		
	var itemCond = document.frmSell.selCondition.options[document.frmSell.selCondition.selectedIndex].value;
	if(itemCond=='-1') 
		errorMsg += "\n- Condition of Item";
		
	var itemDesc = document.frmSell.txtDesc.value;
	if(itemDesc=='') 
		errorMsg += "\n- Description of Item";
		
	var price = document.frmSell.txtPrice.value;
	if(price=='0.0'||price=='') 
		errorMsg += "\n- Asking Price";
		
	if(errorMsg!='') {
		errorMsg = "You have to add the following information before proceeding:" + errorMsg;
		alert(errorMsg);
		//return false;	
		
	} else {
	
		//document.frmSell.subaction.value='cancel';//SUBACTION_CANCEL
		document.frmSell.submit();
		
	}
}

function proceedSales(){
	
	var errorMsg = "";
	var elementTitle;
	var elementAuthor;
	var elementWeight;
	var elementDesc;
	var elementPrice;
	var elementCond;
	
	var sTitle = "";
	var sAuthor = "";
	var sWeight = "";
	var sDesc = "";
	var sPrice = "";
	var itemCond = "";

	for(var i=0; i< 10;i++) {
		
		elementTitle = document.getElementById('bookName_'+i);
		sTitle = elementTitle.value.trim();
		
		elementAuthor = document.getElementById('author_'+i);
		sAuthor = elementAuthor.value.trim();
		
		elementWeight = document.getElementById('weight_'+i);
		sWeight = elementWeight.value.trim();
		
		elementDesc = document.getElementById('sBookDesc_'+i);
		sDesc = elementDesc.value.trim();
		
		elementPrice = document.getElementById('sAskingPrice_'+i);
		sPrice = elementPrice.value.trim();
		
		elementCond = document.getElementById('selCondition_'+i);
		itemCond = elementCond.options[elementCond.selectedIndex].value;
		
		if(sTitle!="") {
			
			//errorMsg += sTitle + " - " + sAuthor + " - " + itemCond + " - " + sDesc + " - " + sPrice + " - ";
		
			if(sAuthor=='' || itemCond=='-1' || sDesc=='' || sPrice=='0.0' || sPrice=='0') {
				errorMsg += "For the item titled \'"+ sTitle +"\' please ensure that the following information is added:\n";
				errorMsg += "a] The author(s)/artist(s)\n";
				errorMsg += "b] The condition of the item (\'Good\' is recommended)\n";
				errorMsg += "c] The description of the item\n";
				errorMsg += "d] The price you wish to quote\n";				
			}
				
		}

		
		
	}
		
	
	if(errorMsg!='') {
		alert(errorMsg);
		//return false;	
		
	} else {
	
		//document.frmSell.subaction.value='cancel';//SUBACTION_CANCEL
		document.frmSell.submit();
		
	}
}

function stripDashes(inputISBN) {
	
	while (inputISBN.search("-") != -1) {
		inputISBN = inputISBN.replace("-","");
	}
	/*
	if (isNaN(inputISBN)) {
		//alert("not a number");
		//return false;
	}
	*/
	return inputISBN;
}

function removeDashes() {

		var isbn = "";
		isbn = stripDashes(document.frmBrowse.txtISBN.value);
		document.frmBrowse.txtISBN.value = isbn;
}


function cancelSale(){
	
	document.frmSell.subaction.value='cancel';//SUBACTION_CANCEL
	document.frmSell.submit();
}

function cancelReq(){
	
	document.frmReq.subaction.value='cancel';//SUBACTION_CANCEL
	document.frmReq.submit();
}

function getItemDetails(itemID){
	
	document.frmSrchRslt.item_id.value=itemID;
	document.frmSrchRslt.submit();
	
}

function getRandomDetails(itemID){
	
	document.frmRndmBks.item_id.value=itemID;
	document.frmRndmBks.submit();
	
}

function addToCart(itemID){
	
	document.frmItems.resource_id.value=itemID;
	document.frmItems.submit();
	
}

function viewCart(formName){
	
	var formElement = eval(formName);
	formElement.action.value = 'cart';//ACTION_CART
	formElement.submit();
}

function getSales(formName){
	
	var formElement = eval(formName);
	formElement.subaction.value='sales';//SUBACTION_SELL
	formElement.submit();
}

function getPurchases(formName){
	
	var formElement = eval(formName);
	formElement.subaction.value='purchases';//SUBACTION_BUY
	formElement.submit();
}

function repriceItems(formName){
	
	var formElement = eval(formName);
	formElement.subaction.value='reprice';//SUBACTION_REPRICE
	formElement.submit();
}

function changeCode(formName){
	
	var formElement = eval(formName);
	formElement.subaction.value='pass_chng';//SUBACTION_PASS_CHNG
	formElement.submit();
}

function emailPass(formName){
	
	var formElement = eval(formName);
	
	var userLogin = "";
	userLogin = formElement.user_login.value;
	
	if(userLogin==''||echeck(userLogin)==false) {
		
		alert('Please enter a valid email address');
		formElement.user_login.focus();
		
	} else {
		
		formElement.action.value='account';//ACTION_ACCT
		formElement.subaction.value='pass_chng_email';//SUBACTION_PASS_CHNG_EML
		formElement.submit();
		
	}

}

function getMessages(formName){
	
	var formElement = eval(formName);
	formElement.subaction.value='inbox';//SUBACTION_INBOX
	formElement.submit();
}

function cancelForm(formName){
	
	var formElement = eval(formName);
	formElement.subaction.value='cancel';//SUBACTION_CANCEL
	formElement.submit();
}

function contactSeller(formName,resourceID){

	var formElement = eval(formName);
	formElement.action.value = 'cart';//ACTION_CART
	formElement.subaction.value = 'email';//SUBACTION_EMAIL
	formElement.resource_id.value = resourceID;
	formElement.submit();
}

function checkPwd() {

	var pass = document.frmReg.txtUsrPass.value;
	var conf = document.frmReg.txtConfirm.value;
	
	if(pass!=conf){
		alert('The passwords you have entered do not match');
		document.frmReg.txtConfirm.focus();
	}
}

function compareCodes(formName){
	
	var formElement = eval(formName);

	var pass = formElement.new_password.value;
	var conf = formElement.confirm_new.value;
	
	if(pass!=conf){
		alert('The passwords you have entered do not match');
		formElement.confirm_new.focus();
	}
}

function checkPostage(){

	/*
	var noOfItems;
	var elementAction;
	var elementPost;
	var post;
	var act;
	var goNoGo = '1';
	noOfItems = parseInt(document.frmItems.itemCount.value);
	for(var i=0; i<noOfItems;i++) {
		elementAction = document.getElementById('selCartActn_'+i);
		elementPost = document.getElementById('selPost_'+i);
		act = parseInt(elementAction.options[elementAction.selectedIndex].value);
		post = parseInt(elementPost.options[elementPost.selectedIndex].value);
		if(act==857 && post==-1) goNoGo = '0';
	}
	if(goNoGo == '0') {
		alert('Please select postage for the item you wish to buy');
	} else {
		document.all.frmItems.submit();
	}
	*/
	document.all.frmItems.submit();
}

/*===============================================*/

var isVisible=0;

function listItem(itemGroup, itemValue, itemText){
this.itemGroup=itemGroup;
this.itemValue=itemValue;
this.itemText=itemText;
}

function replyInboxMsg(){
	
	if(document.frmMsgs.replyTo.value==''){
		alert('Choose any message to reply to');
	} else if(document.frmMsgs.replyTo.value==''){
		alert('Please type in a message');		
	} else {
		document.frmMsgs.submit();
	}
}

function getCatalogs() {
	
	document.all.frmVmenu.action="/servlet/AppControl.CatalogServlet";
	document.all.frmVmenu.action.value="catalog";//ACTION_CATALOG
	document.all.frmVmenu.subaction.value="list";//SUBACTION_SUBMIT
	document.all.frmVmenu.submit();
}

function getTaggedItems(tagID) {
	
	document.all.frmHmenu.action="/servlet/AppControl.MiscServlet";
	document.all.frmHmenu.action.value="tags";//ACTION_TAGS
	document.all.frmHmenu.subaction.value="submit";//SUBACTION_LIST
	document.all.frmHmenu.tempID.value=tagID;
	document.all.frmHmenu.submit();
}

function getBooksBy(authorName){

	var aName = "";
	var aNameArray;
	authorName = authorName.trim();

	if(authorName.indexOf(",")==-1) {
		aName = authorName;
	} else {
		aNameArray = authorName.split(",");
		aName = aNameArray[1].trim() + " " + aNameArray[0].trim();	
	}
	document.all.frmBrowse.txtAuthor.value=aName;
	document.all.frmBrowse.submit();
}

function prepareForReply(msgString){
	//used while replying to messages in inbox
	//msgString comes in the format(<=emailFrom>, <=emailID>)
	document.frmMsgs.replyTo.value=msgString.substr(0,msgString.indexOf(','));
	//alert(document.frmMsgs.replyTo.value);
	var msgID = msgString.substr(msgString.indexOf(',')+1, msgString.length);
	var element = document.getElementById("subj_"+msgID);
	document.frmMsgs.txtSubj.value = "Re:"+element.value;
}

function populateSubList(groupID, elementName){
	//this block clears the current listings in the second dropdown, if the dropdown has any
	objSub = document.getElementById(elementName);
	objSub.selectedIndex=0;
	isVisible=0;
	if(objSub.options.length>1){
	   for (x=objSub.options.length; x>0; x--){
	        objSub.options[x]=null;
	   }
	}
	//this block populates the second drop down, by matching the selected value of dropdown 1
	//to the lookup value of the list items
	for(x=0; x < arrItems.length; x++){
	   if(arrItems[x].itemGroup==groupID){
	        listOpt = document.createElement("option") ;
	        listOpt.value = arrItems[x].itemValue ;
	        listOpt.text = arrItems[x].itemText ;
	        try {
	        	
		        objSub.add(listOpt,null) ;
		        
        	}catch (ex) {
	        
	        	objSub.add(listOpt);
        	}	 
	   }
	}

}
