
// scrollTo function ---------  use: <a href='#the_div_name'>smooth scrolling</a>
jQuery(function($){
	$.localScroll.hash({
		target: 'body', 
		queue:true,
		duration:1000
	});

	$.localScroll({
		target: 'body', 
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
		},
		onAfter:function( anchor, settings ){
		}
	});
});
// end scrollTo



//
function resizeMainHeight() {// resize div '#main' height to fit the page
		$('#main').animate({
		height: ($(document).height() - $('#header').height())
		}, 1000);
}
	
	



$(document).ready( function() {
// animate content
	$('#maincontent').css('opacity','0');
	$('#maincontent').animate({ opacity:1.0 },1000);// fade in maincontent
	if($('#rightcontent').html()!='') {
		$('#rightcontent').hide();
		/*setTimeout("$('#rightcontent').slideToggle('slow')",500);*/
		$('#rightcontent').slideToggle('slow');// slidding rightcontent
	} else {
		$('#rightcontent').hide();
		$('#maincontent').css('border-color','transparent');
		$('#maincontent').animate({ width: 965 });// enlarge maincontent to fullsize
	}
//	
setTimeout("resizeMainHeight()",1000);
// click on div logo
$('#logo').click( function() {
	goHome('');
	});
$('#logo').mouseover(function () {
	$(this).css('cursor', 'pointer');
	$(this).attr('title', 'VIVA Home...');
});

// ------------------------ start pulldown mainmenu -----------------------
$(".topnav").dropDownPanels({
            speed: 100,
            resetTimer: 100
        });
//
});
// ------------------------ end on document .ready -----------------------






// loading data and open the wrapper between header and content
function slidingWrapper(datatarget) {
	if($('#slidingwrapper').is(':hidden')) {
	$('#slidingwrapper').load('http://'+window.location.hostname+'/'+datatarget,function() {$('#slidingwrapper').slideToggle('slow',function(){ resizeMainHeight() })});
	// fade out other containers
		$('#maincontent').animate({opacity:'0.2'});
		$('#rightcontent').animate({opacity:'0.2'});
	} else {
		$('#slidingwrapper').slideToggle('fast',function(){
			$('#slidingwrapper').load('http://'+window.location.hostname+'/'+datatarget,function() {$('#slidingwrapper').slideToggle('slow',function(){ resizeMainHeight() })})
			// fade out other containers
			$('#maincontent').animate({opacity:'0.2'});
			$('#rightcontent').animate({opacity:'0.2'});
			});
		}
	// check if succes story details is open and close it
	if($('div').hasClass('show_moreinfo')) {
		$('.show_moreinfo').remove();
	}
	// end check succes story details
	}
	
// closing the wrapper
function removeWrapper() {
	$('#slidingwrapper').slideToggle('slow',function(){ $('#slidingwrapper').html('') });
	// fade in the other containers
	$('#maincontent').animate({opacity:'1'});
	$('#rightcontent').animate({opacity:'1'});

	// check if succes story details is open and close it
	if($('div').hasClass('show_moreinfo')) {
		$('.show_moreinfo').remove();
	}
	// end check succes story details
	}






//show layer over map and load addresses from db list
function selectLocations(l_data) {
	if($('#addresses_list').is(':hidden')) {
	$('#blockleft').load(l_data,function(){ $('#addresses_list').slideToggle( 'slow' );$('#blockright').hide(); })
	} else {
		$('#blockleft').html('');
		$('#blockright').html('');
		$('#blockright').hide();
		$('#blockleft').load(l_data);
		//$('#blockright').append("<div id='cbutt' class='close_button'><a href='javascript:void(0)'></a></div>");
		}
	}


