//used to toggle the elements on the contact form
function show_hide_menu(the_select, the_element){
	theOptions = document.getElementById(the_select).getElementsByTagName('option');
	for (i=0;i<theOptions.length;i++) {
			document.getElementById(theOptions[i].value).style.display = 'none';
		}
	document.getElementById(the_element).style.display = 'block'	
}

function show_hide(the_element, type, direction){
	if(type == 'switch'){
		if (direction == 'on'){
			document.getElementById(the_element).style.display = 'block';
		}else{
			document.getElementById(the_element).style.display = 'none';
		}
	}else{
		if(document.getElementById(the_element).style.display == 'block'){
			document.getElementById(the_element).style.display = 'none';
		}else{
			document.getElementById(the_element).style.display = 'block';
		}
	}
}

// Log Pad Expandable Content
function show_hide(the_element, the_div, content_type){
	
	if(document.getElementById(the_element).style.display == 'block'){
		document.getElementById(the_div).getElementsByTagName('a')[1].innerHTML = 'View '+content_type;
		document.getElementById(the_element).style.display = 'none';
	}else{
		document.getElementById(the_div).getElementsByTagName('a')[1].innerHTML = 'Hide '+content_type;
		document.getElementById(the_element).style.display = 'block';
	}
}

//Pop Up Script

function OpenWindow(url, width) {
			if (width == null) {
				width = 540;
			} else {
				width = width + 20;
			}
			var newWin;
      newWin = window.open(url,"press","width=" + width + ",height=400,toolbar=0,status=0,scrollbars=1");
      newWin.focus();
		}

//Pop Up for Demo

function popUp(strURL,strHeight,strWidth,winName) {
	var strOptions="height="+strHeight+",width="+strWidth;
	window.open(strURL, winName, strOptions);
}

//Jump menu in Choose a Region
function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}






