﻿// JScript File
function displaySelectMagazineItem(item)
{
    itemnametmp=item.name; 
    isCollection=false;
    var Editor="";
    var tempdescription =new Array();
    var tempImage=new Array();
    var tempEditorID="";
     // added by saraswathy on 24/03/2009
    var tempselp = new Array();

    var html= '<table width="440" cellpadding="3" cellspacing="0" border="0" bgcolor="#D6DDBD">';
	html+='<tr><td colspan="3">';
    html+= '<table width="100%" cellpadding="0" cellspacing="0">';
	html+= '<tr>';
	html+= '<td width="0%"><img src="gui/img/bg_title_left.gif" width="10" height="37" alt=""></td>';
    html+= '<td  width="460" colspan="5" align="center" background="gui/img/bg_title.gif"><center><h1 class="white">'+item.name+'</center></h1></td>';
	html+= '<td width="0%"><img src="gui/img/bg_title_right.gif" width="10" height="37" alt=""></td>';
	html+= '</tr></table></td></tr>';
    for(var i=0,j=0;i<SelectedProducts.length;i++)
    {
        if((SelectedProducts[i].name == item.name)&&(SelectedProducts[i].ProductCategoryID==2))
	    { 
	          // added by saraswathy on 24/03/2009
	        tempselp[j] = SelectedProducts[i].Editor;

            tempdescription[j]=SelectedProducts[i].EditorDescription;
            tempImage[j]=SelectedProducts[i].EditorImage;
            tempEditorID=SelectedProducts[i].EditorID;

        }
    }
    
	if (item.Editor!= "N/A")
    {
        Editor='<table><tr><td align="left" width="30%"><img height="100" width="100" src='+ tempImage[j] +' alt="Author Image" /></td><td align="left" valign="top" width="70%"><font size="2"> <div id="LoadDescription" ></div></td></tr></table>';
         var desc=tempdescription[j];
         var attribute= desc.substr(0, desc.indexOf(".", 0))
         
         $('popupBody').innerHTML=Editor;
         
         clientSideInclude("LoadDescription", "admin/PageContent/Editor/"+ attribute +"/"+ desc);
         //commented and modified by geetha from saraswath on 25/03/2009
        // html+= '<tr><td align="left" class="PageText" width="30%"><strong>ஆசிரியர்:</strong></td><td class="PageText" width="30%" onmouseover="javascript:popUpAuthor()" onmouseout="javascript:popUpAuthor()" style="cursor: pointer;" ><a href="javascript:displaySearchedBooks('+tempEditorID+',3,this.form)"  > <font color="blue">'+item.Editor +'</font></a></td>';
           html+= '<tr><td align="left" class="PageText" width="30%"><strong>ஆசிரியர்:</strong></td><td class="PageText" width="30%" onmouseover="javascript:popUpAuthor()" onmouseout="javascript:popUpAuthor()" style="cursor: pointer;" ><a href="javascript:funDisplaySearchedBooks(0,\'funDisplaySearchedBooks\','+tempEditorID+',3,\''+tempselp[j]+'\')"> <font color="blue">'+item.Editor +'</font></a></td>';
         //ends here
    }
    if (item.Publisher!= "N/A")
    {
	   html+= '<tr><td align="left" class="PageText"><strong>பதிப்பாளர்:</strong></td><td class="PageText">'+item.Publisher+'</td>';
	}
	html+= '<tr><td valign="top" align="left" width="35%">';
    html+= '<a href="#"><br>';
	html+= '<img src="'+item.image+'" alt="'+item.name+'"  border="0"><br>';
	html+= '</a></td>'
    html+='<td width="45%"><img src="gui/img/spacer.gif" alt="" width="3" height="1">';
    //Code Commented and added by senthil on 26/06/2009 for add magazine type in this screen
//    for(var i=0,j=0;i<SelectedProducts.length;i++)
//   	{
//    	if(item.name==SelectedProducts[i].name &&(SelectedProducts[i].ProductCategoryID==2)) 
//    	{
//            var newhtml ='<table width="200" height="30" class="PageText" border="1">';
//                //commented and modified by deepika on 28/04/09
////                newhtml += '<tr><td class="PageTitleText">Yearly Subscription </td><td align="right" class="PageText">$'+SelectedProducts[i].Issue12+' (approx...Rs.'+SelectedProducts[i].Issue12 * INRValue[0].value+')</td></tr>';  
//                  newhtml += '<tr><td class="PageTitleText">Yearly Subscription </td><td align="right" class="PageText">$'+SelectedProducts[i].Issue12+' (approx...Rs.'+(SelectedProducts[i].Issue12 * INRValue[0].value).toFixed(2)+')</td></tr>';  
//                newhtml += '<tr><td colspan=2><center>';
//                newhtml +='<input type="button" value="Buy & Download Now" src="images/bt_buy.gif" onclick=" Magazinecheckbuy('+item.id+','+isCollection+',this.form)"" id="Button1"/>';
//                newhtml +='</center></td></tr></table>';
//             
//        }
//    }
    for(var i=0;i<SelectedProducts.length;i++)
   	{
    	if(item.name==SelectedProducts[i].name &&(SelectedProducts[i].ProductCategoryID==2)) 
    	{
    	    
            var newhtml ='<table width="200" height="30" class="PageText" border="1">';
                newhtml += '<tr><td class="PageTitleText">Subscription </td>';
                newhtml += '<td align="right" class="PageText">';
                newhtml += '<select id="subType" onchange="funDispPrice('+SelectedProducts[i].id+')" style="width:100%;">';
               for(var j=0;j<SelectedProducts[i].MagazineType.length;j++)
                {                  
                 newhtml += '<option value="'+SelectedProducts[i].MagazineType[j].id+'">'+SelectedProducts[i].MagazineType[j].Name+'</option>';        
                }                
                newhtml += '</select>';                
                newhtml += '</td></tr>';  
                //Code commented and added by senthil on 6/07/2009 for give space in the caption
                //newhtml += '<tr><td class="PageTitleText">NoOfIssue</td>';
                newhtml += '<tr><td class="PageTitleText">No Of Issue</td>';
                newhtml += '<td align="right" class="PageText"><div id="NoIssue"></div>';
                newhtml += '</td></tr>';  
                //newhtml += '<tr><td class="PageTitleText">Price </td>';
                newhtml += '<tr><td class="PageTitleText"><div id="ActualPrice"></div></td>';
                newhtml += '<td align="right" class="PageText"><div id="Price"></div>';
                //Code added by ranjith on 26 06 2009
                newhtml +='<tr><td>' 
                newhtml += '<div id="DiscountedPrice"></div></td><td align="right" ><div id="OriginalPrice"></div></td></tr>';     
                //End here          
                newhtml += '<tr><td colspan=2><center>';
                //code commented and added by senthil on 15/09/2009 for added extra parameter buy in onclick event function
                //newhtml +='<input type="button" value="Buy & Download Now" src="images/bt_buy.gif" onclick=" Magazinecheckbuy('+item.id+','+isCollection+',this.form)"" id="Button1"/>';
                newhtml +='<input type="button" value="Buy & Download Now" src="images/bt_buy.gif" onclick=" Magazinecheckbuy('+item.id+','+isCollection+',\'Buy\',this.form)"" id="Button1"/>';
                //newhtml +='</center></td></tr></table>';
                newhtml +='</center></td></tr>';               
                newhtml += '<tr><td colspan=2><div id="RenewalButton"><center>';
                //Code commneted and added by senthil on 10/11/2009 for change the button text
                //newhtml +='<input type="button" value="Buy &Renewal Now" onclick=" Magazinecheckbuy('+item.id+','+isCollection+',\'Renewal\',this.form)"" id="Button2"/>';
                newhtml +='<input type="button" value="Buy & Renew Now" onclick=" Magazinecheckbuy('+item.id+','+isCollection+',\'Renewal\',this.form)"" id="Button2"/>';
                //End here senthil 10/11/2009
                newhtml +='</center></div></td></tr></table>';              
               //end here 
        }
    }
   //End here  
    if(item.issale=="True")
    {
       html+= '<div id="TestDiv">'+newhtml+'</div></td>';
    }
    else
    {
       html+= '<input type="button" value="Download" onclick="return Download(this.form,'+item.id+')" id="Button1"/>';
    }
   
	html+='<tr><td align="left"  width="25%" colspan="0" class="PageText"><strong>Size:</strong></td><td class="PageText">'+item.Size + '</td></tr>';
	
	html+='<tr><td align="left"  width="25%" colspan="0" class="PageText"><strong>மொ.பக்கம்:</strong></td><td class="PageText">'+item.NoOfPages + '';
	if(item.Samples!="N/A")
    {
    html+= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="promoProductDesc"><a href="'+item.Samples+'" ><font color="blue">View Sample Pages</font></a></span></td></tr>';
    }
	html+= '<td width="20%"><img src="gui/img/spacer.gif" alt="" width="" height="1"></td>';
    html+= '</tr><tr><td colspan="3">';
	html+= '<div id="includeone" class="promoProductDesc"></div><br><br>';
	html+='</td></tr></table>';

	return html;
}
function displaySelectedMagazineItem(itemid)
{
    
	var html='<form name="frmMagazine" method="post" action=""> ';
	directbuy="false";
	flavtmp = "Select" ;
	sizetmp = "Select";
	html +='<table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#E4E4E4">';
	html +='<tr>';
	html +='<td>';
	html +='<table width="100%" border="0" cellpadding="0" cellspacing="4" bgcolor="#FFFFFF">';
	var tmp="";
	var MagazineIndex=0;
    for(var i=0;i<SelectedProducts.length;i++)
	{
        if((SelectedProducts[i].id == itemid)&&(SelectedProducts[i].ProductCategoryID==2))
		{
			MagazineIndex=i;
			tmp+='	<td valign="top">'+displaySelectMagazineItem(SelectedProducts[MagazineIndex])+'</td>';
		}
	    else if((SelectedProducts[i].id == itemid)&&(SelectedProducts[i].ProductCategoryID==3))
        {
        
           var categoryid=SelectedProducts[i].ProductCategoryID;

            MagazineIndex=i;
           tmp+='<td valign="top">'+displaySelectCollectionItem(SelectedProducts[MagazineIndex])+'</td>';
	    }
	} 
	html+='<tr align="center">'+tmp;
	html+='</tr>';
	html +='<tr><td>';
	html+='<table width="100%" height="320px"  bgcolor="#D6DDBD">';
      html+='<tr valign="top"><td align="center">';
      html+='<table><tr><td align="center"><FONT color=#CC6600><b>விமர்சனங்கள்</b></font></td></tr>';
      html+='<tr><td align="left" width= "100%" class="promoProductDesc"><FONT color=#CC6600>உங்கள் விமர்சனங்கள் வரவேற்கப்படுகின்றன</font></td></tr>';
      html+='</table></td></tr>';

      html+='<tr style="height:280px" valign="top"><td align="left" valign="top">';

      html+='<div style="overflow: auto; width:100%;height:250px;position:absolute; border: thin solid #FFFF00"><table>';
      html+='<tr><td><table class="promoProductDesc">';
      for (var i=0; i<BookReview.length; i++)
      {
       if(BookReview[i].id==itemid)
 	        {
      html+='<tr><td align="left"><b>Name :</b></td><td>'+ BookReview[i].Username +'</td>';
      html+='<tr><td align="left"><b>Country :</b></td><td>'+ BookReview[i].Country +'</td></tr>';
      html+='<tr><td align="left"><b>Comment :</b></td><td>'+ BookReview[i].Comments +'</td></tr>';
      html+='<tr><td><img alt="" height="3" src="images/spacer.gif" width="100%" align="middle" /></td></tr>';
            }
     
    }  
	html+='</table></td></tr></table></div>';
	html+='</td></font></tr></table>';
    html+='</table>';
    html+='</td></tr></table></td></tr></table></form>';
   
   
	if(categoryid!=3)
    {
	    var element = document.getElementById("flashContent");
	    element.innerHTML=html;
	    var row ="" ;
	    var element1 = document.getElementById("listProducts");
	    element1.innerHTML=row;
        $('listItems').innerHTML = "";        
	    for(var i=0;i<SelectedProducts.length;i++)
	    {
	    if((SelectedProducts[i].id == itemid) &&(SelectedProducts[i].ProductCategoryID==2))
		    clientSideInclude("includeone", "admin/PageContent/Products/"+itemid+"/"+SelectedProducts[i].LongDescription);
	    }
	    
	}
}
//Code commented and added by senthil on 15/09/2009 for magazine renwel option
//function Magazinecheckbuy(itemId,isCollection,frm)
function Magazinecheckbuy(itemId,isCollection,StrRenewal,frm)
//End here
{
     var itemidtmp; 
     var strCriteria ="";
     var k =0;
     isavailable="false";
     //Code commented and added by senthil on 26/06/2009     
     //strCriteria="YearlyIssue";
     strCriteria = document.getElementById("subType").value;
     //End here
     for(var i=0;i<SelectedProducts.length;i++)
     {
	    if(SelectedProducts[i].id == itemId)
	    {
		    itemnametmp = SelectedProducts[i].name;		
	    }
     }
     for(var i=0;i<SelectedProducts.length;i++)
     {
	    if(SelectedProducts[i].name==itemnametmp)
	    {
		    isavailable="true";
		    itemidtmp=SelectedProducts[i].id;
	    }	
     }
     if(isavailable=="true")
     {
        //Code comented and added by senthil on 15/09/2009 for magazine renewal option
        //return buy(itemidtmp,isCollection,strCriteria);
        return buy(itemidtmp,isCollection,strCriteria,StrRenewal);
        //End here
     }
}

