function pk_is_upper_case(value) {
	return (value && value==value.toUpperCase());
}

function pk_is_numeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
	  { 
	  Char = sText.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 IsNumber = false;
		 }
	  }
   return IsNumber;
   
}

function trim( word ) {
	return word.replace(/^\s*/, '').replace(/\s*$/, '');
}

function pk_trim( word ) {
	return word.replace(/^\s*/, '').replace(/\s*$/, '');
}

// http://www.codingforums.com/showthread.php?t=29410&highlight=form+dirty
function pk_form_is_modified(oForm)
{
	var el, opt, hasDefault, i = 0, j;
	while (el = oForm.elements[i++]) {
		
		switch (el.type) {
			case 'text' :
			case 'textarea' :
			//case 'hidden' : // no FF nao funciona com HIDDEN, qdo um hidden eh modificado via JS, nao eh detectado o default value
					if ( /*!/^\s*$/.test(el.value) &&*/ el.value != el.defaultValue) return true;
					// edu - comentei a expre reg acima, pois campo em branco nao estava acusando como "diferente"
					break;
			case 'checkbox' :
			case 'radio' :
					if (el.checked != el.defaultChecked) return true;
					break;
			case 'select-one' :
			case 'select-multiple' :
					j = 0, hasDefault = false;
					while (opt = el.options[j++])
							if (opt.defaultSelected) hasDefault = true;
					j = hasDefault ? 0 : 1;
					while (opt = el.options[j++]) 
							if (opt.selected != opt.defaultSelected) return true;
					break;
		}
	}
	return false;
}

function pk_any_checked(form, name) {
	var checked = false;

	for (var i=0; i<form.elements.length; i++) {
		var e = form.elements[i];
		if ((e.type=='checkbox') && (e.name==name))
			if (e.checked) {
				checked = true;
				break;
			}
	}

	return checked;
}

function pk_check_all(form, name, checked) {
	for (var i=0; i<form.elements.length; i++) {
		var e = form.elements[i];
		if ((e.type=='checkbox') && (e.name==name))
			e.checked = checked;
	}
}

function pk_hidden(id) {
	document.getElementById(id).style.display = 'none';
}

function pk_show(id) {
	document.getElementById(id).style.display = 'none';
}

function pk_is_email(email) {
  var email_re = /^[A-Za-z0-9_&+.-]+@([A-Za-z0-9_-]+\.)+[A-Za-z]{2,4}$/;
  return email_re.test(email);
}

function pk_extract_file_ext(data) {
	data = data.replace(/^\s|\s$/g, "");
	if (/\.\w+$/.test(data)) {
		var m = data.match(/([^\/\\]+)\.(\w+)$/);
		if (m) return m[2];
	}
	return;
}

function pk_file_ext_in(file_name, list) {
	//if (path && !path.match("(.*?)\.(jpg|jpeg|png|gif|bmp)$")) {
	if (!file_name) return false;	
	var ext = pk_extract_file_ext(file_name.toLowerCase());
	for (var i=0; i<list.length; ++i)
		if (ext==list[i]) return true;
	return false;
}

function pk_change_class(obj, cls) {
	obj.className = cls;
}

function pk_select_all(select) {
	for (var i=0; i<select.options.length; ++i) {
		select.options[i].selected = true;
    }
}

function pk_next_object(n) {
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}

function pk_previous_object(p) {
	do p = p.previousSibling;
	while (p && p.nodeType != 1);
	return p;
}

// rule_index => 1 = arquivo CSS / 2 = classes internas (depende da ordem que foi declarado no html)
function pk_change_css(rule_index, myclass,element,value) {
	var CSSRules
	if (document.all) {
		CSSRules = 'rules'
	}
	else if (document.getElementById) {
		CSSRules = 'cssRules'
	}
   
	for (var i = 0; i < document.styleSheets[rule_index][CSSRules].length; i++) {		
      if (document.styleSheets[rule_index][CSSRules][i].selectorText == myclass) {
			document.styleSheets[rule_index][CSSRules][i].style[element] = value
		}
	}	
}

function pk_array_index_of(obj, search) {
	for(var i=0; i<obj.length; i++){
		if(obj[i]==search) {
			return i;
		}
	}
	return -1;
}

function pk_get_elements_by_class( searchClass, domNode, tagName) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = " "+searchClass+" ";
  for(i=0,j=0; i<tags.length; i++) {
	 var test = " " + tags[i].className + " ";
	 if (test.indexOf(tcl) != -1)
		el[j++] = tags[i];
  }
  return el;
}

function pk_get_year(date) {
	year = date.getYear();
	if ((year>89) && (year<100))
		year+=1900;
	else
		year+=2000;
	return year;
}

function pk_is_valid_date(myDate) {

	var sep = "/";

	if (myDate.length == 8) {
		var day   = myDate.substring(0,2);
		var month = myDate.substring(3,5);
		var year  = myDate.substring(6,8);
		var new_date = new Date(year,parseInt(month, 10)-1,day);
		myDate = day + "/" + month + "/" + pk_get_year(new_date);
	}

	if (myDate.length == 10) {

		if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {

			var day   = parseInt(myDate.substring(0,2), 10);
			var month = parseInt(myDate.substring(3,5), 10);
			var year  = parseInt(myDate.substring(6,10), 10);

			var test = new Date(year,parseInt(month, 10)-1,day);

			if (year == test.getFullYear() && (month == test.getMonth() + 1) && (day == test.getDate())) {
				reason = '';
				return true;
			}
			else {
				reason = 'valid format but an invalid date';
				return false;
			}
		}
		else {
			reason = 'invalid spearators';
			return false;
		}
	}
	else {
		reason = 'invalid length';
		return;
	}
}

function pk_text_counter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		{field.value = field.value.substring(0, maxlimit);}
	else
		countfield.value = field.value.length;
}


//http://bytes.com/forum/thread145113.html
function pk_format_number(theNumber, with_decimal) {

	function isThousands(position) {
		if (Math.floor(position/3)*3==position) return true;
		return false;
	};

	var theCurrency = "";
	var theThousands = ".";
	var theDecimal = with_decimal && "," || false;

	var theDecimalDigits = Math.round((theNumber*100)-(Math.floor(theNumber)*100));
	theDecimalDigits= ""+ (theDecimalDigits + "0").substring(0,2);
	theNumber = ""+Math.floor(theNumber);
	var theOutput = theCurrency;
	for (x=0; x<theNumber.length; x++) {
		theOutput += theNumber.substring(x,x+1);
		if (isThousands(theNumber.length-x-1) && (theNumber.length-x-1!=0)) {
			theOutput += theThousands;
		};
	};
	
	if (theDecimal) {
		theOutput += theDecimal;	
		theOutput += theDecimalDigits;
	}
	
	return theOutput;
};

function show_fale_com_suporte() {
	window.open("fale_com_suporte.php", "fale_com_suporte", "scrollbars=no,width=450,height=250,top=100,left=100");
}

function pk_replace_all(str, de, para){
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}

function ajustar_caracteres_word(str) {
	str = pk_replace_all(str, '“', '"');
	str = pk_replace_all(str, '”', '"');	
	str = pk_replace_all(str, '–', '-');
	return str;
}