// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitDoc(formName) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}
//onkeypress="return numbersonly(this, event)"
function numbersonly(myfield, e, dec){
  var key;
  var keychar;
  if (window.event)
   key = window.event.keyCode;
  else if (e)
   key = e.which;
  else
   return true;
  keychar = String.fromCharCode(key);
// control keys
  if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
    return true;
// numbers
  else if ((("0123456789+").indexOf(keychar) > -1))
    return true;
// decimal point jump
  else if (dec && (keychar == ".")) {
   myfield.form.elements[dec].focus();
   return false;
  }
 else
  return false;
}

////MAIN MENU FUNCTIONS - SWAP
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
MM_preloadImages('http://www.fortechocolates.com/images/ProductRolloutMenu_bg.jpg','http://www.fortechocolates.com/images/home-over.jpg','http://www.fortechocolates.com/images/ourphilosphy-over.jpg','http://www.fortechocolates.com/images/chocfacts-over.jpg','http://www.fortechocolates.com/images/productguide-over.jpg','http://www.fortechocolates.com/images/newsletter-over.jpg','http://www.fortechocolates.com/images/events-over.jpg','http://www.fortechocolates.com/images/contactus-over.jpg','http://www.fortechocolates.com/images/choclatefacts-over.jpg','http://www.fortechocolates.com/images/newslettersignup-over.jpg');


////////////opacity
function opacity(did, 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 + ",'" + did + "')",(timer * speed));
            timer++;
        }
				
    } else if(opacStart < opacEnd) {
        
				for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + did + "')",(timer * speed));
            timer++;
        }
				
    }
}
function changeOpac(opacity, did) {
    var object = document.getElementById(did).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

var ProdOverCount = 0;
function ProdMenuFadeIn(){
  var object_st = document.getElementById('ProductsRollOutMenuHolder').style;
	ProdOverCount = 0;
  //if(object_st.display == "none"){   
		opacity('ProductsRollOutMenuHolder', 0, 100, 1000);
	  object_st.display = "block";
	//}
}
function ProdMenuFadeOut(){
 var object_st = document.getElementById('ProductsRollOutMenuHolder').style;
 ProdOverCount++;
 if(ProdOverCount >= 1){
    changeOpac(0, 'ProductsRollOutMenuHolder')
    SetIDDisplayNone('ProductsRollOutMenuHolder')
  }
}//end function
function SetIDDisplayNone(did){
  var object_st = document.getElementById(did).style;
	object_st.display = "none"
}

function ProdMenuFadeOutInside(element, event, JavaScript_code) {
			var current_mouse_target = null;
			if( event.toElement ) {				
				current_mouse_target 			 = event.toElement;
			} else if( event.relatedTarget ) {				
				current_mouse_target 			 = event.relatedTarget;
			}
			if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
				eval(JavaScript_code);
			}
}
///////////////
function is_child_of(parent, child) {
			if( child != null ) {			
				while( child.parentNode ) {
					if( (child = child.parentNode) == parent ) {
						return true;
					}
				}
			}
			return false;
}
var ie4 = false; 
if(document.all) { 
	ie4 = true; 
}
function getObject(id) 
{ 
	if (ie4) { 
		return document.all[id]; 
	} else { 
		return document.getElementById(id); 
	} 
}

function BrowserDetection(){
  var browser=navigator.appName;
  return browser;
}
function ExpandContentLeftHeight(){
 //browser_type = BrowserDetection();
 cr = getObject('content_right');
 cl = getObject('content_left');
 ht = cr.offsetHeight;
 //alert(cr.offsetHeight);
 var defLeftHT = 570;
 if(ht < defLeftHT){
  	cl.style.height = defLeftHT+"px";
 }else{
   //if(browser_type == "Opera"){cl.style.height = (cr.pixelHeight)+"px";}
   cl.style.height = (cr.offsetHeight)+"px";
  
 }

}
////////////////

