// Shortcut to :document.getElementById
function gebi(objectName){
	return document.getElementById(objectName);
}

function nlChkBoxChg(obj){
	var toCheck="" ;

	if (obj.checked)
		toCheck = "true" ;
	else
		toCheck = "" ;
		
	for(var i = 0 ; i < obj.parentNode.parentNode.cells[1].getElementsByTagName("input").length; i++){
		obj.parentNode.parentNode.cells[1].getElementsByTagName("input")[i].checked = toCheck ; 
	}
	//for(var i = 0;; i++){
		//if (obj.parentNode.parentNode.cells[1].firstChild.rows[2] != null && obj.parentNode.parentNode.cells[1].firstChild.rows[2].cells[0].firstChild.rows[4] != null && obj.parentNode.parentNode.cells[1].firstChild.rows[2].cells[0].firstChild.rows[4].cells[0].firstChild.rows[0].cells[0].firstChild.rows[0].cells[i] != null && obj.parentNode.parentNode.cells[1].firstChild.rows[2].cells[0].firstChild.rows[4].cells[0].firstChild.rows[0].cells[0].firstChild.rows[0].cells[i].firstChild != null){ 
			//obj.parentNode.parentNode.cells[1].firstChild.rows[2].cells[0].firstChild.rows[4].cells[0].firstChild.rows[0].cells[0].firstChild.rows[0].cells[i].firstChild.firstChild.checked = toCheck;
	//	}
	//	else{
			//if (obj.parentNode.parentNode.cells[1].firstChild.rows[2].cells[0].firstChild.rows[1] == null || obj.parentNode.parentNode.cells[1].firstChild.rows[2].cells[0].firstChild.rows[1].cells[0].firstChild.rows[i] == null)
		//		break ;
		//}
	//} 
	
}

function sectionChkBoxChg(obj){
	if (obj.checked == true )
		obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.cells[0].firstChild.checked = true ;
	else {
		//var allUnChecked = 0 ;
		//for(var i = 0 ; i < obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("input").length; i++){
			//if (obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("input")[i].checked == true){
				//allUnChecked = 1 ;
				//break;
			//}
		//}
		//if (allUnChecked == 0)
			//obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.cells[0].firstChild.checked = false ;	
	}
	
}
function sectionChkBoxChgHaaretzCom(obj){
	var rootCb = null;
	var inputArr = document.getElementsByTagName("input");
	// returns the first input of type checkbox
	for (var i=0; i<inputArr.length; i++)
	{
		if(inputArr[i].type == 'checkbox')
		{
			rootCb = inputArr[i];
			break;
		}
	}		
	if (rootCb != null)
	{
		// if parent checkbox is not checked, check it
		if(!rootCb.checked) rootCb.checked = true;			
		var isEmpty = true;
		var sectionNodes = obj.parentNode.parentNode.parentNode.parentNode.childNodes;
		// if all sections are un-checked, uncheck the newsletter checkbox
		for(var i=0; i<sectionNodes.length; i++)
		{
			if(sectionNodes[i].childNodes[0].childNodes[0].childNodes[0].checked == true)
			{
				isEmpty = false;
				break;
			}
		}
		if(isEmpty == true) rootCb.checked = false;
	}
}

function personalSec(obj,openMsg,closeMsg){
	var tempObj = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rows[2].cells[0].firstChild ;
	
	if (tempObj.style.display == "none") {
		tempObj.style.display = "" ;
		obj.innerHTML = closeMsg ;
	}
	else {
		tempObj.style.display = "none" ;
		obj.innerHTML = openMsg ;
	}
}


function subSiteClick(t,site,openMsg,closeMsg){
	var tab = gebi(t.id + "Table") ;
	var gif = gebi(t.id + "ArrGif") ;
	var txt = gebi(t.id + "Txt") ;
	
	if (tab != null){ 
		if (tab.style.display == 'none'){
			tab.style.display = '' ;
			txt.innerHTML = closeMsg ;
			gif.src = 'images/' + site + '-b_c.gif' ;
		}
		else{
			tab.style.display = 'none' ;
			txt.innerHTML = openMsg ;
			gif.src = 'images/' + site + '-b_o.gif' ;
		}
	}
}
function toggleSendButton(){
	gebi("btnSubmit").disabled = !(gebi("marketingCheckbox").checked);	
	if (gebi("marketingCheckbox").checked){
		gebi("regConfirmText").className="regConfirmTextUnLocked";
	}else{
		gebi("regConfirmText").className="regConfirmTextLocked";
	}
}
function chkRegSend(){
	if (gebi("txtEmail") == null || gebi("txtEmail").value == null ||  gebi("txtEmail").value == ""){
		alert("אנא הכנס כתובת דואר אלקטרוני") ; 
		return false ;
	}

	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	
	if (!emailPattern.test(gebi("txtEmail").value)){
		alert("אנא הכנס כתובת דואר אלקטרוני תקינה") ;
		return false
	}
	
	if(isFormEmpty())
	{	
		alert("יש לבחור בניוזלטר המבוקש");
		return false; 
	}
	
	NUCONOMY.Logger.LogActivity(gebi("txtEmail").value, "", "",742 );

	return true ;
}

function chkRegSendEn(){
	if (! gebi("marketingCheckbox").checked){		 
		gebi("regConfirmText").className="regConfirmTextLocked";
		return false ;
	}
	if (gebi("txtEmail") == null || gebi("txtEmail").value == null ||  gebi("txtEmail").value == ""){
		alert("Please insert a valid email address.") ; 
		return false ;
	}

	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	
	if (!emailPattern.test(gebi("txtEmail").value)){
		alert("lease insert a valid email address.") ;
		return false
	}
	
	if(isFormEmpty())
	{	
		alert("יש לבחור בניוזלטר המבוקש");
		return false; 
	}
	
	NUCONOMY.Logger.LogActivity(gebi("txtEmail").value, "", "",742 );

	return true ;
}

function isFormEmpty(){
	var isEmpty = true;
	var inputArr = document.getElementsByTagName("input");
	var checkboxArray = new Array();
	// initialize the checkboxes array
	for(var i=0, j=0; inputArr != null && i<inputArr.length; i++)
	{
		if(inputArr[i].type == 'checkbox' && inputArr[i] != gebi("marketingCheckbox"))
		{			
			checkboxArray[j] = inputArr[i];
			if(checkboxArray[j].checked == true)
			{				
				isEmpty = false;
				break;
			}
			j++;
		}
	}
	return isEmpty;
}	
