function Dimension(element){
      this.x=-1;
      this.y=-1;
      this.w=0;
      this.h=0;
      if (element==document){
            this.x=element.body.scrollLeft;
            this.y=element.body.scrollTop;
            this.w=element.body.clientWidth;
            this.h=element.body.clientHeight;
      }else if (element!=null){
            var e=element;
            var left=e.offsetLeft;
            while ((e=e.offsetParent)!=null) {
                  left+=e.offsetLeft;
            }
            var e=element;
            var top=e.offsetTop;
            while((e=e.offsetParent)!=null) {
                  top+=e.offsetTop;
            }
            this.x=left;
            this.y=top;
            this.w=element.offsetWidth;
            this.h=element.offsetHeight;
      }
}
// id -> id do elemento pai
// texto a mensagem a ser exibida
// o id da nova div
// ex: hotelowner repchannel.jsp
function mostrar(id, texto, codigo) {	

	element   = document.getElementById(id);
	dimension = new Dimension(element);

	x = dimension.x;
	y = dimension.y;	
	
	div = document.createElement("div");
	
	div.style.position='absolute';
	
	div.style.top = y + 10;
	div.style.left = x + 70;

	/*var attrClass = document.createAttribute("class");
	attrClass.value = "tooltip";
	div.setAttributeNode(attrClass);*/
	div.style.zIndex = '1';
	div.style.backgroundColor = "#FFFFCC";
	div.style.border = "1px solid #EBEB47";
	div.style.whiteSpace = "nowrap";
	div.style.padding = "5px";
	div.innerHTML = texto;
	div.id = codigo;

	element.appendChild(div);
}
// idTextod -> id do elemento pai
// cod -> id do Elemento filho
function esconder(idTexto, cod) {

	el    =  document.getElementById(idTexto);
	texto =  document.getElementById(cod);
	texto.style.visibility = 'hidden';
	texto.id = '';
}
// email check.

function emailCheck (emailStr)
{
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
	{
		// alert("Email address seems incorrect (check @ and .'s)")
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	if (user.match(userPat)==null)
	{
		// alert("The username doesn't seem to be valid.")
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				// alert("Destination IP address is invalid!")
				return false;
    		}
   		}
   		return true;
	}

	var domainArray=domain.match(domainPat);
	if (domainArray==null)
	{
		// alert("The domain name doesn't seem to be valid.");
		return false;
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
   		// alert("The address must end in a three-letter domain, or two letter country.")
   		return false;
	}

	if (len<2)
	{
   		// var errStr="This address is missing a hostname!";
   		// alert(errStr);
   		return false;
	}

	return true;
}

//Check digit
function isDigit(str)
{
	var ltdArray = new Array("1","2","3","4","5","6","7","8","9","0");
	var ch;
	for(var i=0; i<str.length; i++ )
	{
		var ltdch = false;
		ch = str.substring(i,i+1);
		for(var j in ltdArray)
		{
			if(ch == ltdArray[j])
			{
				ltdch = true;
				break;
			}
			if(j == ltdArray.length)
			{
				break;
			}

		}
		if(!ltdch)
		{
			break;
		}
	}
	return(ltdch);
}

//Check numeric number
function isNum(str)
{
	var ltdArray = new Array("1","2","3","4","5","6","7","8","9","0",".");
	var ch;
	for(var i=0; i<str.length; i++ )
	{
		var ltdch = false;
		ch = str.substring(i,i+1);
		for(var j in ltdArray)
		{
			if(ch == ltdArray[j])
			{
				ltdch = true;
				break;
			}
			if(j == ltdArray.length)
			{
				break;
			}

		}
		if(!ltdch)
		{
			break;
		}
	}
	return(ltdch);
}

//check blank value
function alltrim(str)
{
	var ch;
	var rstr;
	var i = 0;
	while(true)
	{
		ch = str.substring(i,i+1);
		if(ch != " ")
			break;
		i++;
	}
	str = str.substring(i,str.length);
	i = str.length;
	while(true)
	{
		ch = str.substring(i,i-1);
		if(ch != " ")
			break;
		i--;
	}
	str = str.substring(0,i);
	return(str);
}

//Check special charecter
function chkspech(str)
{
	var speArray = new Array("~","!","\\","\"","|");
	var ch;
	var isSpeCh = false;
	for(var i=0;i<str.length;i++)
	{
		ch = str.substring(i,i+1);
		for(var j in speArray)
		{
			if(ch == speArray[j])
			{
				isSpeCh = true;
				break;
			}
		}
		if(isSpeCh)
			break;
	}
	return(isSpeCh);
}

function chkspechplus(str)
{
	var speArray = new Array("~","!","\\","\"","|","\'","","`","'");
	var ch;
	var isSpeCh = false;
	for(var i=0;i<str.length;i++)
	{
		ch = str.substring(i,i+1);
		for(var j in speArray)
		{
			if(ch == speArray[j])
			{
				isSpeCh = true;
				break;
			}
		}
		if(isSpeCh)
			break;
	}
	return(isSpeCh);
}

