﻿
var key='';
var type=-1;
var n=10;
var start=0;

if(!getCookie("key"))SetCookie("key","");
else key=getCookie("key");

if(!getCookie("type"))SetCookie("type","");
else type=getCookie("type");

if(!getCookie("n"))SetCookie("n","10");
else n=getCookie("n");

if(!getCookie("start"))SetCookie("start","0");
else n = getCookie("start");


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ();  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}


 function getCookieVal (offset) 
   {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
   }	    
   
function SetCookie (name, value) 
   {  
   document.cookie = name+"="+value;
   }
   
function writeCookie (name, value) 
   {  
   document.cookie = name+"="+value;
   }
   
   var txtStart = 'Nhập nội dung tìm kiếm';
   
function Search()
{
    var txt = document.getElementById('textSearch');
    key = txt.value;
    if(key!=''&&key!=txtStart)
    {
    location.replace('Default.aspx?keyword=' + key + '&t=-1' + '&s=' + start + '&n=10');
    SetCookie('searchtype','-1');
    
    return false;
    }
    else
    {
        alert('Bạn phải nhập từ khóa');
        return false;
    }
}



function Focus()
{
    var txt = document.getElementById('textSearch');
    if(txt.value==txtStart)txt.value='';
    
}
function Blur()
{
    var txt = document.getElementById('textSearch');
    if(txt.value=='')
    {
    txt.value=txtStart;
    txt.className = 'textSearch1';
    }
}
function ChangeText()
{
    var txt = document.getElementById('textSearch');
    txt.className = 'textSearch';
}

function Load()
{
    if(key=='')
    var txt = document.getElementById('textSearch');
    txt.value = 'Nhập nội dung tìm kiếm';
    txt.className = 'textSearch1';
}

function ChangeType(type)
{
    delete_cookie('searchtype');
    SetCookie('searchtype',type);
}

function doResize(url,id,const_width,const_height)
{//alert(const_height);
	oImg = new Image();
	oImg.src =url;	
	scale = (const_width/oImg.width);
    new_width = const_width;
    new_height = parseInt(oImg.height * scale);	
	var oIdimag = document.getElementById(id);//alert(oIdimag);

	    oIdimag.style.width = new_width + "px";
	    oIdimag.style.height = new_height + "px";	
	    

}

