// JavaScript Document


function show_sub(multi,pid)
{
		// Show
		addtopPX = 22;
		increasetopPX = addtopPX * multi;

		menu_content = $('#menu_sons_'+pid).html();
		
		// apply
		if (menu_content != '' && menu_content && ' ' && menu_content.length > 2)
		{
			$('.sub_menu').html(menu_content);
			$('.sub_menu').css({'top' : increasetopPX});
			$('.sub_menu').fadeIn("medium");
		}
		else
		{
			$('.sub_menu').css({'display' : 'none'});
		}

}

function keep_sub()
{
	$('.sub_menu').css({'display' : 'block'});
}

function hide_sub()
{
	$('.sub_menu').css({'display' : 'none'});
	//$('.sub_menu').fadeOut("fast");
}



// FAQ
function show_answer(id)
{
	//alert('show only->' + id);
	$('.faq_answer').each(function(i) {
		var currentId = $(this).attr('id'); 
		if (currentId == id)
		{
			//$(this).css({'display' : 'block'});
			$(this).toggle();
		}
		else
		{
			$(this).css({'display' : 'none'});
		}
	});
		
}
	
	
	
function isValidEmail(strEmail) 
	{
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (strEmail.search(validRegExp) == -1) {return false;} 
	return true;
}	
	

function formCheck(formobj)
{

	// Enter name of mandatory fields
	var fieldRequired = Array("club_first_name", "club_last_name", "club_email", "club_address");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("שם פרטי", "שם משפחה", "מייל", "כתובת מלאה");
	
	// dialog message
	var alertMsg = "עלייך למלא את הפרטים הבאים:\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function formCheck_contact(formobj){
	//alert('check');
    //return false;
	// Enter name of mandatory fields
	var fieldRequired = Array("txt_firstname", "txt_lastname","txt_phone");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("שם פרטי", "שם משפחה","טלפון");
	
	// dialog message
	var alertMsg = "עלייך למלא את הפרטים הבאים:\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}



function show_refer2(selected_value) {
//	alert(selected_value);
	if (selected_value == 'אחר')
	{
		$('#div_refer2').css({'display' : 'block'});
	}
		
	else
	{
		$('#div_refer2').css({'display' : 'none'});
	}
}


function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}


function gallery_showimage(filename,desc,show_desc)
{
	var src = './uploads/'+filename;
   
	$("#BigImage_div").fadeOut("slow");
	$("#BigImage_div").fadeIn("slow");
	
	t=setTimeout("gallery_swapimage('"+src+"')",500);
    
	// desc
	if (desc == '')
	{
		desc = '&nbsp;';	
	}
	
	$("#image_remark").html(desc);
    
    // Hide Big Image Desc
    if (show_desc == 1)
    {
        // Show Desc
        setTimeout("$('.BigImage_desc').css('display','block')",500);
    }
    else
    {
        // Hide Desc
        $('.BigImage_desc').css('display','none');
    }
    
    
    
}

function gallery_swapimage(src)
{
	$('#BigImage_div').css('background-image','url('+src+')');
}


// Clock
function updateClock() 
{

	var clientTime = new Date();
	var currentTime = new Date();
	var timeOffset = 8 * 60 * 60 * 1000;
	currentTime.setTime(clientTime.getTime() + timeOffset);

	//var currentHours = currentTime.getUTCHours();
	//var currentMinutes = currentTime.getUTCMinutes();
	//var currentSeconds = currentTime.getUTCSeconds();
	var currentMonth = currentTime.getUTCMonth();
	var currentDate = currentTime.getUTCDate();
	var currentDay = currentTime.getUTCDay();

	switch(currentMonth) {
		case 0:currentMonth = 'ינואר';break;
		case 1:currentMonth = 'פברואר';break;
		case 2:currentMonth = 'מרץ';break;
		case 3:currentMonth = 'אפריל';break;
		case 4:currentMonth = 'מאי';break;
		case 5:currentMonth = 'יוני';break;
		case 6:currentMonth = 'יולי';break;
		case 7:currentMonth = 'אוגוסט';break;
		case 8:currentMonth = 'ספטמבר';break;
		case 9:currentMonth = 'אוקטובר';break;
		case 10:currentMonth = 'נובמבר';break;
		case 11:currentMonth = 'דצמבר';break;
	}

	switch(currentDay) {
		case 0:currentDay = 'ראשון';break;
		case 1:currentDay = 'שני';break;
		case 2:currentDay = 'שלישי';break;
		case 3:currentDay = 'רביעי';break;
		case 4:currentDay = 'חמישי';break;
		case 5:currentDay = 'שישי';break;
		case 6:currentDay = 'שבת';break;
	}

	//currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
	//currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

		// Lior Edit
		   var d = new Date();
		   var c_hour = d.getHours();
		   var c_min = d.getMinutes();
		   var c_sec = d.getSeconds();
			
			// add 0 - minutes
			if (c_min < 10)
				c_min = '0' + c_min;

			// add 0 - seconds
			if (c_sec < 10)
				c_sec = '0' + c_sec;

		   var t = c_hour + ":" + c_min + ":" + c_sec;



	//document.getElementById("clock").innerHTML = t;
	//document.getElementById("date").setAttribute('class', currentMonth);
	//document.getElementById("date").innerHTML =  currentDate + ' ב' + currentMonth;
//	document.getElementById("day").innerHTML = 'יום '+ currentDay;
}



window.onload = function() {
//	updateClock();
//	setTimeout(updateClock, 2000);
}













// Opacity
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	/* Lior Edit - Dont use this next line now...
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	*/
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}


function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function playsound(soundfile){
if (document.all && document.getElementById){
document.getElementById("soundeffect").src="" //reset first in case of problems
document.getElementById("soundeffect").src=soundfile
}
}

function bindsound(tag, soundfile, masterElement)
{
if (!window.event) return
var source=event.srcElement
while (source!=masterElement && source.tagName!="HTML"){
if (source.tagName==tag.toUpperCase()){
playsound(soundfile)
break
}
source=source.parentElement
}
}

