function addTofavorite(notes_id,status,baseurl,from)
{
	// if(document.getElementById("favlist"+notes_id) != null)
	// {	
	// document.getElementById('favlist'+notes_id).innerHTML = "Loading...";
	// }
    var myAjax = new Ajax.Request(baseurl+'/accountcanvas/dofavorite',
	{method: 'get', parameters: {clipid: notes_id,stat:status,burl:baseurl,from:from},onComplete:handleResponse,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to add clips to favorites';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to add clips to favorites';}});
	
}
function handleResponse(transport)
{
	var  str = transport.responseText;
	
    if(str.search(/An error occurred/) == -1 )
    {    	
    	var action = str.substring(0,1);
        len = str.search(/#/);
        var clipid = str.substring(1,len);
        urllen = str.search(/@/);
        var fvcnt = str.substring(len+1,urllen);
        var frmlen = str.search(/~/);
        var from = str.substring(urllen+1,frmlen);
        var baseurl = str.substring(frmlen+1);
        
        var favlist 		= document.getElementById("favlist"+clipid);
        var navbarFavlist 	= document.getElementById('navbar_favlist'+clipid);
        var favcount	 	= document.getElementById('favcount');
        
		if(action == 'L'){
			window.location.href = baseurl+'/login';
			return false;
			
		}else if(action == 'A'){
			
			if(favcount)
				favcount.innerHTML = fvcnt;
						
			 if(favlist)
			 {	
				 if(from == 'F')
					 favlist.innerHTML = "<a class=\"removeFromCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'R','"+baseurl+"','F'); return false;\">Remove from favourites</a>";                                    
                 else
                	 favlist.innerHTML = "<a class=\"removeFromCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'R','"+baseurl+"'); return false;\">Remove from favourites</a>";
			 }
			 
			 if(navbarFavlist)
			 {	
				 if(from == 'F')
					 navbarFavlist.innerHTML = "<a class=\"removeFromCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'R','"+baseurl+"','F'); return false;\">Remove from favourites</a>";                                    
                 else
                	 navbarFavlist.innerHTML = "<a class=\"removeFromCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'R','"+baseurl+"'); return false;\">Remove from favourites</a>";
			 }
			 
		}else{
			
			if(favcount)
				favcount.innerHTML = fvcnt;
			
			 if(favlist){
				 if(from == 'F')
					 favlist.innerHTML = "<a class=\"addToCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'A','"+baseurl+"','F'); return false;\">Add to favourites</a>";
				 else
                 	favlist.innerHTML = "<a class=\"addToCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'A','"+baseurl+"'); return false;\">Add to favourites</a>";
			}
			 
			 if(navbarFavlist){
				 if(from == 'F')
					 navbarFavlist.innerHTML = "<a class=\"addToCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'A','"+baseurl+"','F'); return false;\">Add to favourites</a>";
				 else
					 navbarFavlist.innerHTML = "<a class=\"addToCanvas\" href=\"javascript:void(0);\" onclick=\"addTofavorite("+clipid+",'A','"+baseurl+"'); return false;\">Add to favourites</a>";
			}
		}
    }else{
       document.getElementById('resultdisp').innerHTML='Unable to add clips to favorites';
    }
}


function loadSmallvideo(clipid,baseurl, controlval)
{
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
        if(hasReqestedVersion == -1)
        {
			 if(document.getElementById("viewsml"+clipid) != null)
			 {
			 document.getElementById("viewsml"+clipid).innerHTML = "<a target='_blank' href='http://www.macromedia.com/go/getflashplayer'><img border='0' src='http://static.clipcanvas.com/files/gfx/getflash_small.png' alt=''/></a>";
			 }
            if(clipid != document.getElementById("playvideo").value)
            {
                if(document.getElementById("playvideo").value=='')
                {
					if(document.getElementById('playvideo') != null)
						{
                        document.getElementById("playvideo").value = clipid;
						}
                }
                else
                {

                        var oldclipid = document.getElementById("playvideo").value;
                        var clpimg = oldclipid+".jpg";
						
						if(document.getElementById("viewsml"+oldclipid) != null)
						{
                        document.getElementById("viewsml"+oldclipid).innerHTML = "<img border='0' src='http://static.clipcanvas.com/thumbs/small/"+clpimg+"' alt='' />";
						}
						if(document.getElementById('playvideo') != null)
						{
                        document.getElementById("playvideo").value = clipid;
						}
                }
            }
		}else
		{
				if(document.getElementById("playvideo").value=='')
            {
					if(document.getElementById('playvideo') != null)
						{
							document.getElementById("playvideo").value = clipid;
				        }
            }
            else
            {

                    var oldclipid = document.getElementById("playvideo").value;
                    var clpimg = oldclipid+".jpg";
					if(document.getElementById('viewsml'+oldclipid) != null)
					{
                    document.getElementById("viewsml"+oldclipid).innerHTML = "<img border='0' src='http://static.clipcanvas.com/thumbs/small/"+clpimg+"' alt='' />";
					}
					if(document.getElementById('playvideo') != null)
					{
                    document.getElementById("playvideo").value = clipid;
					}
            }
			
if(controlval==null) controlval='search';		
            var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadsmallvideo',
            {method: 'get', parameters: {clipid: clipid,flashplay:hasReqestedVersion},onComplete: handleResponsevideo,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load videos';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load videos';}});

		}			
	
}
function handleResponsevideo(transport)
{
	var str = transport.responseText;
   if(str.search(/An error occurred/) == -1 )
  {
	var len = str.search(/<object/);
	var clipid = str.substring(0,len);
	var orginal = str.substring(len);
	if(document.getElementById('viewsml'+clipid) != null)
	{
	document.getElementById('viewsml'+clipid).innerHTML = orginal;
	}
  }
  else
      {
          document.getElementById('viewsml').innerHTML='Unable to load videos';
      }
}

