/*****************************************************
 * Common Javascript functions                       *
 *****************************************************/

function np() {
 return void(0)
}

function openWin(x,width,height) {
 window.open(x,null,"width="+width+",height="+height+",menubar=0,toolbar=0,resizable=0,scrollbars=1");
}

function $CF(el, radioGroup) {
 if($(el).type && $(el).type.toLowerCase() == 'checkbox') {
  var radioGroup = $(el).name;
  var el = $(el).form;
 } else if ($(el).tagName.toLowerCase() != 'form') {
   return false;
 }
 var checked = $(el).getInputs('checkbox', radioGroup).find(
  function(re) {return re.checked;}
 );
 return (checked) ? $F(checked) : null;
}

function expColPanel(panelName) {
 divName = 'panelBody' + panelName
 arrowName = 'imgArrow' + panelName
 Effect.toggle(divName,'slide', {duration: 0.5, afterFinish:
  function() {
   if (Prototype.Browser.IE) {
    if (panelName == 'Map') {
     $(divName).style.backgroundImage = 'url(../grfx/back.panel.map.gif)';
    } else {
     $(divName).style.backgroundImage = 'url(../grfx/back.panel.gif)';
    }
   }
  }
 });
 if ($(divName).style.display == 'none') {
  $(arrowName).src = 'grfx/arrow.minimise.gif'
  $(arrowName).alt = 'Click to minimise'
  $(arrowName).title = 'Click to minimise'
 } else {
  $(arrowName).src = 'grfx/arrow.maximise.gif'
  $(arrowName).alt = 'Click to maximise'
  $(arrowName).title = 'Click to maximise'
 }
}

function showSearchOption(optNum) {
 $('bodySearchOptions1').hide();
 $('bodySearchOptions2').hide();
 $('bodySearchOptions3').hide();
 $('bodySearchOptions' + optNum).show();
}

function changeStock(stockName,stockTicker) {
 $('stockChartName').innerHTML = 'Graph: ' + stockName
 $('stockChart').src = 'http://www.google.com/finance/chart?q=INDEX' + stockTicker;
}

function showLogout() {
 alert("You have logged out of your account")
}

function goHome() {
 $('panelResults').hide();
 $('panelResultsWait').hide();
 $('panelMain').show();
}

function glowOn(div) {
 div.style.backgroundImage = 'url(../grfx/back.result.platinum.on.jpg)';
}

function glowOff(div) {
 div.style.backgroundImage = 'url(../grfx/back.result.platinum.jpg)';
}

function chkSearch(pageNum) {
 if ($F('q') == '' && $CF('ito') == null && $CF('bpo') == null && $CF('ver') == null && $F('compCountryId') == '0' && $F('showPlatinum') == null) {
  alert("You have not selected any criteria to search");
  return false;
 }
 $('panelMain').hide();
 $('panelResults').hide();
 $('panelResultsWait').show();
 if (pageNum == null) pageNum = 1;
 new Ajax.Updater('panelResults', 'process/get.results.asp', {method: 'post', parameters: ($('formSearch').serialize() + '&pageNum=' + pageNum), evalScripts: true, onComplete:
  function() {
   $('panelResultsWait').hide();
   $('panelResults').show();
   Effect.Pulsate('panelResults', {pulses: 3});
  }
 });
 return false;
}

function chkAddEvent() {
 eventName = $('eventName')
 eventURL = $('eventURL')
 eventVenue = $('eventVenue')
 eventHost = $('eventHost')
 contactName = $('contactName')
 contactEmail = $('contactEmail')

 if (eventName.value == "") {
  alert("Please enter the Event Name");
  eventName.focus();
  return false;
 }

 if (eventURL.value == "") {
  alert("Please enter the Event URL");
  eventURL.focus();
  return false;
 }

 if (eventVenue.value == "") {
  alert("Please enter the Event Venue");
  eventVenue.focus();
  return false;
 }

 if (eventHost.value == "") {
  alert("Please enter the Event host");
  eventHost.focus();
  return false;
 }

 if (contactName.value == "") {
  alert("Please enter your Name");
  contactName.focus();
  return false;
 }

 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(contactEmail.value))) {
  alert("Please enter a valid Email");
  contactEmail.focus();
  return false;
 }
 $('formEvent').submit();
}

function chkSendPassword() {
 login = $('login')
 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(login.value))) {
  alert("Please enter a valid Email");
  login.focus();
  return false;
 }
 $('formPassword').submit();
}

function chkSendFeedback() {
 feedbackName = $('feedbackName')
 feedbackEmail = $('feedbackEmail')
 feedbackMsg = $('feedbackMsg')

 if (feedbackName.value == "") {
  alert("Please enter your Name");
  feedbackName.focus();
  return false;
 }

 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(feedbackEmail.value))) {
  alert("Please enter a valid Email");
  feedbackEmail.focus();
  return false;
 }

 if (feedbackMsg.value == "") {
  alert("Please enter your feedback");
  feedbackMsg.focus();
  return false;
 }
 $('formFeedback').submit();
}

function chkEmailProfile() {
 emailFrom = $('emailFrom')
 emailTo = $('emailTo')

 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(emailTo.value))) {
  alert("Please enter valid Email to send to");
  emailTo.focus();
  return false;
 }

 if (!(chkFilter.test(emailFrom.value))) {
  alert("Please enter a your valid Email");
  emailFrom.focus();
  return false;
 }
 $('profileForm').submit();
}

