function empty_box()
	{
	// to empty search bon on click
	document.search.q.value="";
	}

function validate_form()
{
    valid = true;

    if( document.enquiry.Name.value == "" )
    {
        //alert ( "Please Enter Your Full Name" );
        document.getElementById("name_msg").innerHTML="<font color= red>Missing Required Field: Full Name</font>";
        valid = false;
    }else if(document.enquiry.Email.value == "" )
    {
    			document.getElementById("name_msg").innerHTML="";
                document.getElementById("email_msg").innerHTML="<font color= red>Missing Required Field: Email Address</font>";
        valid = false;
    }
    else if(getemail(document.enquiry.Email.value)==1 )
    {
    document.getElementById("name_msg").innerHTML="";
                document.getElementById("email_msg").innerHTML="<font color= red>Enter a valid Email Address</font>";
        valid = false;
    }
    else if(document.enquiry.subject.value == "" )
    {
    			document.getElementById("subject_msg").innerHTML="";
                document.getElementById("subject_msg").innerHTML="<font color= red>Missing Required Field: Subject</font>";
        valid = false;
    }
    else if(document.enquiry.Message.value == "" )
    {
    			document.getElementById("enquiry_msg").innerHTML="";
                document.getElementById("enquiry_msg").innerHTML="<font color= red>Missing Required Field: Enquiry</font>";
        valid = false;
    }
    else if(document.enquiry.TuringTest.value == "" )
    {			
    			document.getElementById("enquiry_msg").innerHTML="";
                document.getElementById("turning_msg").innerHTML="<font color= red>Missing Required Field: Security Code</font>";
        valid = false;
    }



    return valid;
}


function Validate_Comment_Form()
{
//alert("Full Name = " . k);
    var valid = true;
    var k = document.getElementById('fullname').value;
    //alert("Full Name = " . k);

    if( document.getElementById("fullname").value == "" )
    {
        //alert ( "Please Enter Your Name" );
        document.getElementById("fullname_msg").innerHTML="<font color= red>Missing Required Field: Full Name</font>";
        valid = false;
    }else if(document.getElementById("email").value == "" )
    {
    		document.getElementById("fullname_msg").innerHTML="";
            document.getElementById("email_msg").innerHTML="<font color= red>Missing Required Field: Email Address</font>";
        	valid = false;
    }
    else if(getemail(document.getElementById("email").value)==1 )
    {			
    			document.getElementById("fullname_msg").innerHTML="";
                document.getElementById("email_msg").innerHTML="<font color= red>Enter a valid Email Address</font>";
        valid = false;
    }
    else if(document.getElementById("subject").value == "" )
    {
        document.getElementById("fullname_msg").innerHTML="";
    	document.getElementById("email_msg").innerHTML="";
        document.getElementById("subject_msg").innerHTML="<font color= red>Missing Required Field: Subject</font>";
        valid = false;
    }else if(document.getElementById("comment").value == "" )
    {
    	document.getElementById("fullname_msg").innerHTML="";
    	document.getElementById("email_msg").innerHTML="";
    	document.getElementById("subject_msg").innerHTML="";
        document.getElementById("comment_msg").innerHTML="<font color= red>Missing Required Field: Comments</font>";
        valid = false;
    }else if(document.getElementById("TuringTest").value == "" )
    {
    			document.getElementById("fullname_msg").innerHTML="";
    	document.getElementById("email_msg").innerHTML="";
    	document.getElementById("subject_msg").innerHTML="";
    			document.getElementById("comment_msg").innerHTML="";
                document.getElementById("TuringTest_msg").innerHTML="<font color= red>Missing Required Field: Security Code</font>";
        valid = false;
    }
   
   if(valid == true)
   { 
    	document.submit_comments.method = "POST";
    	document.submit_comments.action = "./";
    	document.submit_comments.submit();
   } 

    //return valid;
}



/* ================AJAX==*/

