function VideoSelect(checktype,price,changediv,asset_id,loginststus,page_name,userid,type)
{
	var content='';
	if(price!='Free')
	{
		content +='<a href="#" onclick="add_to_cart(\''+page_name+'\',\''+asset_id+'\',\''+userid+'\',\''+type+'\',\''+checktype+'\');">	<div class="btn primary">Add to Cart</div></a>&nbsp;';
	}
	else
	{
		content +='<div id="freeprice" style="display:inline; float:left;"><a ';
		if(loginststus=='no')
			content +='href="/login" >';
		else
			content +='href="#" onclick="add_to_cart(\''+page_name+'\',\''+asset_id+'\',\''+userid+'\',\''+type+'\',\''+checktype+'\');">';
			
		content +='<div class="btn primary m_top_10">Add to My Purchases</div>';		
		content +='</a> </div>&nbsp;';
	}
	
	$('#small_icon1').html(content);
}

function add_to_cart(page_name,asset_id,user_id,type,checked_value)
{
	xmlHttp=GetXmlHttpObject()
 
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
 	var url= 'ajax_add_to_cart&popup=yes';
 	url=url+"&asset_id="+asset_id+"";
	url=url+"&type="+type+"";
	if(checked_value!='')
		checked_value=checked_value;
	else if(checked_value=='')
	{
		checked_value='buy';
	}
	 
	
	url=url+"&buy_type="+checked_value+"";
	url=url+"&user_id="+user_id+"&page_name="+page_name+"";
	
	$.ajax({
		url: webUrl()+url,
		success: function(data){
			updateCartCount ();  
			showTheAssetResult(data);
		}
	}); 
	/*xmlHttp.onreadystatechange=stateChanged;

 	xmlHttp.open("GET",url,true);
 	xmlHttp.send(null);*/  
} 

function showTheAssetResult(html)
{
	if(html!="")
	{
		//$("#error_js #return_message").show(); 
		//$("#error_js #return_message").html(html); 
		
		$("#error_js #return_message").show().html(html).fadeIn('fast');
					setInterval(function() {
						$("#error_js #return_message").fadeOut('fast');
					}, 5000);
		
		
		if(document.getElementById('status').innerHTML=='yes')
		{
			if(document.getElementById('cartcountinput').value!=1)
			{
				var count = $('input#cartcountinput').val();
			}
			else if(document.getElementById('cartcountinput').value==1)
			{
				$('#cartcountcircle').show();		
			}
		}
		else if(document.getElementById('status').innerHTML=='Free' || document.getElementById('status').innerHTML=='FreeRent')
		{
			$('#freeprice').show();
			if(document.getElementById('status').innerHTML=='Free')	{ var linkto=''} 	
			if(document.getElementById('status').innerHTML=='FreeRent') { var linkto='&type=rent'} 	
			
			$('#ajax_show_purchased').removeClass('hide').addClass('show');
			var purchases_link = webUrl()+"my_purchases"+linkto;
			$('#freeprice').html('<a href="'+purchases_link+'"><div class="btn primary m_top_10">View It Now</div></a>');	
			var purchasednumber= + $('#ajax_show_purchased #showpurchased').html()+1
		
			if(purchasednumber>1)
				var purchasedtime=' times';
			else
				var purchasedtime=' time';
			$('#ajax_show_purchased #showpurchased').html(purchasednumber);
			$('#ajax_show_purchased #showpurchasetimes').html(purchasedtime);
		
		}
	 }else{
		 document.getElementById("return_message").innerHTML='<img src="'+staticUrlForImages()+'spin.gif" alt="Processing"/>';
	 }
	
}
function stateChanged() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		 
		 if(xmlHttp.responseText!="")
		 {
			 $("div#return_message").removeAttr("style");
			$("div#return_message").html(xmlHttp.responseText);
			if(document.getElementById('status').innerHTML=='yes')
			{
				
				updateCartCount (); //Function called to update cart count on click, by KKulkarni , defined in top_menu.php
				if(document.getElementById('cartcountinput').value!=1)
				{
					var count = document.getElementById('cartcountinput').value;
					document.getElementById('total_cartcountid').innerHTML= count;
					document.getElementById('cartcountinput').value=count+1;
				}
				else if(document.getElementById('cartcountinput').value==1)
				{
					$('#cartcountcircle').show();		
					document.getElementById('total_cartcountid').innerHTML='1'; 
				}
			}
			else if(document.getElementById('status').innerHTML=='Free' || document.getElementById('status').innerHTML=='FreeRent')
			{
				$('#freeprice').show();
				if(document.getElementById('status').innerHTML=='Free')	{ var linkto=''} 	
				if(document.getElementById('status').innerHTML=='FreeRent') { var linkto='&type=rent'} 	
				
				$('#ajax_show_purchased').removeClass('hide').addClass('show');
				var purchases_link = webUrl()+"my_purchases"+linkto;
				$('#freeprice').html('<a href="'+purchases_link+'"><div class="btn primary m_top_10">View It Now</div></a>');	
				var purchasednumber= + $('#ajax_show_purchased #showpurchased').html()+1
				
				if(purchasednumber>1)
					var purchasedtime=' times';
				else
					var purchasedtime=' time';
					
				$('#ajax_show_purchased #showpurchased').html(purchasednumber);
				$('#ajax_show_purchased #showpurchasetimes').html(purchasedtime);
			}		 
		 }
	 } 
	 else
	 {
		 document.getElementById("return_message").innerHTML='<img src="'+staticUrlForImages()+'spin.gif" alt="Processing"/>';
	 }
}

function showCartPopup(urlParam){
	$("div#modal-cart-dom").show();
	$("span#modal_body_cnts").html("");
	$.ajax({
		type		: "POST",
		cache	    : false,
		url		    :   urlParam,
		success: function(data) 
		{
			displayAddToCartDetails(data);
		}
	});
}

//Function To Extract The required Data from Response
function convertResponseToTableFormat(content){
	var modifiedHTMLResponse = "";
	var startPoint	=	parseInt(content.search("<tbody>"))+8;
	var endPoint	=	content.search("<\/tbody>");
	modifiedHTMLResponse = trim(content.substring(startPoint,endPoint));
	return modifiedHTMLResponse;
}

//Function To Display the resultant Add To Cart details 
function displayAddToCartDetails(content){
	var modifiedHTMLResponse = content;
	 $("span#modal_cart_body_cnts").html(modifiedHTMLResponse);
}

function reloadRating(buytype)
{
  	xmlHttp=GetXmlHttpObject()
 
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	
 	var url='/ajax_check_rating&popuph=yes&buytype='+buytype;
 	url=url+"&type=loadRating";
	
	
	xmlHttp.onreadystatechange=stateChanged_ReloadRating;
 	xmlHttp.open("GET",url,true);
 	xmlHttp.send(null);
} 

function stateChanged_ReloadRating() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		
		 if(xmlHttp.responseText!="")
		 {
			$('#showrating').show();	
			$('#showrating').html(xmlHttp.responseText);		
		 }
	 } 
}