/*addtocart ajax function call*/
function addTocart(notes_id,status, price, totalprice, totalcount, currency, user_id,from,urlvalue)
{
	//if(document.getElementById('add'+notes_id) != null)
	//{
	//	document.getElementById('add'+notes_id).innerHTML = "Loading...";
	//}	
	var myAjax = new Ajax.Request(urlvalue+'/cart/addtocart',
	{method: 'post', parameters: {clipid: notes_id,stat:status, price: price, totalprice:totalprice, totalcount:totalcount, currency:currency, userid:user_id,from:from,urlval:urlvalue},onComplete: handleAddToCartResponse,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to add clip to cart.';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to add clip to cart. Got exception.';}});
	
}
function addTologcart(notes_id,status, price, totalprice, currency, user_id, source,urlvalue)
{
        //if(document.getElementById('add'+notes_id) != null)
	//{
	//	document.getElementById('add'+notes_id).innerHTML = "Loading...";
	//}	
	var myAjax = new Ajax.Request(urlvalue+'/cart/addtologcart',
	{method: 'post', parameters: {clipid: notes_id,stat:status, price: price, totalprice:totalprice, currency:currency, userid:user_id,from:source,urlval:urlvalue},onComplete: handleAddToLogCartResponse,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to add clip to cart';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to add clip to cart';}});
	
}