function ajax_Initialization()
{
   try
 {
   // Opera 8.0+, Firefox, Safari
   var ajaxRequest = false;
   ajaxRequest = new XMLHttpRequest();   
 }
 catch (e)
 {
   // Internet Explorer Browsers
   try
   {      
      //For IE 6
      //ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
       
        var types = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 
'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP']; 

        for (var i = 0; i < types.length; i++) 
        { 
                try 
                { 
                   //alert("types = " + types[i]);
                      ajaxRequest = new ActiveXObject(types[i]);
                      if(ajaxRequest != '')
                      {
                         break;
                      }                      
                } 
                catch(e) {} 
        }
          
        //ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
       //alert("ajax request = " + ajaxRequest);   
       //alert("Type " + typeof ActiveXObject); 
       //alert(navigator.appVersion);
             
                
   }
   catch (e)
    {
      try
      {
         //alert("here 2");
         //For IE 5
         ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         
      }
      catch (e)
      {
         // Something went wrong
         alert("Your browser broke! It is not IE5 or Higher..");
         return false;
      }
   }
 }
 return ajaxRequest;
}

function ArchiveList(id)
{
 // var input_box=confirm('Do You Really want to change the State of Published..');
  //if(input_box == true)
 // {
    var ajaxRequest;  // The variable that makes Ajax possible!
	//alert("path = " + path); 
    ajaxRequest = ajax_Initialization(ajaxRequest);
 
  //alert(ajaxRequest);
  
// var pub = document.getElementById('published_'+id).value;
 var year = document.getElementById(id+'_year').value;
 
  //alert("window location = " + window.location.href);
 var queryString = "/site/archive/getArchiveList.php";
 var randomnumber=Math.floor(Math.random()*1000000001)
 queryString += "?id=" + id;
// queryString +=  "&pub=" + pub;
 queryString +=  "&year=" + year;
 queryString +=  "&anticache=" + randomnumber;
 
 alert("url before = " + queryString); 
 ajaxRequest.open("GET", queryString, true);
 
 ajaxRequest.onreadystatechange = function()
{  
   
   if(ajaxRequest.readyState == 4)
   {                      
      var ajaxDisplay = document.getElementById(id);
      alert("id = " + id);
      alert (ajaxRequest.responseText);
      ajaxDisplay.innerHTML  = ajaxRequest.responseText;
      //ajaxDisplay.innerHTML = queryString;      
   }
}
 
  
 if(window.ActiveXObject)
 {
    ajaxRequest.send("");    
 }
 else 
 {
    ajaxRequest.send(null);
 } 
            
         
//  }
  
    
 // alert("called");
}


function ArchiveList_month(id)
{
 // var input_box=confirm('Do You Really want to change the State of Published..');
  //if(input_box == true)
 // {
    var ajaxRequest;  // The variable that makes Ajax possible!
	//alert("path = " + path); 
    ajaxRequest = ajax_Initialization(ajaxRequest);
 
 // alert(ajaxRequest);
  
// var pub = document.getElementById('published_'+id).value;
 var month = document.getElementById(id+'_month').value;
 var year = document.getElementById(id+'_year').value;
 
  //alert("window location = " + window.location.href);
 var queryString = "/site/archive/getArchiveList_month.php";
 var randomnumber=Math.floor(Math.random()*1000000001)
 queryString += "?id=" + id;
// queryString +=  "&pub=" + pub;
 queryString +=  "&month=" + month;
 queryString +=  "&year=" + year;
 queryString +=  "&anticache=" + randomnumber;
 
 //alert("url before = " + queryString); 
 ajaxRequest.open("GET", queryString, true);
 
 ajaxRequest.onreadystatechange = function()
{  
   if(ajaxRequest.readyState == 1)
   {
   		var ajaxDisplay = document.getElementById(id);
         ajaxDisplay.innerHTML  = "<p align=center>Loading...<br><img src=/site/userimage/image/ajax-loader.gif border=0 alt='loading...'></p>";
//		alert ('wad');
   } 
   else if(ajaxRequest.readyState == 4)
   {                 
      var ajaxDisplay = document.getElementById(id);
      //alert (ajaxRequest.responseText);
      ajaxDisplay.innerHTML  = ajaxRequest.responseText
      //ajaxDisplay.innerHTML = queryString;      
   }
}
 
  
 if(window.ActiveXObject)
 {
    ajaxRequest.send("");    
 }
 else 
 {
    ajaxRequest.send(null);
 } 
            
         
//  }
  
    
 // alert("called");
}

