show = function(childnode,leaf){
  if(document.getElementById(childnode).style.display == 'none'){
  		document.getElementById(childnode).style.display='';
  		leaf.src="\\images\\minus.gif" 
  }else{
  		document.getElementById(childnode).style.display='none';
  		leaf.src="\\images\\plus.gif"  
  }
}


hide = function(divname){
document.getElementById(divname).style.display='none';
}
preview=function(){
	  var previewhtml="";
		var preview_table = document.getElementById('preview_table');
		preview_table.width="100%"
		preview_table.className="msgborder"
		preview_table.style.display='';
		
		this.deleteTable('preview_table');	
		var j=0;		
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
       	td.innerHTML="<b>Preview of Paarayana Books selected :</b>";
		td.className="previewtitle";   
		var bookfields = document.body.getElementsByTagName("input");			  
		var hasBooks = false;
		for(var i=0;i<bookfields.length;i++){
			if(bookfields[i].type == "text"){
			     if(bookfields[i].id !="FirstName" && bookfields[i].id !="LastName" && bookfields[i].id !="Email" && bookfields[i].id !="Phone"  && bookfields[i].id !="Address1" && bookfields[i].id !="Address2" && bookfields[i].id !="City" && bookfields[i].id !="State" && bookfields[i].id !="ZipCode" && bookfields[i].id !="BillCountry"&& bookfields[i].id !="ShipCountry"){
					if(	bookfields[i].value != ""){
						j++;
						hasBooks = true;					
						var row = preview_table.insertRow(j);
						var td = row.insertCell(0);
						td.className="langtitle";
						td.innerHTML = " <b> "+bookfields[i].name +" </b>: "+bookfields[i].value;;
	
					}
			     }
			}
		}
		if(hasBooks == true){document.getElementById('preview_table').focus();}
}

deleteTable=function(tableId){
		var tableObj = document.getElementById(tableId);
		var rowCount = tableObj.rows.length;    
		while(rowCount > 0)
		{  
			var j=0;
			if(j != rowCount)
			{
			tableObj.deleteRow(j);
			j++;
			}
			rowCount--;
		}	
}

copyBilling = function(obj){
    if(obj.checked){
	document.orderform.ShipAddress1.value  = document.orderform.BillAddress1.value ;
	document.orderform.ShipAddress2.value  = document.orderform.BillAddress2.value ;
	document.orderform.ShipCity.value  = document.orderform.BillCity.value ;
	document.orderform.ShipState.value  = document.orderform.BillState.value ;
	document.orderform.ShipCountry.options[document.orderform.BillCountry.options.selectedIndex].selected = true;
	document.orderform.ShipZipcode.value  = document.orderform.BillZipcode.value ;
    }else {
	document.orderform.ShipAddress1.value  = "";
	document.orderform.ShipAddress2.value  = "";
	document.orderform.ShipCity.value  = "";
	document.orderform.ShipState.value  = "";
	document.orderform.ShipCountry.options[0].selected = true;
	document.orderform.ShipZipcode.value  = "";
    }
}

