// JavaScript Document


// -------------- Shows the clicked row content of a list. Example : news list ---------------//

function List_Show_Hide( list_name, total_rows, current_id ) {
	
 var list_row;
	var i;
	
	for ( i = 1; i <= total_rows; i++ ) {		

		list_row = document.getElementById( list_name + "_" + i );

  if ( i == current_id ) {
			if ( list_row.style.display == '' ){
		  list_row.style.display='none';
			} else {
		  list_row.style.display='';
			}
		} else { 
		 list_row.style.display='none';
		}
	}

}


// ------------------------- Opens a new window ----------------------------- //

function Open_Window( url, win_name, features ) {
  my_win = window.open( url, win_name, features);
		my_win.focus();
}



// ------------------------- Opens/Closes Site Map Sections  ----------------------------- //
function Site_Map_Section_Opener( id ) {
	
	var site_map_button = document.getElementById( "site_map_" + id + "_button" );
	var site_map_arrow = document.getElementById( "site_map_" + id + "_arrow" );
	var site_map_content = document.getElementById( "site_map_" + id + "_content" );
 
	var	img_path = site_map_button.src.substring( 0, site_map_button.src.lastIndexOf("/") + 1  );
	var img_src = site_map_button.src.substring( site_map_button.src.lastIndexOf("/") + 1, site_map_button.src.length );
  
		if ( site_map_content.style.display == '' ){
		 
		 site_map_content.style.display = 'none';
			
			switch ( img_src ) {
				case 'minus_root.gif':
				 site_map_button.src = img_path + 'plus_root.gif';
				break;
				case 'minus_L.gif':
				 site_map_button.src = img_path + 'plus_L.gif';
				break;
				case 'minus_T_cross.gif':
				 site_map_button.src = img_path + 'plus_T_cross.gif';
				break;
			}
			
			site_map_arrow.src = img_path + 'container_arrow_right.gif';
						
		} else { 
		
		 site_map_content.style.display = '';
			
			switch ( img_src ) {
				case 'plus_root.gif':
				 site_map_button.src = img_path + 'minus_root.gif';
				break;
				case 'plus_L.gif':
				 site_map_button.src = img_path + 'minus_L.gif';
				break;
				case 'plus_T_cross.gif':
				 site_map_button.src = img_path + 'minus_T_cross.gif';
				break;
			}
			
			site_map_arrow.src = img_path + 'container_arrow_down.gif';
			
		}
	
}




//  check email format
//  str : string (email) to check 
function isEmail( str ) 
{
// are regular expressions supported?
	var supported = 0;
	
	if ( window.RegExp ) 
	{
		var tempStr = "a";
		var tempReg = new RegExp( tempStr );
		if ( tempReg.test( tempStr ) ) 
		{
			supported = 1;
		}
	}
	
	if ( !supported ) 
	{
		return ( str.indexOf(".") > 2 ) && ( str.indexOf("@") > 0 );
	}
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	
	return ( !r1.test(str) && r2.test(str) );
}




function Get_Txt( textid ){
 
		var string = "";
		if ( aLang[textid] == null ){
				string = textid;
		} else{
				string = aLang[textid];
		}			
					
		return string;
		
}
			



// checks file extension type
function Check_Extensions_Filter( form, file, msg ) {
		allowSubmit = false;
		while (file.indexOf("\\") != -1){
			file = file.slice(file.indexOf("\\") + 1);
		}
		ext = file.slice(file.indexOf(".")).toLowerCase();
		for (var i = 0; i < extArray.length; i++) {
			if (extArray[i] == ext) { allowSubmit = true;}
		}
		if (allowSubmit){
			return true; 
		}
		else 
		{
			alert(msg);
			return false;
		}

}




// add a new participant
function new_participant () {

  var obj = document.getElementById( "participants" );
  var row = obj.insertRow( obj.rows.length );
						
		// bgcolor
		var bgcolor;
		if ( obj.rows.length % 2 == 0 ){
			 bgcolor = "#ffffff";
		} else {
			 bgcolor = "#f3f3f3";
		}
		
		var column;
		column = row.insertCell(0);
		column.width = '250';
		column.style.backgroundColor = bgcolor;
		column.innerHTML = '<input type="text" name="participant_name[]" value="" class="form-input" />';

		column = row.insertCell(1);
		column.width = '100';
		column.align = 'center';
		column.style.backgroundColor = bgcolor;
		column.innerHTML = '<input type="text" name="participant_age[]" value="" maxlength="2" class="form-input" style="width:20px;text-align:center" />';
	
		column = row.insertCell(2);
		column.width = '100';
		column.align = 'center';
		column.style.backgroundColor = bgcolor;
		column.innerHTML = '<input type="button" value=" - " style="width:25px;" onclick="remove_participant(this)" />';

}

// remove a participant
function remove_participant( r ) {
	
  var i = r.parentNode.parentNode.rowIndex;
  document.getElementById('participants').deleteRow(i);
		
}



function Remove_Row( id ) {
			var tbl = document.getElementById( id );
			var tr  = tbl;
			while ( tbl != document && tbl.nodeName != 'TABLE' ) {
					tbl = tbl.parentNode;
			}
			if ( tbl && tbl.nodeName == 'TABLE' && tr && tr.nodeName == 'TR' ) {
					while ( tr.hasChildNodes() ) {
							tr.removeChild( tr.lastChild );
					}
					tr.parentNode.removeChild( tr );
			}
	}



//------------------------------------ Confirm an action ( Example : logout? ) ------------------------------------//

function Confirm_Action( msg, url ) {
	if ( confirm( msg ) ) {
			window.location = url;
	} 
}

