function checkUncheckAll(form_object,checkbox_name) {
	var checkboxes = form_object[checkbox_name];
	checkall = document.getElementById('checkall');
	for(i=0;i<checkboxes.length;i++) {
		if (checkall.checked == true) {
			checkboxes[i].checked = true;
			lightOn(checkboxes[i]);
		} else {
			checkboxes[i].checked = false;
			lightOn(checkboxes[i]);
		}
	}
}

function lightOn(object) {
	var tr = document.getElementById('id_'+object.value);
	if (object.checked == true) {
		tr.className = 'rowMark';
	} else {
		tr.className = '';
	}
	return true;
}

function checkChecked(form_object,checkbox_name) {
	var checkboxes = form_object[checkbox_name];
	for(i=0;i<checkboxes.length;i++) {
		if (checkboxes[i].checked == true) {
			if (confirm('Do you want to delete checked items?')) {
				document.actions.submit();
			}
			return;
		}
	}
	alert('Check items to delete');
}

function checkCheckbox(id) {
	var checkbox = document.getElementById('checkbox_id_'+id);
	if (checkbox.checked == true) {
		checkbox.checked = false;
		lightOn(checkbox);
	} else {
		checkbox.checked = true;
		lightOn(checkbox);
	}
}

function print_r(theObj){
	  if(theObj.constructor == Array ||
	     theObj.constructor == Object){
	    document.write("<ul>")
	    for(var p in theObj){
	      if(theObj[p].constructor == Array||
	         theObj[p].constructor == Object){
	document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
	        document.write("<ul>")
	        print_r(theObj[p]);
	        document.write("</ul>")
	      } else {
	document.write("<li>["+p+"] => "+theObj[p]+"</li>");
	      }
	    }
	    document.write("</ul>")
	  }
}

function onDocumentLoaded() {
	var delButton = document.getElementById('delButton');
	//delButton.disabled = true;
}

function redirect(url) {
	window.location.href = url;
}

function openWindow(url) {
	popup = window.open(url, 'location,width=700,height=800,top=0');
	popup.focus();
	return false;
}

function objectLightOn(object,color) {
	object.style.background = color;
}

function opencloseblock(id) {
	var object = document.getElementById(id);
	//alert(object.style.display);
	if (object.style.display == 'block') {
		object.style.display = 'none';
	} else if (object.style.display == 'none'){
		object.style.display = 'block';
	}
}

function checkPostCardForm(formNum, showMess) {
	var form = document.forms[formNum];
	var checked = false;
	for(i=0;i<form.pid.length;i++) {
		if (form.pid[i].checked == true) {
			checked = true;
		}
	}
	if (form.subject.value == '' ) {
		checked = false;
	}
	if (checked == false) {
		alert('Some fields must be have value,\r\nplease check form and try again.');
	} else {
		if (formNum == 0 && showMess == 'true') {
			if (showCreditsPrice('3')) {
				form.submit();
			}
		} else {
			form.submit();
		}
	}
}

function showCreditsPrice(creditsPrice) {
	return confirm("You need to spend "+creditsPrice+" credits for using this function.");
}

function showCreditsPriceSubmit(creditsPrice,formId, type, credits) {
	if (type == 'free') {
            if (credits == '0') {
                document.forms[formId].submit();
                return;
            }
		returned = confirm("You need to spend "+creditsPrice+" for using this function.");
		if (returned) {
			document.forms[formId].submit();
		}
	} else if (type == 'gold') {
		document.forms[formId].submit();
	}
}
