//this file is updated at 29-09-09 for the acuanote point 345,349

setMenuHoverOn = function (elem) {
    if (elem == null) return;
	var sfEls = elem.getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}

}

sfHover = function() {
  setMenuHoverOn(document.getElementById("nav"));
  setMenuHoverOn(document.getElementById("nav-sub"));
}

var setGradient = (function(){
	 
	//private variables;
	var p_dCanvas = document.createElement('canvas');
	var p_useCanvas =  !!( typeof(p_dCanvas.getContext) == 'function');
	var p_dCtx = p_useCanvas?p_dCanvas.getContext('2d'):null;
	var p_isIE = /*@cc_on!@*/false;
	 
	
	 //test if toDataURL() is supported by Canvas since Safari may not support it
	
   try{   p_dCtx.canvas.toDataURL() }catch(err){
          p_useCanvas = false ;
   };
         
	if(p_useCanvas){
	   
	   return function (dEl , sColor1 , sColor2 , bRepeatY ){
			
			if(typeof(dEl) == 'string') dEl =  document.getElementById(dEl);
			if(!dEl) return false;
			var nW = dEl.offsetWidth;
			var nH = dEl.offsetHeight;
			p_dCanvas.width = nW;
			p_dCanvas.height = nH;
			
		
			var dGradient;
			var sRepeat;
			// Create gradients
			if(bRepeatY){
				dGradient = p_dCtx.createLinearGradient(0,0,nW,0);
				sRepeat = 'repeat-y';
			}else{
				dGradient = p_dCtx.createLinearGradient(0,0,0,nH);
				sRepeat = 'repeat-x';
			}		
			
			dGradient.addColorStop(0,sColor1);
			dGradient.addColorStop(1,sColor2);				
			
			p_dCtx.fillStyle = dGradient ; 
			p_dCtx.fillRect(0,0,nW,nH);
			var sDataUrl = p_dCtx.canvas.toDataURL('image/png');
			
			with(dEl.style){
				backgroundRepeat = sRepeat;
				backgroundImage = 'url(' + sDataUrl + ')';
				backgroundColor = sColor2;    
			};
	   }
	}else if(p_isIE){
		
		p_dCanvas = p_useCanvas = p_dCtx =  null;		
		return function (dEl , sColor1 , sColor2 , bRepeatY){
			if(typeof(dEl) == 'string') dEl =  document.getElementById(dEl);
			if(!dEl) return false;
			dEl.style.zoom = 1;
			var sF = dEl.currentStyle.filter;
			dEl.style.filter += ' ' + ['progid:DXImageTransform.Microsoft.gradient(	GradientType=',  +(!!bRepeatY ),',enabled=true,startColorstr=',sColor1,', endColorstr=',sColor2,')'].join('');
		    
		};
	
	}else{
		
		p_dCanvas = p_useCanvas = p_dCtx =  null;
		return function(dEl , sColor1 , sColor2  ){
			
			if(typeof(dEl) == 'string') dEl =  document.getElementById(dEl);
			if(!dEl) return false;
			with(dEl.style){
				 backgroundColor = sColor2; 
			};
			//alert('your browser does not support gradient effet');
		}
	}
})();


function whichElement(event){
  var element = event.target || event.srcElement;

  if(element){
    if(element.id != "search_results_div" && element.id != "big-search-field" && element.className != "a_school_result" ){        
        if(window.location.toString().match("/campaigns/new") != null){
            setTimeout(function(){school_results.hide()}, 250);
        }
    }
  }
}

  function center( element, limitX, limitY )
  {
   element = $(element);

   var elementDims = element.getDimensions();
   var viewPort = document.viewport.getDimensions();
   var offsets = document.viewport.getScrollOffsets();
   var centerX = viewPort.width / 2 + offsets.left - elementDims.width / 2;
   var centerY = viewPort.height / 2 + offsets.top - elementDims.height / 2;
   if ( limitX && centerX < limitX )
   {
    centerX = parseInt(limitX);
   }
   if ( limitY && centerY < limitY )
   {
    centerY = parseInt(limitY);
   }

   element.setStyle( { position: 'absolute', top: Math.floor(centerY) + 'px', left: Math.floor(centerX) + 'px' } );

   return element;
  }

    function close_flash_div(){
      elem = document.getElementById("flash_div");
      if(elem != null){
        document.getElementById("flash_div").style.display = 'none';
      }
    }

      function show_branded_logo(){

    $('pop_up_div').style.display = "block";

    $('background_transparent_div').style.display = "block";
    center($('pop_up_div'),100,100);
    $('pop_branded_logo_directs_to').value = $('organization_branded_logo_directs_to').value;

  }

 function hide_addresses(){
    $('background_transparent_div').style.display = "none";
    $('pop_up_div').style.display = "none";
  }

    function closeOnEnterButton(e){
    if (e.keyCode == 13) {
      close_branded_logo();
      return false;
    }
  }

  function close_branded_logo(){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test($('pop_branded_logo_directs_to').value)){
      $('pop_up_div').style.display = "none";
      $('background_transparent_div').style.display = "none";
      $('branded_logo_directs_to_hidden_field').value = $('organization_branded_logo_directs_to').value = $('pop_branded_logo_directs_to').value;
      document.org_for_brandedemail.submit();
    }else{
      alert("Please enter some valid URL");
      //return false;
    }
  }

  function show_ques(){

    if($('show_q').style.display == "none")
    {
      center($('show_q'),100,100);
      $('show_q').style.display = "block";
    }
    else
    {
      $('show_q').style.display = "none";
    }
  }
  
     

  
  function hideQues(){
    $('show_q').style.display = "none";
  }

  

  function check_url_available(){
    dd_elem = $('organization_addresses');
    txt_elem = $('organization_address_url_portion');

    var forreturn = true
    if($('isUrlExist').value == "true"  && dd_elem.options[dd_elem.selectedIndex].value == "(Old Springboard URLs)"){
      $('msg_div').style.color = "orange";
      forreturn =  false;
    }else if ($('isUrlExist').value == "" && dd_elem.options[dd_elem.selectedIndex].value != "(Old Springboard URLs)"){
      forreturn = true;
    }

    if( forreturn == true && dd_elem.options[dd_elem.selectedIndex].value != "(Old Springboard URLs)" ){
      txt_elem.value = dd_elem.options[dd_elem.selectedIndex].innerHTML;
      txt_elem.style.background = "#eeeeee";
      txt_elem.readOnly = true;
      forreturn =  true;
    }   
    return forreturn;
  }
  




