// Shared formatting functions
// By: Yanay Zohar



function activateDropMenu() {
    	
      
      if (document.all&&document.getElementById) {
                if(document.getElementById("nav")){
		//do nothing
		}else{
			return;
		}
    		navRoot = document.getElementById("nav");
    		for (i=0; i<navRoot.childNodes.length; i++) {
    		
    			node = navRoot.childNodes[i];
    			if (node.nodeName=="LI") {

            node.onmouseover=function() {
    					this.className+=" over";
    				}
    				node.onmouseout=function() {
    					this.className=this.className.replace(" over", "");
    				}
    			}
    		}
    	}
    }
    




var BehaveRules = {
		
    '#nav li' : function(element){
			element.onclick = function(){
				alert(this.innerHTML);
			}
		}
    
    /*
    ,
		'#someid u' : function(element){
			element.onmouseover = function(){
				this.innerHTML = "BLAH!";
			}
		}
		*/
		
	};
	
	//Behaviour.register(BehaveRules);



function date_today() {
//returns date format
    var X;
    with (new Date()) {
        X = String((getFullYear() * 100 + getMonth() + 1) * 100 + getDate());
    }
    return X;
}



function jungo_date(){

  var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  var final_date;
  
  with (new Date()) {
        
        day = getDate();
        if( day<10 ) day = '0' + day;
        
        month = months[ getMonth() ];
        
        final_date =  day + '-' + month + '-' + getFullYear();
         
    }

    return final_date;
  
}

function js_bypass(){
  // allows override with 'onclick's...
}




function get_base_path( baseType ){

  var base_path = "";
  
  if( baseType=='abs' )  // for ABSolute home page path:
  {
        if (location.href.match('yes3'))
        { base_path = "http://yes3.home.jungo.com/root/home/yanive/site/www/openrg/"; }
    if( !base_path )
        base_path = "http://www.jungo.com/openrg/";
  }
        
  else // for php/dynamic (default):  
  {
        if (location.href.match('yes3'))
        { base_path = "http://yes3.home.jungo.com/root/home/yanive/site/www/openrg/";  }
    
    if( !base_path )
        base_path = "http://www.jungo.com/openrg/";
  }
  
  return base_path;
  
  /*
  
  if( baseType=='abs' )  // for ABSolute home page path:
  {
    if (location.href.match('yes2'))
	var base_path = "http://yes2/root/home/yanay/site/www/";
    else if(location.href.match('assafi'))
	var base_path = "http://assafi/root/home/assafi/site/www/";
    else if(location.href.match('yanive-colinux'))
	var base_path = "http://yanive-colinux/root/home/assafi/site/www/";
    
    // TEMP testing new no //
    else if(location.href.match('ip112'))
    var base_path = "http://ip112/";
    
    else
	var base_path = "http://www.jungo.com/";
  }
    	
  else // for php/dynamic (default):  
  {
    if (location.href.match('yes2'))
	var base_path = "http://yes2/root/home/yanay/site/www/";
    else if(location.href.match('assafi'))
	var base_path = "http://assafi/root/home/assafi/site/www/";
    else if(location.href.match('yanive-colinux'))
	var base_path = "http://yanive-colinux/root/home/assafi/site/www/";
    
    // TEMP testing new no //
    else if(location.href.match('ip112'))
    var base_path = "http://ip112/php/";
    
    else
	var base_path = "http://www2.jungo.com/php/";
  }
  return base_path;
  */
}


function redirect_to_download( product_name, custom_tag ){
  
  var download_path =  get_base_path() + "scripts/download.php?product=" + product_name;
  
  if( custom_tag )  
    download_path += "&tag=" + custom_tag;
  else
    download_path += "&tag=" + location.pathname;  // default tag is referring page
  
  location.href = download_path;                               
                              

}




function redirect_to_contact( contact_subject, custom_tag ){

  var contact_path =  get_base_path() + "scripts/contact_form.php?subject=" + contact_subject;
  
  if( custom_tag )  
    contact_path += "&tag=" + custom_tag;
  else
    contact_path += "&tag=" + location.pathname;  // default tag is referring page 
    
  
  
  location.href = contact_path;                               
  

}


function redirect_to_st_store( product_id ){

  var store_path =  get_base_path() + "scripts/store/index.php";
  
  if( product_id ) store_path += "?pid=" + product_id; 
  
  location.href = store_path;
  
}



