/*****************************************************
 * 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 goToSection(url) {
 top.$("frmMainPanel").src = url;
 top.$("frmMainPanel").style.display = '';
}

function calcHeight(iframeId) {
 iframeHeight = $(iframeId).contentWindow.document.body.scrollHeight;
 if (iframeHeight < 450) {
  $(iframeId).height = 450;
 } else {
  $(iframeId).height = iframeHeight;
 }
}

function loginWindow(encVal) {
 openWin('login.site.asp?id=' + encVal,700,550)
}

function getContent(src) {
 new Ajax.Updater('loginContent', 'process/get.content.asp', {method: 'post', parameters: {src: src}});
}

function chkUser() {
 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test($F('txtUserName')))) {
  alert("Please enter valid username");
  $('txtUserName').focus();
  return false;
 }

 if ($F('txtPassword')== "") {
  alert("Please enter the password");
  $('txtPassword').focus();
  return false;
 }

 if ($F('txtPassword').indexOf(' ') != -1) {
  alert("You cannot have spaces in your password");
  $('txtPassword').focus();
  return false;
 }

 if ($F('securityCode') == "") {
  alert("Please enter security code");
  $('securityCode').focus();
  return false;
 }

 if ($F('securityCode').indexOf(' ') != -1) {
  alert("You cannot have spaces in security code");
  $('securityCode').focus();
  return false;
 }
 new Ajax.Updater('errorMessage', 'process/validate.user.asp', {method: 'post', evalScripts: true, parameters: {txtUserName: $F('txtUserName'), txtPassword: $F('txtPassword'), securityCode: $F('securityCode')}, onComplete:function() {if ($('errorMessage').innerHTML == '') document.location='menu.asp'}});
}

function showClock() {
 var dte = new Date();
 var hrs = dte.getHours();
 var min = dte.getMinutes();
 var day = dte.getDate();
 var month = dte.getMonth();
 var year = dte.getFullYear();
 var apm;
 var monthname = new Array("Jan","Feb","Mar","April","May","June","July","Aug","Sep","Oct","Nov","Dec");
 if (12 < hrs) {
  apm = "pm";
  hrs -= 12;
 } else {
  apm = "am";
 }
 if (hrs == 0) hrs = 12;
 if (min<=9) min = "0" + min;
 clock = document.getElementById("clockHeader");
 clock.innerHTML = monthname[month] + " " + day + ", " + year + " " + hrs + ":" + min + " " + apm;
}

function chkProfile() {
 if (($F("campaignName") == "")) {
  alert("Please enter your Campaign or Organization name");
  $("campaignName").focus();
  return false;
 }

 if ($F("officeTitleId") == "0") {
  alert("Please select your Office Title");
  $("officeTitleId").focus();
  return false;
 }

 if ($F("partyAffId") == "0") {
  alert("Please select your Party");
  $("partyAffId").focus();
  return false;
 }

 var chkFilter=/^[a-zA-Z]+$/;
 if ((!(chkFilter.test($F("firstName"))))) {
  alert("Please enter your first name.\nNo spaces or numerals are allowed.");
  $("firstName").focus();
  return false;
 }

 if ((!(chkFilter.test($F("lastName"))))) {
  alert("Please enter your last name.\nNo spaces or numerals are allowed.");
  $("lastName").focus();
  return false;
 }

 var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 if (!(chkFilter.test($F("email")))) {
  alert("Please enter a valid email address");
  $("email").focus();
  return false;
 }

 if (($F("address1") == "")) {
  alert("Please enter your Address Line 1");
  $("address1").focus();
  return false;
 }

 if (($F("city") == "")) {
  alert("Please enter City");
  $("city").focus();
  return false;
 }

 if ($F("state") == "0") {
  alert("Please select State");
  $("state").focus();
  return false;
 }

 var chkFilter=/(^\d{5}$)|(^\d{5}-\d{4}$)/;
 if (!(chkFilter.test($F("zip")))) {
  alert("Please enter valid Zip");
  $("zip").focus();
  return false;
 }

 var chkFilter=/^[\d]{3}-[\d]{3}-[\d]{4}$/;
 if (!(chkFilter.test($F("phone")))) {
  alert("Please enter phone number in xxx-xxx-xxxx format.");
  $("phone").focus();
  return false;
 }

 var chkFilter=/^[\d]{3}-[\d]{3}-[\d]{4}$/;
 if (($F("fax") != "") && (!(chkFilter.test($F("fax"))))) {
  alert("Please enter fax number in xxx-xxx-xxxx format.");
  $("fax").focus();
  return false;
 }

 if ($F("electionType") == 0) {
  alert("Please select Election Type");
  $("electionType").focus();
  return false;
 }

 var chkFilter=/^[\S]+$/
 if (($F("password").length < 5) || (!(chkFilter.test($F("password"))))) {
  alert("Please enter minimum 5 characters as your password");
  $("password").focus();
  return false;
 }

 if ($F("password") != $F("passwordConfirm")) {
  alert("Passwords do not match");
  $("passwordConfirm").focus();
  return false;
 }

 document.getInfo.submit();
}

function chkLogin() {
 txtUserName = document.siteLogin.txtUserName.value
 txtPassword = document.siteLogin.txtPassword.value
 securityCode = document.siteLogin.securityCode.value

 if (document.siteLogin.loginType.selectedIndex <= 0) {
  alert("Please select site to login");
  document.siteLogin.loginType.focus();
  return false;
 }

 //var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 //if (!(chkFilter.test(txtUserName))) {
 if (txtUserName == "") {
  alert("Please enter valid username");
  document.siteLogin.txtUserName.focus();
  return false;
 }

 if (txtPassword == "") {
  alert("Please enter the password");
  document.siteLogin.txtPassword.focus();
  return false;
 }

 if (txtUserName.indexOf(' ') != -1) {
  alert("You cannot have spaces in your username");
  document.siteLogin.txtUserName.focus();
  return false;
 }

 if (txtPassword.indexOf(' ') != -1) {
  alert("You cannot have spaces in your password");
  document.siteLogin.txtPassword.focus();
  return false;
 }

 if (document.siteLogin.securityCode.value == "") {
  alert("Please enter security code");
  document.siteLogin.securityCode.focus();
  return false;
 }

 if (securityCode.indexOf(' ') != -1) {
  alert("You cannot have spaces in security code");
  document.siteLogin.securityCode.focus();
  return false;
 }
 document.siteLogin.submit();
}

function goForgotPwd() {
 wchSite = $F('loginType');
 if (wchSite=='') {
  alert("You have not selected any site.");
 } else {
  window.location = 'http://my.electionmall.com/forgotpassword.asp?src=' + wchSite;
  // window.location.replace("http://my.electionmall.com/forgotpassword.asp?src=" + wchSite);
 }
}

function goNewUser() {
 wchSite = $F('loginType');
 switch (wchSite) {
  case 'tawp':
   window.location = 'http://www.voterspace.com/';
   break;

  case 'ocs':
   window.location = 'http://www.onlinecampaignstore.com/';
   break;

  case 'dp':
   window.location = 'http://www.fundraisingbynet.com/';
   break;

  case 'gotv':
   window.location = 'http://www.myegotv.com/';
   break;

  case 'pb':
   window.location = 'http://www.mypartybuilder.com/marketing/index.asp';
   break;

  case 'em':
   window.location = 'http://www.electionemail.com/';
   break;

  case 'el':
   window.location = 'http://www.myeleader.com/';
   break;

  case 'ea':
   window.location = 'http://www.myeadvocacy.com/login.asp';
   break;

  case 'eyp':
   window.location = 'http://staging.electionmall.ws/YellowPages/index.asp';
   break;

  case 'img':
   window.location = 'http://www.mycampaignimages.com/index.php?module=customer&pId=100&start=0';
   break;

  default:
   alert("You have not selected any site.");
   document.siteLogin.loginType.focus();
 }
}

function redirectUrlFooter(url) {
 if (url != 'Select Site') {
  siteUrl = 'http://' + url + '/'
  window.location.href = siteUrl;
 }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}