//Function added by senthil for display the price and noofissue on change of magazine type
function funDispPrice(itemid)
{
 var subscription = document.getElementById("subType").value;
 for(var i=0;i<SelectedProducts.length;i++)
 {
  if(SelectedProducts[i].id == itemid)
  {       
     for(var j=0;j<SelectedProducts[i].MagazineType.length;j++)
     {     
         if(SelectedProducts[i].MagazineType[j].id == subscription)
         {
             var element = document.getElementById("NoIssue");
	        element.innerHTML=SelectedProducts[i].MagazineType[j].NoofIssue;
	        var element1 = document.getElementById("Price");
	        var actualPrice = document.getElementById("ActualPrice");
	        var discountPrice = document.getElementById("DiscountedPrice");
            var originalPrize = document.getElementById("OriginalPrice");
	        if(SelectedProducts[i].MagazineType[j].DiscPrice == 0)	{
	        var html ="";
	        html='<p>';     
	        html+='$'+SelectedProducts[i].MagazineType[j].Price+'<br/>(approx...Rs.'+(SelectedProducts[i].MagazineType[j].Price * INRValue[0].value).toFixed(2)+')';
	        html+='</p>';
	        element1.innerHTML=html;
	        actualPrice.innerHTML = 'Price';
	        discountPrice.innerHTML ="";
	        originalPrize.innerHTML ="";
	    }
        else
	    {
	        html='<p class="DiscountPriceRate">';     
	        html+="$"+SelectedProducts[i].MagazineType[j].DiscPrice+'<br/>(approx...Rs.'+(SelectedProducts[i].MagazineType[j].DiscPrice * INRValue[0].value).toFixed(2)+')'
	        html+='</p>';
	        element1.innerHTML=html;	    
	        getOriginalPrice('$'+SelectedProducts[i].MagazineType[j].Price+'<br/>(approx...Rs.'+(SelectedProducts[i].MagazineType[j].Price * INRValue[0].value).toFixed(2)+')');
	    }
	    
     } 
   }
  }
 }
}
//Function added by senthil given by ranjith on 26/06/2009
function getOriginalPrice(value)
{
 var element1 = document.getElementById("DiscountedPrice");
 var element2 = document.getElementById("OriginalPrice");
 var element3 = document.getElementById("ActualPrice");
 var innerhtm;
        innerhtm= 'Discounted Price';	    
	    element1.innerHTML=innerhtm;
	    innerhtm = '<p class="OriginalPrice">';
	    innerhtm +=value;
	    innerhtm +='</p>';    
	    element2.innerHTML=innerhtm;
	    element3.innerHTML='Actual Price'
}
//End here
//Function added by senthil on 15/09/2009 for Display the Renewal button when the user subscription count is less than four 
function getIssueCount(ItemID)
{   
    if((Cust.length==0) ||(Cust[0].FirstName=='')||(Cust[0].FirstName=='LoginFailed')||(Cust[0].FirstName=='RegLoginFailed')||(Cust[0].FirstName=='UnApproved')||(Cust[0].FirstName=='RegSuccess'))
     {  
        var  btRenewal = document.getElementById("RenewalButton");     
        btRenewal.innerHTML ="";       
     }
     else
     {
         var url = 'Data.aspx?mode=main&rnd='+Math.random()+'&action=getIssueCount&itemid='+ItemID;
	     handleRequest(GET, url, funDisplayRenewalButton,progress);     
     }

}
function  funDisplayRenewalButton(req)
{
   eval('var IssueCount ='+req.responseText);   
   if((IssueCount[0].isHaving == "True") && (IssueCount[0].IssueCount < 4) )
   {    
   }
   else 
   {
    var  btRenewal = document.getElementById("RenewalButton");
    btRenewal.innerHTML ="";
   }
}
//End here senthil on 15/09/2009 