function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver >= 6.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  //alert( msg );
}


function play(){
	var coef = 1;

	// Coeficiente de ajuste para IE 7
	var ver = getInternetExplorerVersion();
	//alert('###ver:'+ver);
	if( ver >= 7.0 || -1 == ver) { // Se for o IE 7 ou maior exibe apenas 95% do espa?o dispon?vel, pq no IE7 o status bar e o url bar n?o da para remover
	    coef = 0.95;
	}
	

	//history.go(-1);
	var width = window.screen.width;
	var height = window.screen.height;
	//alert('i?m ' + width);
	//alert('i?m ' + height);
	
	if(coef == 1) {
		//alert('###executing on IE6 or older');
		if (width == 1280 && height == 800) { // monitor wide
			window.open('http://netcartas.com.br/game.jsp?auxWidth=1068&auxHeight=797','game','scrollbars=no,resizable=no, left=0,top=0,width=1068,height=797,status=no,location=no,toolbar=no');
		}else if (width > 1024) { // 1280 x 1024 ou monitores maiores -- Ok, tested
			window.open('http://netcartas.com.br/game.jsp?auxWidth=1152&auxHeight=865','game','scrollbars=no,resizable=no, left=0,top=0,width=1152,height=865,status=no,location=no,toolbar=no');
		}else if (width == 1024){ // Ok, tested
			window.open('http://netcartas.com.br/game.jsp?auxWidth=950&auxHeight=710','game','scrollbars=no,resizable=no, left=0,top=0,width=950,height=710,status=no,location=no,toolbar=no');
		}else if (width == 800){
			window.open('http://netcartas.com.br/game.jsp?auxWidth=720&auxHeight=540','game','scrollbars=no,resizable=no, left=1,top=1,width=720,height=540,status=no,location=no,toolbar=no');
		}else {
			alert('Este jogo funciona apenas em resolucao maior ou igual a 800 x 600');
		}
		
	}else{
		//alert('###executing on IE7,newer or another browser');
		if (width == 1280 && height == 800) { // monitor wide -- Ok IE 7
			window.open('http://netcartas.com.br/game.jsp?auxWidth=925&auxHeight=745','game','scrollbars=no,resizable=no,left=0,top=0,width=925,height=745,status=no,location=no,toolbar=no');
		}else if (width > 1024) { // 1280 x 1024 -- Mozilla Ok
			window.open('http://netcartas.com.br/game.jsp?auxWidth=1100&auxHeight=825','game','scrollbars=no,resizable=no,left=0,top=0,width=1100,height=825,status=no,location=no,toolbar=no');
		}else if (width == 1024){ // Mozzila Ok, IE Ok
			window.open('http://netcartas.com.br/game.jsp?auxWidth=880&auxHeight=680','game','scrollbars=no,resizable=no, left=0,top=0,width=880,height=680,status=no,location=no,toolbar=no');
		}else if (width == 800){ // Mozilla Ok
			//window.open('http://netcartas.com.br/game.jsp','game','scrollbars=no,resizable=no, left=1,top=1,width=649,height=513,status=no,location=no,toolbar=no');
			window.open('http://netcartas.com.br/game.jsp?auxWidth=720&auxHeight=540','game','scrollbars=no,resizable=no, left=1,top=1,width=720,height=540,status=no,location=no,toolbar=no');
		}else {
			alert('Este jogo funciona apenas em resolucao maior ou igual a 800 x 600');
		}
	
	}
}

function playTruco(){
	//880x660
	var coef = 1;

	// Coeficiente de ajuste para IE 7
	var ver = getInternetExplorerVersion();
	//alert('###ver:'+ver);
	if( ver >= 7.0 || -1 == ver) { // Se for o IE 7 ou maior exibe apenas 95% do espa?o dispon?vel, pq no IE7 o status bar e o url bar n?o da para remover
	    coef = 0.95;
	}
	

	//history.go(-1);
	var width = window.screen.width;
	var height = window.screen.height;
	//alert('i?m ' + width);
	//alert('i?m ' + height);

	if(coef == 1) {
		//alert('###executing on IE6 or older');
		if (width == 1280 && height == 800) { // monitor wide
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=880&auxHeight=660','game','scrollbars=no,resizable=no, left=0,top=0,width=880,height=660,status=no,location=no,toolbar=no');
		}else if (width > 1024) { // 1280 x 1024 ou monitores maiores -- Ok, tested
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=1067&auxHeight=800','game','scrollbars=no,resizable=no, left=0,top=0,width=1067,height=800,status=no,location=no,toolbar=no');
		}else if (width == 1024){ // Ok, tested
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=880&auxHeight=660','game','scrollbars=no,resizable=no, left=0,top=0,width=880,height=660,status=no,location=no,toolbar=no');
		}else if (width == 800){
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=720&auxHeight=540','game','scrollbars=no,resizable=no, left=1,top=1,width=720,height=540,status=no,location=no,toolbar=no');
		}else {
			alert('Este jogo funciona apenas em resolucao maior ou igual a 800 x 600');
		}
		
	}else{
		//alert('###executing on IE7,newer or another browser');
		if (width == 1280 && height == 800) { // monitor wide -- Ok IE 7
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=925&auxHeight=745','game','scrollbars=no,resizable=no,left=0,top=0,width=925,height=745,status=no,location=no,toolbar=no');
		}else if (width > 1024) { // 1280 x 1024 -- Mozilla Ok
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=1100&auxHeight=825','game','scrollbars=no,resizable=no,left=0,top=0,width=1100,height=825,status=no,location=no,toolbar=no');
		}else if (width == 1024){ // Mozzila Ok, IE Ok
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=880&auxHeight=660','game','scrollbars=no,resizable=no, left=0,top=0,width=880,height=680,status=no,location=no,toolbar=no');
		}else if (width == 800){ // Mozilla Ok
			//window.open('http://netcartas.com.br/game.jsp','game','scrollbars=no,resizable=no, left=1,top=1,width=649,height=513,status=no,location=no,toolbar=no');
			window.open('http://netcartas.com.br/truco/gameTruco.jsp?auxWidth=720&auxHeight=540','game','scrollbars=no,resizable=no, left=1,top=1,width=720,height=540,status=no,location=no,toolbar=no');
		}else {
			alert('Este jogo funciona apenas em resolucao maior ou igual a 800 x 600');
		}
	
	}
}






/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("A data deve estar no formato : dd/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Digite um m?s v?lido")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Digite um dia v?lido")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("O ano deve estar entre "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Digite uma data v?lida")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

var lastComboActivateElement = null;

function divComboOpen(id, close, element) {
	var divCombo = document.getElementById(id);
	var isOpened = (divCombo.style.display.toLowerCase().indexOf("block") > -1);
	if (divCombo) {
		if ((isOpened || (isOpened && (close))) && ((isOpened && (!close) && (element != lastComboActivateElement) ) || (element == lastComboActivateElement)))  {
			divCombo.style.display = "none"
		} else if (!close) {
			divCombo.style.display = "block";
		}
	}
	lastComboActivateElement = element;
}
