function CheckSelect(variable,msg)
{
  for (i=0; ;i++)
  {
    thisVar = variable + '_' + i;
    obj = document.getElementById(thisVar);
    if (obj)
    {
      if (obj.checked)
        return true;
    }
    else
      break;
  }
  window.alert(msg);
  return false;
}

function CheckSearch(formObj,msg)
{
 if (document.forms[formObj].elements['keywords'].value == '')
 {
   window.alert(msg);
   document.forms[formObj].elements['keywords'].focus();
   return false;
 }
 else
  return true;
}

function CheckAll(element)
{
  for(i=0;;i++)
  {
  	var thisObj = document.getElementById(element+i);
  	if (!thisObj)
  	  break;
  	thisObj.checked=true; 
  }
  return;
}

function UncheckAll(element)
{
  var allObj = document.getElementById('all_'+element);
  var allVal = true;	
  for (i=0;;i++)
  {
  	var thisObj = document.getElementById(element+i);
  	if (!thisObj)
  	  break; 
  	else if(!thisObj.checked)
  	{
  	  allVal = false;	
  	  break;	
  	}
  }
  allObj.checked = allVal;
}

//Telex Print

function printThis()
{
  document.styleSheets[0].disabled=true;	
  document.styleSheets[1].disabled=false;
  window.print();
  setTimeout('printDone()', 700);
}

function printDone()
{
  document.styleSheets[1].disabled=true;	
  document.styleSheets[0].disabled=false;
}

//End

//Form Validation

function eCheckEMail(sn){
    s= sn.value;
    if (s.indexOf("@") == -1) return false;
    if (s.indexOf(".") == -1) return false;
    at=false;
    dot=false;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1);
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                if (ch == "@"){
                  if (at) return false;
                  else at=true;
                }
                if ((ch==".") && at)
                   dot=true;
        }
        else return false;
    }
   return dot;
}

function CheckEMail(theForm,theEmailFields,theMsg){
   for(var i=0; i<theEmailFields.length; i++)
         if (!eCheckEMail(theForm.elements[theEmailFields[i]])){
            alert(theMsg);
            theForm.elements[theEmailFields[i]].focus();
            return false;
        }
   return true;
}


function CheckRequiredFields(theForm,theRequiredFields,theMsg)
{
   for(i=0; i<theRequiredFields.length; i++)
        if (theForm.elements[theRequiredFields[i]].type=="radio")
        {
          var radioName = theForm.elements[theRequiredFields[i]].name;	
          var radioLength = theForm.elements[radioName].length;	
          
          for (n=0; n<radioLength; n++)	
          {
          	if (theForm.elements[radioName][n].checked)
          	  return true;
          }
          alert(theMsg);
          theForm.elements[theRequiredFields[i]].focus();
          return false;
        }
        else if(theForm.elements[theRequiredFields[i]].value==""){
            alert(theMsg);
            theForm.elements[theRequiredFields[i]].focus();
            return false;
        }
   return true;
}

function CheckForm(theForm,theEmailFields,theRequiredFields,theEmailMsg,theGlobalMsg){
     if(CheckRequiredFields(theForm,theRequiredFields,theGlobalMsg))
     if(CheckEMail(theForm,theEmailFields,theEmailMsg))
          return true;
  return false;
}

//End

function changeLang()
{
  var obj = $('#chlang')[0];
  var selectedVal = obj.options[obj.selectedIndex].value;
  
  if (selectedVal == "")
    return;
  
  location.href = selectedVal;  
}


function CheckLogin(formObj,msg1,msg2,msg3)
{
  var usrVal = document.forms[formObj].elements['cuser'].value;
  var pasVal = document.forms[formObj].elements['cpass'].value;
  
  if (usrVal == "" && pasVal == "")
  {
    window.alert(msg1);	
    document.forms[formObj].elements['cuser'].focus();
  	return false;
  }
  else if (usrVal == "")
  {
  	window.alert(msg2);	
  	document.forms[formObj].elements['cuser'].focus();
  	return false;
  }
  else if (pasVal == "")
  {
  	window.alert(msg3);
  	document.forms[formObj].elements['cpass'].focus();	
  	return false;
  }
  else
    return true;
}