function chkUserActivate() {
 compName = $('compName')
 contactName = $('contactName')
 compCountryId = $('compCountryId')

 if (compName.value == "") {
  alert("Please enter your Company Name");
  compName.focus();
  return false;
 }

 if (compCountryId.value == "") {
  alert("Please select your country");
  compCountryId.focus();
  return false;
 }

 if (contactName.value == "") {
  alert("Please enter your Contact Name");
  contactName.focus();
  return false;
 }

 if ($('pwd') != null) {
  pwd = $('pwd')
  newPwd1 = $('newPwd1')
  newPwd2 = $('newPwd2')
  if (pwd.value != '' && (newPwd1.value == '' || newPwd1.value != newPwd2.value || newPwd1.value.length < 5)) {
   alert("You need to enter all the fields to change your password.\nMinimum password length is 5 characters.");
   return false;
  }
 }
}

function chkVendorRegister() {
 compName = $('compName')
 contactEmail = $('contactEmail')
 pwd = $('pwd')
 pwdRetype = $('pwdRetype')
 $('errMessage').innerHTML = ''

 if (compName.value == "") {
  alert("Please enter your Company Name");
  compName.focus();
  return false;
 }

 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(contactEmail.value))) {
  alert("Please enter a valid Email");
  contactEmail.focus();
  return false;
 }

 var chkFilter=/^[\S]+$/
 if ((pwd.value.length < 5) || (!(chkFilter.test(pwd.value)))) {
  alert("Please enter minimum 5 characters as your password");
  pwd.focus();
  return false;
 }

 if (pwd.value != pwdRetype.value) {
  alert("Passwords do not match");
  pwdRetype.focus();
  return false;
 }

 $('errMessage').innerHTML = '<img src="grfx/loader.gif" hspace="5">Please wait...';
 new Ajax.Updater('errMessage', 'process/chk.contact.email.asp', {method: 'post', parameters: {contactEmail: contactEmail.value}, onComplete:
  function() {
   if ($('errMessage').innerHTML == '') {
    new Ajax.Updater('bodyRegister', 'process/register.asp', {method: 'post', parameters: $('formVendorRegister').serialize()})
   }
  }
 })
 return false;
}

function chkLogin() {
 loginEmail = $('loginEmail')
 loginPwd = $('loginPwd')

 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(loginEmail.value))) {
  alert("Please enter a valid Email");
  loginEmail.focus();
  return false;
 }

 if (loginPwd.value == "") {
  alert("Please enter your password");
  loginPwd.focus();
  return false;
 }

 new Ajax.Updater('loginResponse', 'process/chk.login.asp', {method: 'post', evalScripts: true, parameters: $('formUserLogin').serialize()});
 return false;
}

function chkNLUnsubscibe() {
 email = $('email')
 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(email.value))) {
  alert("Please enter your valid Email to unsubscribe");
  email.focus();
  return false;
 }
}

var arrCompFieldNames = ["loginEmail","loginPwd"]
var arrCompFieldVals = ["Email address","Password"]

function emptyValue(fieldName) {
 for (var i = 0; i < arrCompFieldNames.length; i++) {
  if (fieldName.name == arrCompFieldNames[i]) {
   if (fieldName.value == arrCompFieldVals[i]) {
    fieldName.value = '';
    break;
   }
  }
 }
}

function fillValue(fieldName) {
 if (fieldName.value == '') {
  for (var i = 0; i < arrCompFieldNames.length; i++) {
   if (fieldName.name == arrCompFieldNames[i]) {
    fieldName.value = arrCompFieldVals[i];
    break;
   }
  }
 }
}

function openEvent(eventDate) {
 new Ajax.Updater(top.$('eventDetails'), '../process/get.date.events.asp', {method: 'post', parameters: {eventDate: eventDate}});
}

function switchTab(tab1,tab2) {
 $(tab1).hide()
 $(tab2).show()
}

function chkUpdates() {
 userEmail = $('userEmail')
 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test(userEmail.value))) {
  alert("Please enter a valid Email");
  userEmail.focus();
  return false;
 }
 new Ajax.Updater('bodyUpdates', 'process/get.updates.asp', {method: 'post', parameters: $('formUpdates').serialize()})
 return false;
}

function addSection(wchOne,cost) {
 if (wchOne.checked) {
  $('totalCostCustom').value = parseInt($F('totalCostCustom')) + cost;
 } else {
  $('totalCostCustom').value = parseInt($F('totalCostCustom')) - cost;
 }
 $('tt').innerHTML = $F('totalCostCustom');

 if ($F('totalCostCustom') == 0) {
  $('boxStep3').hide();
 } else {
  $('boxStep3').show();
 }
}

function selectFeatures(memberType) {
 $('boxStep2').show();
 if (memberType == 'c') {
  $('step2c').show();
  $('step2p').hide();
  if ($F('totalCostCustom') == 0) {
   $('boxStep3').hide();
  } else {
   $('boxStep3').show();
  }
 } else {
  $('step2p').show();
  $('step2c').hide();
  $('boxStep3').show();
 }
}