function handleAddToLogCartResponse(transport)
{
	var str = transport.responseText;
if(str.search(/An error occurred/) == -1 )
  {
	var action = str.substring(0,1);
        if(action!='D')
        {
            var len = str.search(/_/);
            var clipid = str.substring(1,len);
            var len1 = str.search(/@/);
            var price = str.substring(len+1,len1);
            var len2 = str.search(/#/);
            var cartprice = str.substring(len1+1,len2);
            var len3 = str.search(/-/);
            var cartcount = str.substring(len2+1,len3);
            var len4 = str.search(/%/);
            var cartcurrency = str.substring(len3+1,len4);
            var len5 = str.search(/~/);
            var cartuser =str.substring(len4+1,len5);
            var len6 = str.search(/!/);
            var from = str.substring(len5+1,len6);
            var urlval = str.substring(len6+1);
            if(from != 'S')
            {
                var forlen = from.search(/\*/);
                var fromval = from.substring(0,forlen);
                var fortype = from.substring(forlen+1);
            }
            else
            {
                var fromval = from;
            }
           
            if(action == 'A')
            {
                    if(fromval == 'F')
                    {
                            if(document.getElementById('add'+clipid) != null)
                            {
                                document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer;background:none;' onclick=javascript:addTologcart("+clipid+",'R','"+price+"','"+cartprice+"','"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')><img src='" + urlval + "/images/remove-from-cart.gif' width='424' height='55' alt='Remove from shopping cart' /></a>";
                            }
		        if ($('numclips') && $('incart') && $('buy_button'))
		        {
		            $('numclips').innerHTML = cartcount;
		            $('incart').setAttribute("class","incart_visible");
		            $('incart').setAttribute("className","incart_visible");
		            $('buy_button').setAttribute("class","buy_button_added");
		            $('buy_button').setAttribute("className","buy_button_added");
		            $('buy_button').href='#';
		        }
                    }
                    else
                    {

                            if(document.getElementById('add'+clipid) != null)
                            {
                                document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer' onclick=javascript:addTologcart("+clipid+",'R','"+price+"','"+cartprice+"','"+cartcurrency+"',"+cartuser+",'E','"+urlval+"')>Remove from cart</a>";
                            }
                    }

					if(document.getElementById('commercial') != null)
					{
                    document.getElementById('commercial').innerHTML = "<div id=\"shoppingCart\"><h4><a href="+urlval+"/cart>Shopping&nbsp;cart</a></h4><div class=\"content\"><div id=\"shoppingdesc\">You have <strong>"+cartcount+"</strong> clips in your shopping cart</div><div id=\"total\">Total: "+cartprice+" "+cartcurrency+"</div><div style=\"float:left;\"><a href="+urlval+"/cart>Proceed&nbsp;to&nbsp;checkout</a></div><!-- <div style=\"float:right;\"><a href="+urlval+"/cart?clearlog=1>Clear&nbsp;cart</a></div> --><div class=\"clearBoth\"></div></div></div>";
					}

            }
            else
            {
                    if(fromval =='F')
                    {
                            if(document.getElementById('add'+clipid) != null)
                            {
                                if(fortype == 'hd')
                                {
                                    document.getElementById('add'+clipid).innerHTML = "<a  class='addToCart' style='cursor:pointer;background:none;'  onclick=javascript:addTologcart("+clipid+",'A','"+price+"','"+cartprice+"','"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')><img src='" + urlval + "/images/add-HD-format-to-cart.gif' width='424' height='55' alt='Add to shopping cart' alt='' /></a>";
                                }
                                else
                                {
                                    document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer;background:none;'  onclick=javascript:addTologcart("+clipid+",'A','"+price+"','"+cartprice+"','"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')><img src='" + urlval + "/images/add-SD-format-to-cart.gif' width='424' height='55' alt='Add to shopping cart' alt='' /></a>";
                                }

                            }
						
                    }
                    else
                    {

                            if(document.getElementById('add'+clipid) != null)
                            {
                                document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer'  onclick=javascript:addTologcart("+clipid+",'A','"+price+"','"+cartprice+"','"+cartcurrency+"',"+cartuser+",'E','"+urlval+"')>"+price+cartcurrency+" &nbsp;Add&nbsp;to&nbsp;cart</a>";
                            }
                    }
                    if(cartcount >=1 )
               {
				if(document.getElementById('commercial') != null)
				{
				document.getElementById('commercial').innerHTML = "<div id=\"shoppingCart\"><h4><a href="+urlval+"/cart>Shopping&nbsp;cart</a></h4><div class=\"content\"><div id=\"shoppingdesc\">You have <strong>"+cartcount+"</strong> clips in your shopping cart</div><div id=\"total\">Total: "+cartprice+" "+cartcurrency+"</div><div style=\"float:left;\"><a href="+urlval+"/cart>Proceed&nbsp;to&nbsp;checkout</a></div><!-- <div style=\"float:right;\"><a href="+urlval+"/cart?clearlog=1>Clear&nbsp;cart</a></div> --><div class=\"clearBoth\"></div></div></div>";
				}
              }else
              {
				if(document.getElementById('commercial') != null)
				{
              document.getElementById('commercial').innerHTML = "<br /><img src=\"http://static.clipcanvas.com/files/gfx/commercial.gif\" width=\"242\" height=\"61\" alt=\"Making Footage Work!\" alt='' />";
				}
              }
            }
        }
  }
  else
      {
          document.getElementById('resultdisp').innerHTML='Unable to add clip to cart';
      }
}

function handleAddToCartResponse(transport)
{

	var str = transport.responseText;
  if(str.search(/An error occurred/) == -1 )
  {
	var action = str.substring(0,1);
	var len = str.search(/_/);
	var clipid = str.substring(1,len);
	var len1 = str.search(/@/);
	var price = str.substring(len+1,len1);
	var len2 = str.search(/#/);
	var cartprice = str.substring(len1+1,len2);
	var len3 = str.search(/-/);
	var cartcount = str.substring(len2+1,len3);
	var len4 = str.search(/%/);
	var cartcurrency = str.substring(len3+1,len4);
	var len5 = str.search(/~/);
	var cartuser =str.substring(len4+1,len5);
        var len6 = str.search(/!/);
	var from = str.substring(len5+1,len6);
        var urlval = str.substring(len6+1);

        if(from != 'S')
        {
            var forlen = from.search(/\*/);
            var fromval = from.substring(0,forlen);
            var fortype = from.substring(forlen+1);
        }
        else
        {
            var fromval = from;
        }
	if(action == 'L')
	{
		document.frmsearch.action = 'login';
		document.frmsearch.submit();	
	}

	if(action == 'A')
	{
		if(fromval == 'F')
                {
                    if(document.getElementById('add'+clipid) != null)
                    {
                        document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer;background:none;' onclick=javascript:addTocart("+clipid+",'R','"+price+"','"+cartprice+"',"+cartcount+",'"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')><img src='" + urlval + "/images/remove-from-cart.gif' width='424' height='55' alt='Remove from cart' /></a>";
                    }
		    if ($('numclips') && $('incart') && $('buy_button'))
		    {
		        $('numclips').innerHTML = cartcount;
		        $('incart').setAttribute("class","incart_visible");
		        $('incart').setAttribute("className","incart_visible");
		        $('buy_button').setAttribute("class","buy_button_added");
		        $('buy_button').setAttribute("className","buy_button_added");
		        $('buy_button').href='#';
		    }
                }
                else
		{
			if(document.getElementById('add'+clipid) != null)
			{
                            document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer' onclick=javascript:addTocart("+clipid+",'R','"+price+"','"+cartprice+"',"+cartcount+",'"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')>Remove&nbsp;from&nbsp;cart</a>";
			}
		}
			if(document.getElementById('commercial') != null)
			{
			document.getElementById('commercial').innerHTML = "<div id=\"shoppingCart\"><h4><a href="+urlval+"/cart>Shopping&nbsp;cart</a></h4><div class=\"content\"><div id=\"shoppingdesc\">You have <strong>"+cartcount+"</strong> clips in your shopping cart</div><div id=\"total\">Total: "+cartprice+" "+cartcurrency+"</div><div style=\"float:left;\"><a href="+urlval+"/cart>Proceed&nbsp;to&nbsp;checkout</a></div><!-- <div style=\"float:right;\"><a href="+urlval+"/cart?clear=1&amp;usid="+cartuser+">Clear&nbsp;cart</a></div> --><div class=\"clearBoth\"></div></div></div>";
			}
		
	}
	else
	{
		if(fromval == 'F')
                {
                    if(document.getElementById('add'+clipid) != null)
			{
                            if(fortype == 'sd')
                            {
                                  document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer;background:none;'  onclick=javascript:addTocart("+clipid+",'A','"+price+"','"+cartprice+"',"+cartcount+",'"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')><img src='" + urlval + "/images/add-SD-format-to-cart.gif' width='424' height='55' alt='Add to shopping cart' alt='' /></a>";
                            }
                            else
                            {
                                    document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer;background:none;'  onclick=javascript:addTocart("+clipid+",'A','"+price+"','"+cartprice+"',"+cartcount+",'"+cartcurrency+"',"+cartuser+",'"+from+"','"+urlval+"')><img src='" + urlval + "/images/add-HD-format-to-cart.gif' width='424' height='55' alt='Add to shopping cart' alt='' /></a>";
                            }
			}
                }
		else
		{
			if(document.getElementById('add'+clipid) != null)
			{
                            document.getElementById('add'+clipid).innerHTML = "<a class='addToCart' style='cursor:pointer'  onclick=javascript:addTocart("+clipid+",'A','"+price+"','"+cartprice+"',"+cartcount+",'"+cartcurrency+"',"+cartuser+",'S','"+urlval+"')>"+price+cartcurrency+"&nbsp;Add&nbsp;to&nbsp;cart</a>";
			}
		}
	   if(cartcount >=1 )
	   {
	   if(document.getElementById('commercial') != null)
		{
	  document.getElementById('commercial').innerHTML = "<div id=\"shoppingCart\"><h4><a href="+urlval+"/cart>Shopping&nbsp;cart</a></h4><div class=\"content\"><div id=\"shoppingdesc\">You have <strong>"+cartcount+"</strong> clips in your shopping cart</div><div id=\"total\">Total: "+cartprice+" "+cartcurrency+"</div><div style=\"float:left;\"><a href="+urlval+"/cart>Proceed&nbsp;to&nbsp;checkout</a></div><!-- <div style=\"float:right;\"><a href="+urlval+"/cart?clear=1&amp;usid="+cartuser+">Clear&nbsp;cart</a></div> --><div class=\"clearBoth\"></div></div></div>";
		}
	  }else
	  {
		if(document.getElementById('commercial') != null)
		{
			document.getElementById('commercial').innerHTML = "<br><img src=\"http://static.clipcanvas.com/files/gfx/commercial.gif\" width=\"242\" height=\"61\" alt=\"Making Footage Work!\" alt='' />";
		}
	  }
	}
         }
  else
      {
          document.getElementById('resultdisp').innerHTML='Unable to add clip to cart';
      }
}

function loadFrontPageVideo()
{
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if(hasReqestedVersion == -1)
    {
		if(document.getElementById('frontpage') != null)
		{
        //document.getElementById('frontpage').innerHTML = "<a target='_blank' href='http://www.macromedia.com/go/getflashplayer'><img border='0' src='http://static.clipcanvas.com/cc-forsidevideo.png' alt='' /></a>";
		}
    }
    else
    {
		if(document.getElementById('frontpage') != null)
		{
		// document.getElementById('frontpage').innerHTML = "<a target='_blank' href='http://www.macromedia.com/go/getflashplayer'><img border='0' src='http://static.clipcanvas.com/cc-forsidevideo.png' alt=''/></a>";
		}
        var myAjax = new Ajax.Request('index/loadfrontpagevideo',
            {method: 'get', parameters: {flashver:hasReqestedVersion},onComplete: handleResponsefrontpagevideo,onFailure: function(transport){document.getElementById('frontpage').innerHTML='Unable to load videos';},onException: function(err){document.getElementById('frontpage').innerHTML='Unable to load videos';}});
    }
}
function handleResponsefrontpagevideo(transport)
{
	str = transport.responseText;
if(str.search(/An error occurred/) == -1 )
 {
	if(document.getElementById('frontpage') != null)
		{
			document.getElementById('frontpage').innerHTML = str;
		}	
 }
 else
     {
         document.getElementById('frontpage').innerHTML='<h2>Unable to load videos</h2>';
     }
}





function loadlargevideo(clipid,absolute_path,controlval)
{
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
       
        if(hasReqestedVersion == -1)
        {
			if(document.getElementById('biclipshow') != null)
			{
            document.getElementById("biclipshow").innerHTML = "<a target='_blank' href='http://www.macromedia.com/go/getflashplayer'><img border='0' src='http://static.clipcanvas.com/files/gfx/getflash_medium.png' alt='' /></a>";
			}
          
        }
        else
        {
			/*if(document.getElementById('biclipshow') != null)
			{
			document.getElementById("biclipshow").innerHTML = "<a target='_blank' href='http://www.macromedia.com/go/getflashplayer'><img border='0' src='http://static.clipcanvas.com/files/gfx/getflash_medium.png' alt=''/></a>";
			}*/

			if(controlval==null) controlval ='details';


           var myAjax = new Ajax.Request(absolute_path+'/'+controlval+'/loadlargevideo',
                        {method: 'get', parameters: {clipid:clipid,flashver:hasReqestedVersion},onComplete: handleResponselargevideo,onFailure: function(transport){document.getElementById('biclipshow').innerHTML='Unable to load videos';},onException: function(err){document.getElementById('biclipshow').innerHTML='Unable to load videos';}});
                        // alert(document.getElementById("resultdisp").innerHTML);
        }



}
function handleResponselargevideo(transport)
{
	var str = transport.responseText;
	//alert(str);
         if(str.search(/An error occurred/) == -1 )
             {
	if(document.getElementById('biclipshow') != null)
	{
	document.getElementById('biclipshow').innerHTML = str;
	}
             }
             else
                 {
                     document.getElementById('biclipshow').innerHTML='<h2>Unable to load videos</h2>';
                 }
}


function submitnewSearch(urlval, controlval)
{
   	var q = document.getElementById("q").value;
    q = q.replace(/\s\s+/, ' ');
    document.getElementById("q").value = unescape(q);
    
    if(controlval==null) controlval='search';
    
	if(document.getElementById("q").value!="")
	{		
        document.frmnewsearch.action=urlval+"/"+controlval+"?q="+q;
        document.frmnewsearch.submit();
	}else{
		window.location.href = urlval+"/"+controlval;
	}	       
}
function submitexistSearch(urlval, controlval)
{
var activestatus = document.getElementById("activestatus").value;
var q = document.getElementById("q").value;
q = q.replace(/\s\s+/, ' ');
q = q.replace(/<\/?[^>]+(>|$)/g, "");
q = q.replace("\"", "");
document.getElementById("q").value = q;

if(controlval==null) controlval='search';
if(activestatus == 'search' || activestatus == 'mysearch')
    {

        if(document.getElementById("calldata"))
            {
                var callfromparam = document.getElementById("calldata").value;

                var paramarray=Array();
                        paramarray = callfromparam.split('&');
                        var str="";
                        for(i=0;i<paramarray.length;i++)
                        {

                                if(paramarray[i].search(/q=/) == -1 && paramarray[i].search(/page=/) == -1)
                                {
                                    if(paramarray[i].search(/noresult=/) == -1 )
                                     {
                                        if(paramarray[i] != '=')
                                        {
                                                if(str == '?' || str == '')
                                                {
                                                str=str+paramarray[i];
                                                }
                                                else
                                                {
                                                str=str+'&'+paramarray[i];
                                                }
                                        }
                                }
                            }

                        }
                 
                        if(str != '')
                            {
                                document.frmnewsearch.action=urlval+"/"+controlval+"?q="+URLEncode(q)+"&"+str;
                            }
                            else
                                {
                                    document.frmnewsearch.action=urlval+"/"+controlval+"?q="+URLEncode(q);
                                }

                        location.href =document.frmnewsearch.action;
            }
    }
    else
        {
			
             document.frmnewsearch.action=urlval+"/"+controlval+"?q="+URLEncode(q);
             location.href =document.frmnewsearch.action;
        }

}
function ajaxsearchcount(hrefval,baseurl,controlval,owner)
{
if(controlval == null)
{
controlval='search';
}


    hrefval = hrefval.replace(/&amp;/g, "&")
    //document.frmnewsearch.q.focus();

	if(owner > 0)
	{						
		   var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'status'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});	
				var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'cat'},onComplete: handleResponsecatspfcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'hand'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'frame'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'price'},onComplete: handleResponsecatcountprice,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'dyna'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'light'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'format'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'special'},onComplete: handleResponsecatspfcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
							
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval+'&owner='+owner,
								{method: 'get', parameters: {scene:'lic'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});					
	}else
	{
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'cat'},onComplete: handleResponsecatspfcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'hand'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'frame'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'price'},onComplete: handleResponsecatcountprice,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'dyna'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'light'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'format'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'special'},onComplete: handleResponsecatspfcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
							
			var myAjax = new Ajax.Request(baseurl+'/'+controlval+'/loadcategorycount?'+hrefval,
								{method: 'get', parameters: {scene:'lic'},onComplete: handleResponsecatcount,onFailure: function(transport){document.getElementById('resultdisp').innerHTML='Unable to load counts';},onException: function(err){document.getElementById('resultdisp').innerHTML='Unable to load counts';}});
	}							


   /* var myAjax = new Ajax.Request('search/loadhandlingcount',
                        {method: 'post', parameters: {hrefpar:hrefval},onComplete: handleResponsecatcount});
                        
   var myAjax = new Ajax.Request('search/loadhandlingcount',
                        {method: 'post', parameters: {hrefpar:hrefval},onComplete: handleResponsecatcount});*/
}
function handleResponsecatcount(transport)
{
    //document.getElementById('resultdisp').innerHTML='';
		var str = transport.responseText;
        
          if(str.search(/An error occurred/) == -1 )
              {
        var catarray = Array();
			catarray = str.split('~');

        for(i=0;i<catarray.length;i++)
        {

           var len = catarray[i].search(/=/);
           var eleid = catarray[i].substring(0,len);
           var lenhid = catarray[i].search(/#/);
           var elecount = catarray[i].substring(len+1,lenhid);
           var elehid = catarray[i].substring(lenhid+1);
            if(elehid != '')
            {
				eleid = eleid.replace(/ /g,'_');
				if(document.getElementById('cat'+eleid) != null)
				{
				document.getElementById('cat'+eleid).innerHTML =eleid.replace(/_/g,' ')+' ('+elecount+')';
				}
            }
             else
            {
				eleid = eleid.replace(/ /g,'_');
				if(document.getElementById('li'+eleid) != null)
				{
				document.getElementById('li'+eleid).innerHTML = '<span class="inactive">'+eleid.replace(/_/g,' ')+'&nbsp;(0)</span>';
				}               
            }
       }
     }
     else
         {
             document.getElementById('resultdisp').innerHTML='Unable to load counts';
         }

}

function handleResponsecatspfcount(transport)
{
   // document.getElementById('resultdisp').innerHTML='';
	var str = transport.responseText;
        var catarray = Array();
			catarray = str.split('~');

        for(i=0;i<catarray.length;i++)
        {

           var len = catarray[i].search(/=/);
           var eleid = catarray[i].substring(0,len);
           var lenhid = catarray[i].search(/#/);
           var elecount = catarray[i].substring(len+1,lenhid);
           var elehid = catarray[i].substring(lenhid+1);
              
            if(elehid != '')
            {

               // alert(document.getElementById('cat'+eleid.replace(' ','_')).id);
				if(document.getElementById('cat'+eleid) != null)
				{
					document.getElementById('cat'+eleid).innerHTML =eleid.replace(/_/g,' ')+' ('+elecount+')';
				}	
            }
             else
            {
                //alert(document.getElementById('cat'+eleid.replace(' ','_')).id);
                if(document.getElementById('li'+eleid) != null)
				{
			   document.getElementById('li'+eleid).innerHTML = '<a class="check_invisible"><span class="inactive">'+eleid.replace(/_/g,' ')+'&nbsp;(0)</span></a>';
			   }
               
            }
       }
}

function handleResponsecatcountprice(transport)
{
    //document.getElementById('resultdisp').innerHTML='';
	var str = transport.responseText;
                
        var catarray = Array();
			catarray = str.split('~');

        for(i=0;i<catarray.length;i++)
        {

           var len = catarray[i].search(/=/);
           var eleid = catarray[i].substring(0,len);
           var lenhid = catarray[i].search(/#/);
           var elecount = catarray[i].substring(len+1,lenhid);
           var elehid = catarray[i].substring(lenhid+1);
            if(elehid != '')
            {
				if(document.getElementById('cat'+eleid) != null)
				{
				document.getElementById('cat'+eleid).innerHTML =eleid.replace(/_/g,' ')+'&nbsp;'+'&euro;'+' ('+elecount+')';
				}
            }
             else
            {
				if(document.getElementById('li'+eleid) != null)
				{
				document.getElementById('li'+eleid).innerHTML = '<span class="inactive">'+eleid.replace(/_/g,' ')+'&nbsp;'+'&euro;'+'&nbsp;(0)</span>';
				}
            }
       }
}

function limitChange(linkvalue)
{
	_limitChange(linkvalue, 'frmlimitsearch', 'changelimit');
}


function limitChangebottom(linkvalue)
{	
	_limitChange(linkvalue, 'frmlimitsearchbottom', 'changelimitbottom');
}


function _limitChange(linkvalue, fromName, selectId){

	document.getElementById(selectId).disabled = true;
	var limitvalue = document.getElementById(selectId).value;


	var limitarray = linkvalue.split('&');
	var str = "";
	
	for(i=0;i<limitarray.length;i++)
	{
		if(limitarray[i].search(/pagelimit=/) == -1 )
		{
			if(limitarray[i] != '=')
			{
				if(str == '?' || str == '')
				{
				str=str+limitarray[i];
				}
				else
				{
				str=str+'&'+limitarray[i];
				}
			}
		}
		else
		{
			if(i == 0)
			{
			str = '?';
			}
		}
	}


	if(str == '' || str == '?=' || str == '?')
	{
		document.forms[fromName].action = "?pagelimit="+limitvalue;
	}
	else
	{
		document.forms[fromName].action = str+"&pagelimit="+limitvalue;		
	}	
	
	document.forms[fromName].submit();
}

function redirectme(controlval)
{
if(controlval == null){
controlval='search';
}
    if(document.getElementById('q').value != '')
        {

            window.location = controlval;
             
        }
        else
            {
                 window.location = controlval;
            }

}
/* function for tags show/hide option */
function showHide(shID) {
    if (document.getElementById(shID)) {
	    if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
			document.getElementById(shID+'-hide').style.display = 'block';
			if (document.getElementById(shID+'-show1').style.display != 'none') {	
				document.getElementById(shID+'-show1').style.display = 'none';
			}else
			{
				document.getElementById(shID+'-show1').style.display = 'block';
			}
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
			document.getElementById(shID+'-hide').style.display = 'none';
            document.getElementById(shID).style.display = 'none';
			if (document.getElementById(shID+'-show1').style.display != 'none') {	
				document.getElementById(shID+'-show1').style.display = 'none';
			}else
			{
				document.getElementById(shID+'-show1').style.display = 'inline';
			}
        }
    }
}

function URLEncode( q )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = q;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode( q )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = q;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return plaintext;
}