//Menu Functions

function menuOver(obj)
{
  obj.style.cssText = "color:#cd9e40;background:#e2dddb;cursor:pointer;";
}

function menuOut(obj)
{
  obj.style.cssText = "color:white;background:none;cursor:none;";
}

function menuClick(url)
{
  location.href = url;	
}

//End

//Doc switcher

var currentDoc = -1;
//var maxDoc = 3;
//var timerSpeed = 8000; //milsec
//var normalBG = '#eceff0';
//var selectedBG = '#d1d3d4';
  
function switchDoc(obj,val)
{
    for(i=0;i<maxDoc; i++)
    {
      if($('#first_doc_bg'+i)[0])
    	$('#first_doc_bg'+i)[0].className='first_doc_slides';
      
      $('#first_doc_sc'+i)[0].style.display='none';
    }
    //$('#first_doc_sc'+obj)[0].style.display=val;
    $('#first_doc_sc'+obj).fadeIn(300);
    
    if($('#first_doc_bg'+obj)[0])
      $('#first_doc_bg'+obj)[0].className='slides_selected';
}
  
function nextDoc()
{
    if (currentDoc < maxDoc-1)
      currentDoc++;    
    else
      currentDoc = 0;
      
    switchDoc(currentDoc,'block');
}
  
function preDoc()
{
    if (currentDoc == 0)
      currentDoc = maxDoc - 1;    
    else
      currentDoc--;
    
    switchDoc(currentDoc,'block');
}
  
function playDocs() {
    nextDoc();
    
    if (maxDoc > 1)	
      autoTimerID = window.setTimeout("playDocs()", timerSpeed);
}
  
function stopDocs() {
	
	if (maxDoc <= 1)
	  return;
	  
    clearTimeout(autoTimerID);
}

function resumeDocs() {
	
	if (maxDoc <= 1)
	  return;
	
    clearTimeout(autoTimerID);
    autoTimerID = window.setTimeout("playDocs()", timerSpeed);
}

function getMaxHeight() {
	
	if (maxDoc <= 1)
	  return;
	  
	var maxHeight=0;
    for(i=0;i<maxDoc; i++)
    {
      $('#first_doc_sc'+i)[0].style.display = "block";	
      if ($('#first_doc_sc'+i)[0].offsetHeight > maxHeight)
      	maxHeight = $('#first_doc_sc'+i)[0].offsetHeight;
      $('#first_doc_sc'+i)[0].style.display = "none";
    }
    
    for(i=0;i<maxDoc; i++)
      $('#first_doc_sc'+i)[0].style.height = maxHeight;
}

//End

//Tab Script