//    
function getElementId ( id )
         {

                 if ( document.getElementById && document.getElementById(id) )
                      return document.getElementById(id) ;

                 if ( document.all && document.all[id] )
                      return document.all[id] ;

                 if ( document.layers && document.layers[id] )
                      return document.layers[id] ;

                 return false ;

         }

         function addMoreAnswers()
         {

         var tableId = getElementId( 'tablePollAnswers' ) ;

         var numRows = tableId.getElementsByTagName('tr').length;

         newRow = numRows+1 ;

         if ( newRow > 20 )
         {

              alert( 'Sorry you can add max 20 answers.') ;

              return false ;

         }

              inputEl = document.createElement( 'input' ) ;

              inputEl.setAttribute( 'type', 'text' ) ;
              inputEl.setAttribute( 'name', 'pollAnswers[]' ) ;
              inputEl.setAttribute( 'id', 'pollAnswers' + newRow ) ;
              inputEl.setAttribute( 'value', '' ) ;
              inputEl.setAttribute( 'size', '50' ) ;
              inputEl.setAttribute( 'maxlength', '200' ) ;

              oRow = tableId.insertRow(-1) ;
              oTd = oRow.insertCell(-1) ;
              oTd.innerHTML = '<label for="pollAnswers' + newRow + '" title="Answer ' + newRow + '">' + newRow + ':</label>';
              oTd = oRow.insertCell(-1) ;
              oTd.appendChild(inputEl) ;

         }

         function checkPollQuestion()
         {

                  var inputField = document.forms['createPoll'].pollQuestion ;

                  if ( inputField.value == '' )
                  {

                       alert('Please write your question.') ;

                       inputField.style.border = '1px solid red' ;
                       inputField.style.background = '#FEB4B4' ;

                       inputField.focus() ;

                       return false;

                  }

                  var docAns = document.getElementsByName('pollAnswers[]');

                  var m = 0;

                  for ( var i = 0; i < docAns.length; i++)
                  {

                        if ( docAns[i].value )
                             m++;

                  }

                  if ( m < 2 )
                  {

                  alert('Please write atleast two answers.');

                  return false;

                  }

         }

         function checkPollConfig()
         {

                  var doc = document.forms['createPoll'] ;

                  if ( doc.configDescription.value == '' )
                  {

                       alert('Please write a description.');

                       doc.configDescription.style.border = '1px solid red';
                       doc.configDescription.style.background = '#FEB4B4';

                       doc.configDescription.focus();

                       return false;

                  }

         }

         function changeBox( id )
         {


                  if ( id == 'comboBox' )
                  {

                       showDiv( 'comboBox' ) ;
                       hideDiv( 'radioButton' ) ;
                       hideDiv( 'checkBoxes' ) ;

                  }else
                  if ( id == 'radioButton' )
                  {

                       hideDiv( 'comboBox' ) ;
                       showDiv( 'radioButton' ) ;
                       hideDiv( 'checkBoxes' ) ;

                  }else
                  if ( id == 'checkBoxes' )
                  {

                       hideDiv( 'comboBox' ) ;
                       hideDiv( 'radioButton' ) ;
                       showDiv( 'checkBoxes' ) ;

                  }

         }

         function showDiv( id )
         {

                  divId = getElementId(id) ;
                  divId.style.display = 'block' ;

         }

         function hideDiv( id )
         {

                  divId = getElementId(id) ;
                  divId.style.display = 'none' ;

         }

         function selectCheckBox( id )
         {

                  var trId = getElementId( 'tr_' + id ) ;

                  var inputId = getElementId( 'id_' + id ) ;

                  if ( inputId.checked ) trId.style.background = '#FFDCC1' ;
                  else
                       trId.style.background = '#FFFFFF' ;

         }

         function updateMyPoll()
         {

         var el = document.getElementsByName('questionId[]');

         var m = 0;

         for ( var i = 0; i < el.length; i++ )
         {

               if ( el[i].checked == false )
                    m++;

         }

         if ( el.length == m )
         {

              alert( 'Please select at least one field.' ) ;

              return false ;

         }else
         {
              var actionValue = getElementId( 'pollAction' ) ;

              if ( actionValue.value == 0 )
              {

                   alert( 'Please select action of the selected fields!' ) ;

                   actionValue.style.border = '1px solid red' ;
                   actionValue.style.background = '#FEB4B4' ;
                   actionValue.focus() ;

                   return false ;

              }
              else
                   return confirm( 'Are you sure you want to ' + actionValue.value + ' this polls?' ) ;

         }

         }

         function animVotes()
         {

                  var tableId = getElementId( 'resultsTableId' ) ;

                  var divId = tableId.getElementsByTagName( 'div' ) ;

                  for ( var i = 0; i < divId.length-1; i++ )
                  {

                        curId = divId[i].getAttribute( 'id' ) ;

                        getElementId(curId).style.display = '' ;

                        slideVotes( curId, 0, 0 ) ;

                  }

         }

         function slideVotes(pollId, currentPercent)
         {

         divIdWidth = pollId.split(':');

         currentPercent = currentPercent/1 + 1 ;

         var obj = getElementId( pollId ) ;

         obj.style.width = Math.max( '0', Math.round( currentPercent / 100*divIdWidth[1] ) ) + 'px' ;

         if ( currentPercent < 100 ) setTimeout( 'slideVotes("' + pollId + '","' + currentPercent + '")', '20') ;

         }

         function changePollColors(id, section, color)
         {

                  if ( color && id )
                  {

                  divId = getElementId(id);

                  if ( section == 'bg' )
                       divId.style.background = color;
                  else if ( section == 'border' )
                  {

                        divId.style.borderRight = '2px solid ' + color;
                        divId.style.borderBottom = '1px solid ' + color;

                  }
                  else
                       divId.style.color = color;

                  }

         }

         function changeCustomColors(value)
         {

                  if ( value )
                  {

                  var colorValue = value.split('#');

                  changePollColors('tempConfigPollColorTitle', 'bg', '#' + colorValue[1]);
                  changePollColors('tempConfigPollColorTitle', 'text', '#' + colorValue[2]);
                  changePollColors('tempConfigPollColorAnswers', 'bg', '#' + colorValue[3]);
                  changePollColors('tempConfigPollColorAnswers', 'text', '#' + colorValue[4]);
                  changePollColors('tempConfigPollColorButton', 'bg', '#' + colorValue[5]);
                  changePollColors('tempConfigResultsColorBar', 'bg', '#' + colorValue[6]);
                  changePollColors('tempConfigResultsColorBar', 'border', '#' + colorValue[7]);

                  }
                  else
                      showDiv( 'customColors' );

         }

         function checkContacts()
         {

                  var form = document.forms[0];

                  for ( var i = 0; i < form.length - 1; i++ )
                  {

                        if ( !form.elements[i].value )
                        {

                              alert('Please fill the field ' + form.elements[i].name);

                              actionValue = getElementId(form.elements[i].id);

                              actionValue.style.border = '1px solid red' ;
                              actionValue.style.background = '#FEB4B4' ;
                              actionValue.focus() ;

                              return false;

                        }

                  }

                  return true;

         }