previewContact=function(){
	  var previewhtml="";
		var preview_table = document.getElementById('contact_table');
		preview_table.width="100%"
		preview_table.className="msgborder"
		preview_table.style.display='';
		
		this.deleteTable('contact_table');	
		var j=0;		
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
       		td.innerHTML="<b> Preview of Address-Contact Details :</b>";
		td.className="previewtitle";   
		j++;
		if(document.orderform.FirstName.value != "" ){
			var row = preview_table.insertRow(j);
			var td = row.insertCell(0);
			td.className="langtitle";
			td.innerHTML = " <b> FirstName :</b> "+document.orderform.FirstName.value ;
			j++;
		}
		if(document.orderform.LastName.value != "" ){
			var row = preview_table.insertRow(j);
			var td = row.insertCell(0);
			td.className="langtitle";
			td.innerHTML = " <b> LastName : </b> "+document.orderform.LastName.value ;
			j++;
		}
		if(document.orderform.Email.value != "" ){
			var row = preview_table.insertRow(j);
			var td = row.insertCell(0);
			td.className="langtitle";
			td.innerHTML = " <b> Email: </b>"+document.orderform.Email.value ;
			j++;
		}
		if(document.orderform.Phone.value != "" ){
		
			var row = preview_table.insertRow(j);
			var td = row.insertCell(0);
			td.className="langtitle";
			td.innerHTML = " <b> Phone: </b>"+document.orderform.Phone.value ;
			j++;
		}
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = " <b> Billing Address </b> ";
		j++;
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = document.orderform.BillAddress1.value 
		j++;
		
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = document.orderform.BillAddress2.value 
		j++;
		if(document.orderform.BillCity.value != "" || document.orderform.BillState.value !="" ||document.orderform.BillZipcode.value !=""){
			var row = preview_table.insertRow(j);
			var td = row.insertCell(0);
			td.className="langtitle";
			td.innerHTML = document.orderform.BillCity.value +","+document.orderform.BillState.value +","+document.orderform.BillZipcode.value 
			j++;
		}
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = document.orderform.BillCountry.options[document.orderform.BillCountry.options.selectedIndex].value; 
		j++;
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = " <b> Shipping Address </b> ";
		j++;
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = document.orderform.ShipAddress1.value 
		j++;
		
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = document.orderform.ShipAddress2.value 
		j++;
		if(document.orderform.ShipCity.value != "" || document.orderform.ShipState.value !="" ||document.orderform.ShipZipcode.value !=""){
			var row = preview_table.insertRow(j);
			var td = row.insertCell(0);
			td.className="langtitle";
			td.innerHTML = document.orderform.ShipCity.value +","+document.orderform.ShipState.value +","+document.orderform.ShipZipcode.value 
			j++;
		}
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = document.orderform.ShipCountry.options[document.orderform.ShipCountry.options.selectedIndex].value;
		j++;
		var row = preview_table.insertRow(j);
		var td = row.insertCell(0);
		td.className="langtitle";
		td.innerHTML = " <b> Comments :</b> "+document.orderform.Comments.value;
		
		
}


	 /* Called on onBlur() event on  email field.*/
  	/* Checks if entered value matches the regular email pattern, if not, alert the user and exit */ 

	this.validateEmail = function(emailId) {
 		var email = emailId.value;
 		
  		 if(email != ""){
  		  		 validEmailExp =/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  		
  		 if (email.search(validEmailExp) == -1) {
	  		 	alert("Email Address Entered is Not Valid");
	    		emailId.value="";
    		}
    	  }
	       return;
    }

    /* Called on onBlur() event on  email field.*/
  	/* Checks if entered value matches the regular email pattern, if not, alert the user and exit */ 

	this.validateRequired = function() {
        if(document.orderform.Email.value ==""){
	        alert("Please enter your Emailaddress before submitting your order inorder to help us contact you.Thankyou! ");
    	}/*else if(document.orderform.Email.value !="" && document.orderform.Phone.value == ""){
	        alert("Please enter your PhoneNo before submitting your order inorder to help us contact you.Thankyou!");
    	}else if(document.orderform.Email.value =="" && document.orderform.Phone.value != ""){
	        alert("Please enter your Emailaddress before submitting your order inorder to help us contact you.Thankyou!");
    	}*/else {
	    	return true;
    	}
    	return false;
    }

this.showBooksBubble = function(element, title, imgtitle,time,adjPos){

 	 if(document.getElementById(element) != null) {
	 	 // set icon to be displayed in bubble
		 var icontype = "\\images\\booksBubbleIcon_info.gif";
		 document.getElementById("closeIcon").src="\\images\\booksBubble_closeHighlight.gif";
		 document.getElementById("closeIcon").onclick=this.hideBooksBubble;
		 //set book image of bubble
		 document.getElementById("bubbleIcon").src =  "\\images\\thumbnails\\"+imgtitle ;
	     var x=0;
	     var y=0;
	       var cElement = document.getElementById(element);
		   var useClient = (cElement.offsetTop == 0) ? 
		        ((cElement.offsetParent.tagName == "TR") ? false : true) : false
		    if (useClient) {
		        var x = cElement.clientLeft
		        var y = cElement.clientTop
		    } else {
		        var x = cElement.offsetLeft
		        var y = cElement.offsetTop
		    }
		    var pElement = cElement.offsetParent
		    while (pElement != document.body) {
		       if(pElement.offsetParent.tagName != "BODY"){
				    if (useClient) {
			            x += pElement.clientLeft
			            y += pElement.clientTop
			        } else {
			            x += pElement.offsetLeft
			            y += pElement.offsetTop
			        }
	      	    }
		        pElement = pElement.offsetParent
		    }		     
		    
		 document.getElementById("booksBubble").style.left = x;
         document.getElementById("booksBubble").style.top = y+42;
	     document.getElementById("booksBubble").style.position="absolute";
	     

	     document.getElementById("booksBubble").style.display="";
	     document.getElementById(element).focus();
	     //set timer to hide alertbubble
	     if(time != 0)
	     setTimeout(this.hideBooksBubble,time);
	  }
 }

 this.hideBooksBubble = function(){
 	document.getElementById("booksBubble").style.display="none";;
 }

