/**
 *  Main Icewine javascript
 *
 */


//invoked on resize
var resizeHandler = function(){
	setWidth("bottom-image");
	setBottom();
}
window.onresize = resizeHandler;

//executes onLoad
function initPage(){
    setWidth("bottom-image");
    setBottom();
}


//sets the width of an div according to screeen width
function setWidth(elementId){
    var w = window.innerWidth;
    if(!w) w = document.documentElement.clientWidth;
    if(!w) w = document.body.clientWidth;
    document.getElementById(elementId).style.width = w;
}

//sets the positon of the footer and of the bottom image
function setBottom(){

    var newTop = getWindowHeight()-239; //adjusted for bottom-image
    if(newTop < 580 ) newTop = 580;     //top limit for bottom-image
	//if(newTop < 370 ) newTop = 370;     //top limit for bottom-image

    if(myTop) newTop = myTop;

	if(document.getElementById("col-left"))
	{
		newTop= document.getElementById("col-left").offsetHeight + 50;
	}
	if(document.getElementById("bottom-image"))
	{
		document.getElementById("bottom-image").style.top = newTop + "px";
    	document.getElementById("footer").style.top = newTop + 225 + "px"; //adjusted for footer
    }
}



//returns window height
function getWindowHeight(){
  	var h = window.innerHeight;
    if(!h) h = document.documentElement.clientHeight;
    if(!h) h = document.body.clientHeight;
		return h;
}

//swaps onmouseover, onmouse out the src of an image (adds or removes -over)
function swapImage(image){
  var url;
  url = image.src;
  //determine if url conains -over. string
  if(url.search(/-over\./) >= 0){//conains the string
    //remove -over from image src
    image.src = url.replace(/-over\./, ".");
  }
  else{ //does not conaint the string
    //add -over to image src
    var imageName = url.substring(0,url.lastIndexOf("."));
    var imageExtension = url.substr(url.lastIndexOf("."),4);
    var newImageName = imageName + "-over" + imageExtension;
    image.src = newImageName;
  }
}

//for opening a full screen popup window
//from: http://www.htmlcodetutorial.com/
//modifications by splash
function popup(mylink, windowname){

	var width = screen.availWidth;
	var height = screen.availHeight;

	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, ',width='+width+',height='+height+',type=fullWindow,fullscreen,scrollbars=no,toolbar=no,status=no,menubar=no,locationbar=no');
	if (typeof(mylink) != 'string') return false; //if called from browser and not flash return the false.
}



// for showing and hiding divs
var currentDiv = ''

function showHide(id){


			if (id == 'nil'){
				return false;
			}

			var defaultdiv = document.getElementById('default');
			defaultdiv.style.display = 'none';

			if(document.all && !document.getElementById) {
				x = document.all[id]
			}else{
				x = document.getElementById(id)
			}

			//show div
			if(currentDiv == '')
			{
				currentDiv = x;
			}
			else
			{
				//swap div
				currentDiv.style.display = 'none';
				currentDiv = x;
			}

			x.style.display = 'block';
		}
		
		
		
// click/clear - a form field
function clickclear(myField, defaultText) {
	if(defaultText==myField.value)
	{
		myField.value = "";
	}
}

function clickrecall(myField, defaultText) {
   var fieldval=myField.value;
	var len=fieldval.length;
	if(len==0)
	{
	myField.value = defaultText;
	}
}


function validate(thisform)
  {
	  
	  var email=document.getElementById("email").value;
	 	   
	  if(email=="" || email=="email address"){
		  alert("Please enter your email address.");
		  document.getElementById("email").focus();
		  return false;
		  
	  } else {		  
		  document.getElementById(thisform).submit();
		  return true;
	  } 
	  
  }