function usbtester_features( byFocus ){

  var txt;
  
  switch( byFocus ){
  
      case    'qa_engineer'     :   txt = "<li>Easily define custom testing scenarios"
                                          +"<li>Real-time USB device feedback"
                                          +"<li>Detailed logs to pinpoint errors"
                                          +"<li>Versatile: test both functionality &amp; validity";                                           
                                          
                                    break;
                                      
                                      
      case    'usb_developer'   :   txt = "<li>Easily verify your USB functionality" 
                                          +"<li>Integrates with USB bus analyzers"
                                          +"<li>Instant log reports. Get crucial feedback"
                                          +"<li>Intuitive: Minimal learning curve"
                                          +"<li>Documentation &amp; support at hand"
                                          +"<li>Frees you to focus on features rather than stability";
                                         
                                    break;
      
      
      case    'production'   :   txt = "<li>Dramatically reduce QA costs"
                                       +"<li>Get instant quality reports"
                                       +"<li>Generate detailed logs for engineers";
      
                                    break;
                                    
      
      case    'pm'   :   txt = "<li>Reduce QA delays on all production levels"
                               +"<li>Minimize QA costs" 
                               +"<li>Enjoy clear reports"
                               +"<li>Monitor detailed test logs"
                               +"<li>Shorten the project cycle time";

                                    break;
  
  }
  
  var features = "<ul class='ul-bullet1'>" + txt + "</ul>";
  
  $('features-focus').update( features );
  
  
  
  


}



function launch_wd_usb_demo(){

  var base_path = get_base_path('abs');
  
  window.open( base_path + 'st/images/viewlet/WinDriverUSB.swf','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=807,height=624,left=20,top=20'); 
  return false;
}

function launch_wd_pci_demo(){

  var base_path = get_base_path('abs');

  window.open( base_path + 'st/images/viewlet/WinDriverPCI.swf','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=807,height=624,left=20,top=20'); 
  return false;
}

function launch_usb_host_tester_demo(){

  var base_path = get_base_path('abs');
  
  window.open( base_path + 'st/images/viewlet/usb_tester_demo.swf','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=807,height=624,left=20,top=20'); 
  return false;
}

function flash() {
var f=document.getElementById("flashscript");
f.innerHTML="<object  style='display:block;position:relative;z-index:1' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='977' height='260' id='main_flash'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='movie' value='images/rg/main_flash.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#d4d4d4' />	<embed src='images/rg/main_flash.swf' quality='high' bgcolor='#d4d4d4' width='977' height='260' name='main_flash' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash'  pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}

var counter=0;
var Id='';
               function setmarq(){
  		    var base_path = get_base_path('php')+"scripts/resizeimg.php?src=";
		    var Images = new Array;
		    Images[0] = base_path + 'openrg/images/rg/logo/simens.gif&percent=0.5';
		    Images[1] = base_path + 'openrg/images/pirelli_logo.gif&percent=0.5';
		    Images[2] = base_path + 'openrg/images/audiocodes_logo.gif&percent=0.7';
		    Images[3] = base_path + 'openrg/images/rg/logo/verizon.gif&percent=0.6&t=10&b=10';
		    Images[4] = base_path + 'openrg/images/rg/logo/adept.gif&percent=0.4';
		    Images[5] = base_path + 'openrg/images/rg/logo/telecom_italy.gif&percent=0.7';
		    Images[6] = base_path + 'openrg/images/rg/logo/france_telecom.gif&percent=0.48&t=10&b=10';
		    Images[7] = base_path + 'openrg/images/rg/logo/zon.gif&percent=0.42';
		    Images[8] = base_path + 'openrg/images/rg/logo/orange.jpg&percent=0.27';
		    Images[9] = base_path + 'openrg/images/rg/logo/rcable.jpg&percent=0.12';

		    var countImg=5;
		      var V_count=counter*countImg;
		        var strImg = "";
			//Set the width of the image's cell
			//
			if ((Images.length-V_count)<countImg)
				var w = (Images.length-V_count)<countImg?100/(Images.length-V_count):100/countImg;

				for (var i=0 ; i<countImg  ;i++){
			       		if (Images.length<(i+V_count)){
					counter=0;
					Id = setTimeout(setmarq, 3000);
					return;
				        }
					else{
					        //if (Images[i+V_count]!=''||Images[i+V_count]!=null)
						if (typeof(Images[i+V_count])!='undefined')
						//alert(Images[i+V_count]);
				    		strImg += "<td align='center' width='"+w+"%' valign='middle' class='img-cell'><img src='"+Images[i+V_count]+"'></td>"; 
		                	}
			        }
                    Timer(strImg );
		}

		function Timer(strImg){
		                fadeOut("marq",100);
		                initImage();
		                document.getElementById("marq").innerHTML="<table cellpadding='0' border='0' width='877' height='50'><tr>"+strImg+"</tr></table>";
				counter++;                                
				Id = setTimeout(setmarq, 6000);
				return;

 		}
	
function initImage() {
  imageId = 'marq';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 200);
    }
  }
}
function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity >0) {
      setOpacity(obj, opacity);
      opacity -= 10;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 200);
    }
  }
}



