function checkAllotment(e,RateInput){ 
	var num=e.value; 
	if (num.length==0) {
	} else {
		re=/^(([1-9]\d*)|(0))$/; 
		if(re.test(num)) 
		{ 
			if (document.getElementById(RateInput).value=="") {
				alert("You cannot assign an allotment when the advertised room rate is blank.");
				e.value="";
				retrievePosition(e);		
			} 
		} 
		else 
		{ 
			alert("This field only allows numbers, eg. 10"); 
			e.value="";
			retrievePosition(e);
		} 
	}
} 


function checkInteger(e){ 
	var num=e.value; 
	if (num.length==0) {
	} else {
		re=/^(([1-9]\d*)|(0))$/; 
		if(re.test(num)) 
		{ 
		} 
		else 
		{ 
			alert("This field only allows numbers, eg. 10"); 
			e.value="";
			retrievePosition(e);
		} 
	}
} 

function checkIntegerNoBlank(e){ 
	var num=e.value; 
	if (num.length==0) {
		alert("Please fill this field with numbers");
		retrievePosition(e);
		return;
	} else {
		re=/^(([1-9]\d*)|(0))$/; 
		if(re.test(num)) 
		{ 
		} 
		else 
		{ 
			alert("This field only allows numbers, eg. 10"); 
			e.value="";
			retrievePosition(e);
		} 
	}
} 
		
		
		
function checkDecimal(e){ 
	var theValue=e.value; 
	if (theValue.length==0) {
	} else {
		rx = /[^0-9.]/;
		if(rx.test(theValue)) {
			alert("The field can only contain numbers");
			e.value="";
			retrievePosition(e);
			return;
		}
		if(theValue.indexOf(".") != -1) {
			theValue = theValue.substring(0,(theValue.indexOf(".") + 3));
		}
		lnt = theValue.length;
		if(lnt > 11) {
			if(theValue.indexOf(".") == -1) {
				theValue = theValue.substring(0,11);
			}else {
				theValue = theValue.substring(0,12);
			}
			lnt = theValue.length;
		}
		if(lnt > 9 && theValue.indexOf(".") == -1) {
			first = theValue.substring(0,9);
			second = theValue.substring(9);
			theValue = first + "." + second;
		}
		e.value = theValue;
	}
} 
			
function checkDecimalNoBlank(e){ 
	var theValue=e.value; 
	if (theValue.length==0) {
		alert("Please fill this field with numbers");
		retrievePosition(e);
		return;
	} else {
		rx = /[^0-9.]/;
		if(rx.test(theValue)) {
			alert("The field can only contain numbers");
			e.value="";
			retrievePosition(e);
			return;
		}
		if(theValue.indexOf(".") != -1) {
			theValue = theValue.substring(0,(theValue.indexOf(".") + 3));
		}
		lnt = theValue.length;
		if(lnt > 11) {
			if(theValue.indexOf(".") == -1) {
				theValue = theValue.substring(0,11);
			}else {
				theValue = theValue.substring(0,12);
			}
			lnt = theValue.length;
		}
		if(lnt > 9 && theValue.indexOf(".") == -1) {
			first = theValue.substring(0,9);
			second = theValue.substring(9);
			theValue = first + "." + second;
		}
		e.value = theValue;
	}
} 			
		
function checkNoBlank(e,msg)
{
	var NoBlankInput=document.getElementById(e);
	if (NoBlankInput.value=="") {
		alert(msg);
		retrievePosition(NoBlankInput);
		return false;
	} else {
		return true;
	}
	
}

		
function retrievePosition(e){
	setTimeout(function(){e.focus();e.select();} ,1);
}

function retrievePositionById(id){
	setTimeout(function(){document.getElementById(id).focus();document.getElementById(id).select();} ,1);
}


function CheckLength(TargetObject, MaxLenth){
        LenString = TargetObject.value.length;
        if (LenString > MaxLenth){
            TargetObject.value = TargetObject.value.substring(0,MaxLenth);
        }
    }
    
