function Get(id){
	return document.getElementById(id);
}

function GetSelected(sel, nullValue){
	if(nullValue == null){
		nullValue = 0;
	}
	if(sel.selectedIndex < 0){
		return nullValue;
	}
	else{
		return sel[sel.selectedIndex].value;
	}
}

function AddElement(sel, value, text, index){
	//adding first (blank) item		
	var oOption = new Option(text, value);//document.createElement("OPTION");
	
	sel[sel.length] = oOption;
	
	oOption.innerText = text;
	oOption.value = value;
}

function ClearDropDown(sel){
	while(sel.options.length > 0){
		sel.options.remove(0);
	}
}

function PageReload(){
	document.location = document.location.href;
}

//----------------- COOKIE ----------------------------
function SetCookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" + value +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );

}

// this function gets the cookie, if it exists
function GetCookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return document.cookie.substring( len, end );
}


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function AddToList(list, separator, item){
	var list = RemoveFromList(list, separator, item);
	if(list && list.length > 0){
		list += separator + item;
	}
	else{
		list = item;
	}
	return list;
}

//----------------- STRING ---------------------
function RemoveFromList(list, separator, item){
	var newList = "";
	if(list && list.length > 0){
		var ary = list.split(separator);
		for(var i=0; i<ary.length; i++){
			if(ary[i] != item){
				newList += separator + ary[i];
			}
		}
		if(newList.length > 0){
			newList = newList.substr(separator.length, newList.length - separator.length);
		}	
	}
	return newList;
}


//------------------ DATE ----------------------

function isDate(strDate){

	var ary = strDate.split("/");
	if(ary.length != 3){
		return false;
	}
	else{
		return isValidDate(ary[1], ary[0] - 1, ary[2]);
	}
}

function isValidDate(day,month,year){

	var dteDate;

	//set up a Date object based on the day, month and year arguments
	//javascript months start at 0 (0-11 instead of 1-12)
	dteDate=new Date(year,month,day);

	//Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date object is different, then it must have been an invalid date to start with...

	return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}

//-----------------------------------------------------------
function isEnter(e) {
	var pK = e.which ? e.which : window.event.keyCode;
	return pK == 13;
}
