// cookies

/*
function SetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
         ((expires) ? "; expires=" + expires.toGMTString() : "") +
         ((path) ? "; path=" + path : "") +
         ((domain) ? "; domain=" + domain : "") +
         ((secure) ? "; secure" : "");
}

function getCookieVal(offset) {
     var endstr = document.cookie.indexOf (";", offset);
     if (endstr == -1)
         endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
     var j = i + alen;
     if (document.cookie.substring(i, j) == arg)
       return getCookieVal (j);
     i = document.cookie.indexOf(" ", i) + 1;
     if (i == 0) break; 
   }
   return null;
}

function DeleteCookie(name,path,domain) {
   if (GetCookie(name)) {
     document.cookie = name + "=" +
       ((path) ? "; path=" + path : "") +
       ((domain) ? "; domain=" + domain : "") +
       "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}
*/

var ProjectName = readCookie("ProjectName")

function readCookie(name) {
	var namearg = name + "=";
	var nlen = namearg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + nlen;
		if (document.cookie.substring(i, j) == namearg) {
			var endpos = document.cookie.indexOf (";", j);
			if (endpos == -1) endpos = document.cookie.length;
			return unescape(document.cookie.substring(j, endpos));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function writeCookie(name, value, expiry) {
	var expdate = new Date();
	if(expiry) { //horas
		expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * expiry);
		document.cookie = name + "=" + escape(value) + "; expires=" + expdate.toGMTString();
	}
	else {
		document.cookie = name + "=" + escape(value);
	}
}

function deleteCookie(name) {
   if (readCookie(name)) {
     document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}

// divs and layers

function divShowHide(div)
{
	if (document.getElementById(div).style.display == 'none')	
		document.getElementById(div).style.display = ''
	else
		document.getElementById(div).style.display = 'none'
}

// windows, popus and dialogs

function openWindow(url, w, h, ws, dialog) {
	var windowStyle;
	var windowParent = {};
	if (w == null) w = 800;
	if (h == null) h = 600;
	
	if (url == '') return
		
	if (dialog == true) {
		windowStyle = 'dialogWidth:' + w + 'px;dialogHeight:' + h + 'px;help:no;status:yes;';
		if (ws) {windowStyle += ',' + ws}
		window.showModalDialog(url, windowParent, windowStyle);
		//"dialogWidth:200px;dialogHeight:200px;help:no;status:no;scroll:no;resizable:yes;"
	} else {
		windowStyle = 'width='+ w +',height='+ h +',screenX=50,left=50,screenY=50,top=50';
		if (ws) {windowStyle += ',' + ws}
		var newWin = window.open(url, "popup", windowStyle);
	}
}


function areYouSure() {return window.confirm('Tem a certeza?')}

// Url functions

function urlAddParam(url, param, value) {
	if (param != "" && value != "") {	
		if (url.substring(url.length - 1) != "?") {
			if (url.indexOf("?") > 0)
				url += "&"
			else	url += "?";
		}
		url += param + "=" + escape(value);
	}
	return url;
}

function popSetup() {
	var a
	for (var i = 0; (a = document.links[i]); i++) {
		if (a.target && a.target.indexOf("_pop") == 0) {
			a.onclick = popOpen
		}
	}
}

function popOpen() {
	var a = this.target.split(":")
	var sFeatures = a[1]
	
	if (this.href == '') return false
	
	window.open(this.href, a.length > 2 ? a[2] : String((new Date()).getTime()), sFeatures)
	return false
	alert("hi")
}


function btnFocus () {
	//alert(this.type)
	//var sClass = this.className + 'MO'; this.className = sClass
}