function SwitchDiv(CurrentSel,tabPrefix,tabAlign)
{	 
  var maxHeight=0;
  var tabCounter = eval(tabPrefix+'TabCounter');	
  var buttonContainerID = eval(tabPrefix+'BcontainerID');
  var selectedClass = eval(tabPrefix+'selectedClass');
  var unSelectedClass = eval(tabPrefix+'unSelectedClass');
  var tabPositioning = eval(tabPrefix+'Positioning');
  var addtopPos = eval(tabPrefix+'TopPos');
  var tabPadding = eval(tabPrefix+'TabPad');
  
  if (!tabPositioning)
  {
    for (i=0; i<tabCounter; i++)
    {
  	  var buttonHeight = $('#'+tabPrefix+'_tab_button'+i).height();
      if (buttonHeight > maxHeight)
      	maxHeight = buttonHeight;
    }
  
    $('#'+buttonContainerID).css("height",maxHeight); 
    
    if (tabPrefix == 'section')
      $('#main_div59').css("height",maxHeight);
	
    for (i=0; i<tabCounter; i++)
    {
      var thisbObj = $('#'+tabPrefix+'_tab_button'+i);	
      var thisPos = 0;
      for (n= ( (tabPrefix == 'section' && i > 3) ? 4 : 0 ) ; n<i; n++) {
         thisPos += $('#'+tabPrefix+'_tab_button'+n).width();
      }
      thisbObj.css(tabAlign,thisPos+( ( (i > 3) ? i-4 : i ) +( ( (i > 3) ? i-4 : i ) *tabPadding)));
      thisbObj.css("height",maxHeight);
    }
    
    var contentMaxHeight=0;
    for(i=0;i<tabCounter; i++)
    {
      var thisTabcontentOBJ = $('#'+tabPrefix+'_tab_content'+i+" table:only-child");
      var contentHeight = thisTabcontentOBJ.height();
      if (contentHeight > contentMaxHeight)
      	contentMaxHeight = contentHeight;
    }
    
    for(i=0;i<tabCounter; i++)	
      $('#'+tabPrefix+'_tab_content'+i+" table:only-child").height(contentMaxHeight);
      
    eval(tabPrefix+'Positioning=true;'+tabPrefix+'maxHeight='+maxHeight+';');  
  }
  
  var tabTopPos = eval(tabPrefix+'maxHeight');
  var selbtJQ = $('#'+tabPrefix+'_tab_button'+CurrentSel);
  
  if (tabPrefix == "section" && CurrentSel > 3)
  {
    selbtJQ.attr("class","tab_button1_sel_buttom");
    selbtJQ.css("top",selbtJQ.height() - tabTopPos - 1);
  }
  else
  {
  	selbtJQ.attr("class",selectedClass);
    selbtJQ.css("top",selbtJQ.height() - tabTopPos + addtopPos);
  }
  
  //$('#'+tabPrefix+'_tab_content'+CurrentSel).css("display","block");
  $('#'+tabPrefix+'_tab_content'+CurrentSel).fadeIn(300);
  
  for (i=0; i<tabCounter; i++)
  {
  	if (i == CurrentSel)
  	  continue;
  	var buttonJQ = $('#'+tabPrefix+'_tab_button'+i);	
    var ContentJQ = $('#'+tabPrefix+'_tab_content'+i);
    
    if (!buttonJQ || !ContentJQ)
      continue;
      
    if (tabPrefix == "section" && i > 3) {
      buttonJQ.attr("class","tab_button1_buttom");
      buttonJQ.css("top",8);
    }
    else {
      buttonJQ.attr("class",unSelectedClass);  
      buttonJQ.css("top",0);
    }
      
    ContentJQ.css("display","none");
  }
}


function getBoxMaxHeight(container,count,addHeight)
{
  var maxHeight=0;
  for(i=0;i<count; i++) {
    if ($('#'+container+i).height() > maxHeight)
      maxHeight = $('#'+container+i).height();
  }
  
  for(i=0;i<count; i++) {
    $('#'+container+i).height(maxHeight+addHeight);
  }
}
//End

//Attachments

function showAtch() {
  var dvObj = $("#attachments_div2");	
  if (dvObj.css("visibility") != "visible") {
    dvObj.css("visibility","visible");
    $("#attachments_div2 object").css("visibility","visible");
  }
}

function hideAtch() {
  var dvObj = $("#attachments_div2");	
  if (dvObj.css("visibility") != "hidden") {
    dvObj.css("visibility","hidden");
    $("#attachments_div2 object").css("visibility","hidden");
  }
}

//End

//Ticker

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
 
$(document).ready(function(){
   headline_count = $("div.headline").size();
   $("div.headline:eq("+current_headline+")").css('top','0px');
 
   headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
   $('#scrollup').hover(function() {
     clearInterval(headline_interval);
   }, function() {
     headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
     //headline_rotate();
   });
});
 
function headline_rotate() {
   current_headline = (old_headline + 1) % headline_count; 
   $("div.headline:eq(" + old_headline + ")").animate({top: -20},"slow", function() {
     $(this).css('top','20px');
   });
   $("div.headline:eq(" + current_headline + ")").show().animate({top: 0},"slow");  
   old_headline = current_headline;
}

//End