function change_price()
{
	var quantity = document.getElementById('quantity_total').value;
	var rate = document.getElementById('rate').value;

    var price = parseInt(quantity) * parseInt(rate);
    //alert("Price = " + price);
    document.getElementById('price').value = price;
    //alert("Quantity = " + quantity);
    document.getElementById('quantity_form').value = quantity;    
}

function getOrderForm()
{
//alert ("getting oredr form");

   var ajaxRequest;  // The variable that makes Ajax possible!
	//alert("path = " + path); 
    ajaxRequest = ajax_Initialization(ajaxRequest);

 //var order = document.getElementById('order').value;
var book_id = document.getElementById('book_id').value;
var title = document.getElementById('site_title').value;
var quantity = document.getElementById('quantity').value;
var rate = document.getElementById('rate').value;

if((quantity == "") || (parseInt(quantity)<=0))
{
   if(quantity == "")
   {
   		alert("Please Enter The Quantity");   
   }
   else
   {
    	alert("Please Enter a Valid Quantity Greater Than Zero");
   }
   
   document.getElementById('quantity').focus();
   document.getElementById('quantity').select();
}
else
{
	//document.getElementById('quantity_text').style.visibility = 'hidden';
  //alert("window location = " + window.location.href);
 var queryString = "/site/ecommerce/order_form.php";
  var randomnumber=Math.floor(Math.random()*1000000001)
 
 queryString +=  "?anticache=" + randomnumber;
 queryString +=  "&book_id=" + book_id;
 queryString +=  "&book_name=" + title;
 queryString +=  "&quantity_form=" + quantity;
 queryString +=  "&rate=" + rate;
 
 
 //alert("url before = " + queryString); 
 ajaxRequest.open("GET", queryString, true);
 
 ajaxRequest.onreadystatechange = function()
{  
   if(ajaxRequest.readyState == 1)
   {
   		var ajaxDisplay = document.getElementById('quantity_text');
         ajaxDisplay.innerHTML  = "<p align=center>Loading Order Form...<br><img src=/site/userimage/image/ajax-loader.gif border=0 alt='loading...'></p>";
		//alert ('wad');
   } 
   else if(ajaxRequest.readyState == 4)
   {                 
      var ajaxDisplay = document.getElementById('quantity_text');
      //alert (ajaxRequest.responseText);
      ajaxDisplay.innerHTML  = ajaxRequest.responseText;
      //ajaxDisplay.innerHTML = queryString;
      
      var ajaxDisplay = document.getElementById('comments');
      ajaxDisplay.innerHTML  = '';
      
      
            
   }
}
 
  
 if(window.ActiveXObject)
 {
    ajaxRequest.send("");    
 }
 else 
 {
    ajaxRequest.send(null);
 } 
            
	
}
  
           
//  }
  
    
 // alert("called");


}


function getemail(str)

{

var at="@"

var dot="."

var lat=str.indexOf(at)

var lstr=str.length

var ldot=str.indexOf(dot)

var error = 0;

if (str.indexOf(at)==-1){

//alert("Invalid E-mail ID")

error = 1;

}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

//alert("Invalid E-mail ID")

error = 1;

}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

//alert("Invalid E-mail ID")

error = 1;

}

if (str.indexOf(at,(lat+1))!=-1){

//alert("Invalid E-mail ID")

error = 1;

}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

//alert("Invalid E-mail ID")

error = 1;

}

if (str.indexOf(dot,(lat+2))==-1){

//alert("Invalid E-mail ID")

error = 1;

}

if (str.indexOf(" ")!=-1){

//alert("Invalid E-mail ID")

error = 1;

}

return error;

 

}
