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 null
}
function setCookie(c_name,value,expiredays)
{var exdate=new Date()

exdate.setTime(exdate.getTime()+(expiredays*24*3600*1000))

document.cookie=c_name+ "=" +escape(value)+((expiredays==0) ? "" : "; expires="+exdate)

}

function OpenNewWindow(URL, Width, Height)
{
	window.open(URL,"_blank","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width="+Width+", height="+Height);
}

function OpenNewWindowWithNo(URL, Width, Height)
{
	window.open(URL,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width="+Width+", height="+Height);
}

function RemoveComma(TbxName)
{
	var Tbx=document.getElementById(TbxName)
	var TbxValue=Tbx.value;
	while(TbxValue.indexOf(",")>=0)
		TbxValue=TbxValue.replace(/,/, "");
	Tbx.value=TbxValue;
}

function BindSelect(dataSource,selectList)
{
	var select=document.getElementById(selectList);
	select.length=0;
	var dataList=new Array();
	if (dataSource.length!=0)
	{
		dataList=dataSource.split(',');
		for (index=0;index<dataList.length;index++)
		{
			var KeyValue=new Array();
			KeyValue=dataList[index].split('&');
			select.add(new Option(KeyValue[1],KeyValue[0]));
		}
	}
}

function Add(source,destination)
		{
			var src=document.getElementById(source);
			var des=document.getElementById(destination);
			for (;src.selectedIndex!=-1;)
			{
				var newOption=new Option(src.options[src.selectedIndex].innerText,src.options[src.selectedIndex].value);
				if (Contains(newOption,destination))
				{
					des.add(newOption);
				}
				src.options[src.selectedIndex].selected=false;
			}
		}
		function Remove(destination)
		{
			var des=document.getElementById(destination);
			for (;des.selectedIndex!=-1;)
			{
				des.remove(des.selectedIndex);
			}
		}
		function RemoveAll(destination)
		{
			var des=document.getElementById(destination);
			des.length=0;
		}
		function AddAll(source,destination)
		{
			var src=document.getElementById(source);
			var des=document.getElementById(destination);
			des.length=0;
			for (var index=0;index<src.length;index++)
			{
				var newOption=new Option(src.options[index].innerText,src.options[index].value);
				des.add(newOption);
			}
		}
function GetRequestContent(Key)
{
	var Url=document.location.href;
	if(Url.toLowerCase().indexOf(Key.toLowerCase())<0)
		return "";
	else
	{
		Url=Url.substr(Url.indexOf("?")+1, Url.length-Url.indexOf("?")-1);
		var List=Url.split("&");
		var Index=0;
		for(Index=0;Index<List.length;Index++)
		{
			if(List[Index].toLowerCase().indexOf(Key.toLowerCase()+"=")>=0)
				return List[Index].substr(List[Index].toLowerCase().indexOf(Key.toLowerCase()+"=")+Key.length+1, List[Index].length-List[Index].toLowerCase().indexOf(Key.toLowerCase()+"=")-Key.length-1);
			else continue;
		}
		return "";
	}
}

function ShowPage(PageIndex, PageName)
{

	if(PageIndex<=0)
		PageIndex=1;
	setCookie(PageName, PageIndex, 0);
	var Url=window.location.href;
	if(Url.toLowerCase().indexOf("ispostback")>=0)
		Url=Url.substr(0, Url.toLowerCase().indexOf("ispostback"))+"IsPostBack=true";
	else
	{
		if(Url.indexOf("?")>0)
			Url=Url+"&IsPostBack=true";
		else Url=Url+"?IsPostBack=true";
	}
	window.location.href=Url;
}

function SetHistory(CookieName,Value)
{
	var viewHistory=getCookie(CookieName);
	if (viewHistory==null||viewHistory.length==0)
		setCookie(CookieName,Value,30);
	else
	{
		var temp=new Array();
		temp=viewHistory.split(',');
		for (i=0;i<temp.length;i++)
		{
			if (Value==temp[i])
				return;
		}
		if (temp.length>=10)
			viewHistory=viewHistory.subString(viewHistory.indexOf(',')+1);
		viewHistory=Value+','+viewHistory;
		setCookie(CookieName,viewHistory,30);
	}
}