// check status of the div and open or close it 
function checkDivStatus(divTarget) {
	if($('#'+divTarget).is(':hidden')) {
		//$('#'+divTarget).animate({'opacity','1'});
		$('#'+divTarget).slideToggle('fast');
	} else {
		$('#'+divTarget).slideToggle('fast');
		setTimeout("$('#"+divTarget+"').slideToggle('slow')",500);
		//$('#'+divTarget).animate({'opacity','0'},function(){$('#'+divTarget).animate({'opacity','1'});});
		}
	}
	

// check status of the div and fade in and out ----------------------  used mostly for the map locations details
function divFadeinandout(divTarget) {
	if($('#'+divTarget).is(':hidden')) {
		$('#'+divTarget).css('display','block');
		$('#'+divTarget).css('opacity','0.0');
		$('#'+divTarget).animate({opacity:0.9});
	} else {
		$('#'+divTarget).animate({opacity:0},function(){
			$('#'+divTarget).animate({
				opacity:0.9
				});
			});
		}
	// resize block left
	$('#blockleft').animate({
		height: $('#'+divTarget).height() - 10
		});
	//
	$('#locationsmap').animate({
		height: $('#'+divTarget).height() + 140
		});
	}




// div popup for succes story more content
function showStory(divOpener) {
	var divOpener;
	$('.show_moreinfo').remove();
	if($('div').hasClass('show_moreinfo') == false) {
	var divOpener_pos = $('#s_story_'+divOpener).offset();// get pos of the opener div
	$('body').append("<div class='show_moreinfo' style='top:"+ Math.round(divOpener_pos.top) +"px;left:"+ Math.round(divOpener_pos.left) +"px;' onclick='$(this).remove();'><img src='http://'+window.location.hostname+'/images/loading.gif' style='margin:-10px 0 0 -10px;'></div>");
	if($('div').hasClass('show_moreinfo')==true) {
		//$('.show_moreinfo').hide();
		$('.show_moreinfo').load('http://'+window.location.hostname+'/includes/success_details.php?successdetails='+divOpener, function(){$('.show_moreinfo').animate({opacity:'1.0'});});
		if(($('.show_moreinfo').offset().left > ($(document).width()/2)+50)&&($('.show_moreinfo').offset().left < ($(document).width()/2)+150)) {
			$('.show_moreinfo').animate({left:'-=160px'});
			} else if($('.show_moreinfo').offset().left > ($(document).width()/2)+150) {
			$('.show_moreinfo').animate({left:'-=320px'});
			}
			//alert($(document).width()/2+'\n'+$('.show_moreinfo').offset().left);
		}
	} else {
	$('.show_moreinfo').remove();
	}
}

/*
function getUserRegion() {
	if (navigator.geolocation) {
  	navigator.geolocation.getCurrentPosition(success, error);
	} else {
  	alert('Not Supported!');
	}
	}
*/





// remove border on links
function BlurLinks(){
	lnks = document.getElementsByTagName('a');
	for(i = 0; i<lnks.length; i++){
	lnks[i].onfocus = new Function("if(this.blur)this.blur()");
	}
}



// check if IE < 8
function checkIEversion() {
if (navigator.appName == 'Microsoft Internet Explorer') {
var navName = navigator.appName;
var brVer = navigator.userAgent;
var brNum;
function verNumIE() {
var brVerId = brVer.indexOf('MSIE');
brNum = brVer.substr(brVerId,8);
}
verNumIE();
if(brNum < "MSIE 8.0") {
document.getElementById('alertDiv').style.display = 'block';
document.getElementById('alertDiv').innerHTML = 'Browser version insecure - you should update to MSIE 8 or higher !';
}
}
}



// redirect to home page
function goHome(lang) {
location.href = './?lang='+lang;
}



// load data dyn into div
function loadData(lTarget,path2File) {
$('#'+lTarget).animate({ opacity: 0.5 });
$('#'+lTarget).html("loading...");
$('#'+lTarget).load(''+path2File, function() {
// on complete
$('#'+lTarget).animate({ opacity: 1.0 });
});
}