this.updateMessage= function(){

	var saisookthi = new Array(8);
	saisookthi[0]="\"Nana, Pranipata implies surrender of body, mind and wealth.<br><br>Then why should Krishna direct Arjuna to other Jnanies or Tatwadarsis when he himself is a Jnani?.\"";
	saisookthi[1]="\"Sleep a little, eat a little, speak a little.\"";
	saisookthi[2]="\"I am in you, You are in me.<br></br> Go on contemplating this truth and eventually you will experience it.\"";
	saisookthi[3]="\"Whatever you do, wherever you may be, ever bear this in mind that I am always aware of everything.\"";   
	saisookthi[4]="\"Nana, Pranipata implies surrender of body, mind and wealth.<br><br>Then why should Krishna direct Arjuna to other Jnanies or Tatwadarsis when he himself is a Jnani?.\"";
	saisookthi[5]="\"Sleep a little, eat a little, speak a little.\"";
	saisookthi[6]="\"I am in you, You are in me.<br></br> Go on contemplating this truth and eventually you will experience it.\"";
	saisookthi[7]="\"Whatever you do, wherever you may be, ever bear this in mind that I am always aware of everything.\"";   
    

	var aacharyavani = new Array(8);
	aacharyavani[0]="\"The sadbhakta (true devotee) takes everything to be Vasudeva (the Lord of existence) says the Bhagavadgita (ch. VII v. 19) <br> <br>i.e., any guru will be Krishna to the devotee and guru takes the disciple to be Vasudeva, and Krishna treats both as his prana (Sprit or Life), and atma (or Self). <br><br>As Sri Krishna knows that there are such bhaktas (devotees) and gurus, he refers Arjuna to them so that their greatness may be known to all.\"";
	aacharyavani[1]="\"If we wakeup, He will be there with us althrough right up to the goal. <br> <br>Otherwise, even if He is with us, we are not with him, lost as we are in the world of our dreams and nightmares.\"";
	aacharyavani[2]="\"All our physical bodies are essentially made of the same material substance. <br><br>The heart beats, the motions and the mental abilities are more or less the same. <br><br>Whatever, which seems to make each of us distinct, is only the detail of form and the objects of our thoughts, feelings and actions. <br><br>Whatever else we are, besides this is the Self which all great Masters have said, is one. <br><br>At the emotional level this comprehends the basic law of all morality and this; \"Do unto others what you would have done Unto\". and logically follows \"Love Thy neighbour as Thyself.\"";
	aacharyavani[3]="\"What a great solace and a source of confidence to his devotees, and yet what an effective check to their evil propensities!\"";
	aacharyavani[4]="\"The sadbhakta (true devotee) takes everything to be Vasudeva (the Lord of existence) says the Bhagavadgita (ch. VII v. 19) <br> <br>i.e., any guru will be Krishna to the devotee and guru takes the disciple to be Vasudeva, and Krishna treats both as his prana (Sprit or Life), and atma (or Self). <br><br>As Sri Krishna knows that there are such bhaktas (devotees) and gurus, he refers Arjuna to them so that their greatness may be known to all.\"";
	aacharyavani[5]="\"If we wakeup, He will be there with us althrough right up to the goal. <br> <br>Otherwise, even if He is with us, we are not with him, lost as we are in the world of our dreams and nightmares.\"";
	aacharyavani[6]="\"All our physical bodies are essentially made of the same material substance. <br><br>The heart beats, the motions and the mental abilities are more or less the same. <br><br>Whatever, which seems to make each of us distinct, is only the detail of form and the objects of our thoughts, feelings and actions. <br><br>Whatever else we are, besides this is the Self which all great Masters have said, is one. <br><br>At the emotional level this comprehends the basic law of all morality and this; \"Do unto others what you would have done Unto\". and logically follows \"Love Thy neighbour as Thyself.\"";
	aacharyavani[7]="\"What a great solace and a source of confidence to his devotees, and yet what an effective check to their evil propensities!\"";

	var dt= new Date();
	var day = dt.getDay(); 
	  document.getElementById("saisookthi").innerHTML='<div class="babamessage">'+saisookthi[day]+'</div>';
	  document.getElementById("acharyavani").innerHTML='<div class="babamessage">'+aacharyavani[day]+'</div>';
	

}

this.validateContact=function(){

   var contactName = document.getElementById("contactName").value ;
   var contactPhone = document.getElementById("contactPhone").value ;
   var contactEmail = document.getElementById("contactEmail").value ;
   
   
    /*if(contactName == "" && (contactPhone != "" && contactEmail !="")){
        	alert("Please enter your name");
        	return false;
    }*/
    
    if(contactEmail =="") {
    	alert("Please enter your  EmailAddress information");
    	return false;
    
    }
   
   return true;
}

this.setSubject = function() {
	var shipCountry = document.orderform.ShipCountry.options[document.orderform.ShipCountry.options.selectedIndex].value;
	document.orderform.subject.value = document.orderform.subject.value + " - " + shipCountry;
	return;
}

this.setCategoryColor = function(id){
	 categories = new Array(8);
	categories[0] = "engcategory";
	categories[1] = "hindicategory";
	categories[2] = "kannadacategory";
	categories[3] = "malayalamcategory";
	categories[4] = "tamilcategory";
	categories[5] = "telugucategory";
	categories[6] = "magcategory";
	categories[7] = "audiovideocategory";
	
	for(var i=0;i<categories.length;i++) {
  	  if(categories[i] == id)
			document.getElementById(id).className="activecataloguetab";
	  else
			document.getElementById(categories[i]).className="cataloguetab";	   
	}
        	
  	return;
}