function CountDownLength(TargetObject, MaxLenth, DisplayObject){
        LenString = TargetObject.value.length;
        if (LenString > MaxLenth){
            TargetObject.value = TargetObject.value.substring(0,MaxLenth);
        }
        //Display how many characters remaining
        LenString = TargetObject.value.length;
        if ((MaxLenth - LenString) > 0 )
        {
			document.getElementById(DisplayObject).innerHTML = eval(MaxLenth - LenString) + " Character(s) Remaining"
        } else {
			document.getElementById(DisplayObject).innerHTML = "";
        }
        
        
    }    

function checkImageFileType(inputName){
	var upload= document.getElementById(inputName)
	var fullName = upload.value;
	var shortName = fullName.match(/[^\/\\]+$/);
	var splitName = fullName.split(".");
	var fileType = splitName[1];
	fileType = fileType.toLowerCase();
	if (fileType == 'jpg' || fileType == 'jpeg' || fileType=='gif')
	{
		return true;
	} else {
		alert("Please select a JPEG or Gif file no larger than 150kb!");
		return false;
	}
}       	

//For Telerik Floating Window
function GetSelectedWindow()
{
	var oManager = GetRadWindowManager();
	return oManager.GetActiveWindow();		
}

function PositionWindow () 
{
	var oWindow = GetSelectedWindow();	
	if (!oWindow) {
		return;
	}
	
	
	var Y = document.documentElement.clientHeight + 
			document.documentElement.scrollTop  -
			oWindow.GetHeight();
			
				
	var X = document.documentElement.clientWidth + 
			document.documentElement.scrollLeft - 10 -
			oWindow.GetWidth();
			
	Y = (Y > 0) ? Y : 0;
	X = (X > 0) ? X : 0;                    
	oWindow.MoveTo(X, Y);
}

function InitWindow () 
{
	var oWindow = GetSelectedWindow();	
	
	if (!oWindow) {
		window.setTimeout('InitWindow()', 500);
	}

	//window.onscroll = PositionWindow;
	//window.onresize = PositionWindow;
	PositionWindow();
}



function SizeToFit()
{
	window.setTimeout(
	function()
	{
	var oWnd = GetRadWindow();
	oWnd.SetWidth(document.body.scrollWidth + 4);
	oWnd.SetHeight(document.body.scrollHeight + 70);
	}, 400);
}

//This code is used to provide a reference to the radwindow "wrapper"
function GetRadWindow()
{
	var oWindow = null;
	if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
	else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)				
	return oWindow;
}

function CloseOnReload()
{
	GetRadWindow().Close();				
}

function RefreshParentPage()
{
	GetRadWindow().BrowserWindow.location.reload();
}

function RedirectParentPage(newUrl)
{
	GetRadWindow().BrowserWindow.document.location.href = newUrl;
}

function CallFunctionOnParentPage(fnName)
{
	var oWindow = GetRadWindow();
	if (oWindow.BrowserWindow[fnName] && typeof(oWindow.BrowserWindow[fnName]) == "function")
	{
		oWindow.BrowserWindow[fnName](oWindow);
	}
}

function SetCookie(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";path=/;expires=" + expire.toGMTString();
}

function ReadCookieArrayLength(cookieName) {
	var arrayValue =  ReadCookie(cookieName);
    var subCookieArray  = arrayValue.split('&');
	return subCookieArray.length;
}

function ReadCookie(cookieName) {
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf(cookieName);
    if (ind == -1 || cookieName == "") return "";
    var ind1 = theCookie.indexOf(';', ind);
    if (ind1 == -1) ind1 = theCookie.length;
    return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}

function DeleteCookie(cookieName) {
    var d = new Date();
    document.cookie = cookieName + "=;path=/;expires=" + d.toGMTString() + ";" + ";";
} 

            
	