// open a popup
function popupDetails(targ,w,h) {
detailsW = window.open(""+targ, "popUp", "width="+w+",height="+h+",toolbar=no,scrollbars=yes,menubar=no,locationbar=no");
detailsW.focus();
}





// --------------------------------------------------------------------------form validation

// normal required fields validation
function validate_required(field) {
with (field)
  {
  if (value==null||value==""||value==" ")
    {
    return false;
    }
  else
    {
    return true;
    }
  }
// special action here...
}

// check if field is a number
function validate_numbers(field) {
with (field)
  {
  if (isNaN(value))
    {
    return false;
    }
  else
    {
    return true;
    }
  }
}

// email validation extra
function validate_email(field) {
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {return false;}
  else {return true;}
  }
}

// checkbox validation
function validate_checkbox(field) {
with (field)
  {
  if (checked!=true)
    {
    return false;
    }
  else
    {
    return true;
    }
  }
}

// radio buttons validation
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

// ----------------------------------------------------  start valide form elements "get member now"
function validate_form(thisform) {
//
sendok = false;
//
with (thisform) {
// -------------------

  if (validate_required(membername)==false) {
  		$('#membername').css('opacity','0');
  		$('#membername').animate({opacity:'1'}, function() {
  			$('#membername').focus();
  			});
  	return false;
  }
  
  if (validate_required(memberfirstname)==false) {
  		$('#memberfirstname').css('opacity','0');
  		$('#memberfirstname').animate({opacity:'1'}, function() {
  			$('#memberfirstname').focus();
  			});
  	return false;
  }

  
  if (validate_required(memberaddress)==false) {
  		$('#memberaddress').css('opacity','0');
  		$('#memberaddress').animate({opacity:'1'}, function() {
  			$('#memberaddress').focus();
  			});
  	return false;
  }
  
  
  if (validate_required(memberzip)==false) {
  		$('#memberzip').css('opacity','0');
  		$('#memberzip').animate({opacity:'1'}, function() {
  			$('#memberzip').focus();
  			});
  	return false;
  }
  
  if (validate_numbers(memberzip)==false) {
  		$('#memberzip').css('opacity','0');
  		$('#memberzip').animate({opacity:'1'}, function() {
  			$('#memberzip').focus();alert('0 - 9');
  			});
  	return false;
  }
  
  
  if (validate_required(membercity)==false) {
  		$('#membercity').css('opacity','0');
  		$('#membercity').animate({opacity:'1'}, function() {
  			$('#membercity').focus();
  			});
  	return false;
  }
  
  if (validate_required(memberphone)==false) {
  		$('#memberphone').css('opacity','0');
  		$('#memberphone').animate({opacity:'1'}, function() {
  			$('#memberphone').focus();
  			});
  	return false;
  }
  
  if (validate_numbers(memberphone)==false) {
  		$('#memberphone').css('opacity','0');
  		$('#memberphone').animate({opacity:'1'}, function() {
  			$('#memberphone').focus();alert('0 - 9');
  			});
  	return false;
  }

  
  if (validate_required(memberemail)==false) {
  		$('#memberemail').css('opacity','0');
  		$('#memberemail').animate({opacity:'1'}, function() {
  			$('#memberemail').focus();
  			});
  	return false;
  }
  
  if(memberemail.value!="") {
  if (validate_email(memberemail)==false) {
  		$('#memberemail').css('opacity','0');
  		$('#memberemail').animate({opacity:'1'}, function() {
  			$('#memberemail').focus();alert('Format: email@domain.com');
  			});
  	return false;
  }
}
  
 if (validate_required(memberstudio)==false) {
  		$('#memberstudio').css('opacity','0');
  		$('#memberstudio').animate({opacity:'1'}, function() {
  			$('#memberstudio').focus();
  			});
  	return false;
  } 

 
// -------------------
  }
  
sendok = true; //send ok, go on...

}
// ----------------------------------------------------  end member form validation