//Check special charecter whitout exclamation mark
function chkspechwem(str)
{
	var speArray = new Array("~","\\","\"","|");
	var ch;
	var isSpeCh = false;
	for(var i=0;i<str.length;i++)
	{
		ch = str.substring(i,i+1);
		for(var j in speArray)
		{
			if(ch == speArray[j])
			{
				isSpeCh = true;
				break;
			}
		}
		if(isSpeCh)
			break;
	}
	return(isSpeCh);
}

//check digit and a to z charecter
function isAlphaNum(str)
{
	var speArray = new Array("~","`","!","@","#","$","%","^","&","*","(",")","+","=","[","{","]","}",":",";",",","<",">",".","/","?","|","\\","\"");
	var ch;
	var isSpeCh = false;
	for(var i=0;i<str.length;i++)
	{
		ch = str.substring(i,i+1);
		for(var j in speArray)
		{
			if(ch == speArray[j])
			{
				isSpeCh = true;
				break;
			}
		}
		if(isSpeCh)
			break;
	}
	return(!isSpeCh);
}

//check upload file size
function LimitAttach(file)
{
	extArray = new Array(".gif", ".jpg");
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	myExt = ext.substring(ext.length-4);
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == myExt) {
			return true;
		}
	}
	return false;
}

//Date checking
function checkdate1(jopDay,jopMonth,jopYear)
{
	var leapyear,year,month,day;
	for( var i=0;i<5;i++)
	{
		if(jopYear[i].selected)
		{
			year = jopYear[i].text;
			break;
		}
	}

	for( var i=0;i<31;i++)
	{
		if(jopDay[i].selected)
		{
			day = jopDay[i].text;
			break;
		}
	}

	for( var i=0;i<12;i++)
	{
		if(jopMonth[i].selected)
		{
			month = jopMonth[i].text;
			break;
		}
	}

	if(year%4 == 0)
	{
		leapyear = true;
	}

	if(!leapyear && month=="February" && day>28)
	{
		return(false);
	}

	if(leapyear && month=="February" && day>29)
	{
		return(false);
	}

	if(month=="April" || month =="June" || month=="September" || month=="November")
	{
		if( day > 30)
		{
			return(false);
		}
	}
	return(true);
}

function checkdate2(jopDay,jopMon)
{
	var dt = true;
	var day, month;

	for( var i=0;i<31;i++)
	{
		if(jopDay[i].selected)
		{
			day = jopDay[i].text;
			break;
		}
	}

	for( var i=0;i<12;i++)
	{
		if(jopMon[i].selected)
		{
			month = jopMon[i].text;
			break;
		}
	}

	if(month=="February" && day>29)
	{
		dt = false;
	}

	if(month=="April" || month =="June" || month=="September" || month=="November")
	{
		if( day > 30)
		{
			dt = false;
		}
	}
	return(dt);
}

//checking fax
function isFax(str)
{
	var ltdArray = new Array("1","2","3","4","5","6","7","8","9","0"," ","-","(",")");
	var ch;
	for(var i=0; i<str.length; i++ )
	{
		var ltdch = false;
		ch = str.substring(i,i+1);
		for(var j in ltdArray)
		{
			if(ch == ltdArray[j])
			{
				ltdch = true;
				break;
			}
			if(j == ltdArray.length)
			{
				break;
			}

		}
		if(!ltdch)
		{
			break;
		}
	}
	return(ltdch);
}

function comparedate(day1, month1, year1, day2, month2, year2)
{
	var fday,fmonth,fyear,tday,tmonth,tyear;
	for(var i=0;i<4;i++)
	{
		if(year1[i].selected)
		{
			fyear = year1[i].value;
		}
		if(year2[i].selected)
		{
			tyear = year2[i].value;
		}
	}
	for( var i=0;i<31;i++)
	{
		if(day1[i].selected)
		{
			fday = day1[i].value;
		}
		if(day2[i].selected)
		{
			tday = day2[i].value;
		}
	}
	for( var i=0;i<12;i++)
	{
		if(month1[i].selected)
		{
			fmonth = month1[i].text;
		}
		if(month2[i].selected)
		{
			tmonth = month2[i].text;
		}
	}

	var fdatestr = fmonth+ " " + fday +", " + fyear;
	var tdatestr = tmonth+ " " + tday +", " + tyear;
	var fmili = Date.parse(fdatestr);
	var tmili = Date.parse(tdatestr);
	if( fmili >  tmili )
	{
		return (false);
	}
	return(true);

}

function HOFeedback(){
	window.open('/hotelowner/emailfeedback.jsp?success=0&errormessage=&hotel=&emailto=&namefrom=&emailfrom=&subject=&message=&phone=','popup','toolbar=0, location=0, directories=0, status=0, width=540, height=385, screenX=10, screenY=10, menubar=0, scrollbars, resizable=0');
}
