/*****************************************************
 * Common Javascript functions
 *****************************************************/
function remName(a, b){
if(a.value==b){
a.value='';

}else if(a.value==''){
a.value=b;

}else{
a.value=a.value;

}
}
 
function chkName(a, b)
{
if(a.value=='')
{
a.value=b;
}

else
{
a.value=a.value;
}
}

function removeColor1()
{
   txtUserName = document.siteLogin.txtUserName.value   
 if(txtUserName != "" && txtUserName != "Username" &&  txtUserName !="Please enter valid username" && document.siteLogin.txtUserName.value!="You cannot have spaces in your username")
 {
	document.siteLogin.txtUserName.style.borderColor='#ffffff'; 
 }
}
function removeColor2()
{
   txtPassword = document.siteLogin.txtPassword.value  
 if(txtPassword != "" && txtPassword != "Password" &&  txtPassword !="Please Enter The password" && document.siteLogin.txtPassword.value!="You cannot have spaces in your password" )
 {
	document.siteLogin.txtPassword.style.borderColor='#ffffff'; 
 }
}
function removeColor3()
{
   securityCode = document.siteLogin.securityCode.value
 if(securityCode != "" && securityCode != "Enter Code Shown Below" &&  securityCode !="Please enter security code" && securityCode !="You cannot have spaces in security code")
 {
	document.siteLogin.securityCode.style.borderColor='#ffffff'; 
 }
}


function emptyvalue1()
{
 if(document.siteLogin.txtUserName.value=="Please enter valid username" || document.siteLogin.txtUserName.value=="Username" || document.siteLogin.txtUserName.value=="You cannot have spaces in your username") 
 { 
  //siteLogin.txtUserName.style.bordercolor='#CCCCCC';
  document.siteLogin.txtUserName.value="";
 }
}
 function emptyvalue2()
{
if(document.siteLogin.txtPassword.value=="Please Enter The password" || document.siteLogin.txtPassword.value=="Password" || document.siteLogin.txtPassword.value=="You cannot have spaces in your password")
 { 
  //siteLogin.txtPassword.style.bordercolor='#CCCCCC'; 
  document.siteLogin.txtPassword.value="";
 }
}
 function emptyvalue3()
{
 if(document.siteLogin.securityCode.value=="Please enter security code" || document.siteLogin.securityCode.value=="Enter Code Shown Below" || document.siteLogin.securityCode.value=="You cannot have spaces in security code") 
 {    
  //siteLogin.securityCode.style.bordercolor='#CCCCCC'; 
  document.siteLogin.securityCode.value="";
 }
}


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 = hrs + ":" + min + " " + apm + " " + monthname[month] + " " + day + ", " + year
 clock.innerHTML = monthname[month] + " " + day + ", " + year + " " + hrs + ":" + min + " " + apm
 //document.write(hrs + ":" + min + " " + apm + monthname[month] + " " + day + ", " + year )
}

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();
// 	window.location = 'http://www.electionmall.com/microsoft/';
//	 return true;
// }

 //var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
 //if (!(chkFilter.test(txtUserName))) {
	
 if (txtUserName == "" || txtUserName == "Username") 
 {  
  document.siteLogin.txtUserName.style.borderColor='#FF0000';
  document.siteLogin.txtUserName.value='Please enter valid username';   
  return false; 
 }
 if(txtUserName== "Please enter valid username")
 {
	 return false;
 }
 
 if (txtUserName.indexOf(' ') != -1) 
 { 
  document.siteLogin.txtUserName.style.borderColor='#FF0000';
  document.siteLogin.txtUserName.value='You cannot have spaces in your username';
  //document.siteLogin.txtUserName.focus();
  return false;
 } 

    var ctrl = document.getElementById("txtPassword"); 
  if(ctrl!= null ) 
 {
   if (txtPassword == "" || txtPassword == "Password" ) 
  {   
	  document.siteLogin.faketxtPassword.style.borderColor='#FF0000';	  
      document.siteLogin.faketxtPassword.value='Please Enter The password';     
      return false;  
   }
 }
 else
 {
	if (faketxtPassword == "" || faketxtPassword == "Password" ) 
  {  	  
	  document.siteLogin.faketxtPassword.style.borderColor='#FF0000'; 
      document.siteLogin.faketxtPassword.value='Please Enter The password';      
      return false;  
   } 
 }

 if(txtPassword== "Please Enter The password")
 {
	 return false;
 }
 
  if (txtPassword.indexOf(' ') != -1) 
 {
  document.siteLogin.txtPassword.style.borderColor='#FF0000';
  document.siteLogin.txtPassword.value='You cannot have spaces in your password';
  //document.siteLogin.txtPassword.focus();
  return false;
 }
 
 if (securityCode == "" || securityCode == "Enter Code Shown Below")
 {  
  document.siteLogin.securityCode.style.borderColor='#FF0000'; 
  document.siteLogin.securityCode.value='Please enter security code'; 
  return false;
 }
 
if(securityCode== "Please enter security code")
 {
	 return false;
 }
 if (securityCode.indexOf(' ') != -1) 
 {  
  document.siteLogin.securityCode.style.borderColor='#FF0000';
  document.siteLogin.securityCode.value='You cannot have spaces in security code';  
  return false;
 }
 //document.siteLogin.submit();
}

function goForgotPwd() {
 //wchSite = document.getElementById('loginType').value;
 //if (wchSite=='') {
 // alert("You have not selected any site.");
// } else {
 var strLInk
  //window.location = 'http://my.electionmall.com/forgotpassword.asp?src=' + wchSite;
  //window.location.replace("http://my.electionmall.com/forgotpassword.asp?src=" + wchSite);
  //document.getElementById('forLink').href='http://staging.electionmall.ws/MyElectionMall17.0/forgotpassword.asp?src=' + wchSite;
	strLInk='http://staging.electionmall.ws/MyElectionMall17.0/forgotpassword.asp?src=' ;
	GB_showCenter('', strLInk,440,500);
  
 //}
}

function goNewUser() {
 wchSite = document.getElementById('loginType').value;

 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;
   
  case 'tools':
   window.location = 'http://www.electionmall.com/campaign-cloud/online-campaign-website-management/';
   break; 

  default:
   //alert("You have not selected any site.");
   window.location = 'http://www.electionmall.com/microsoft/';
   //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];}}
}



function user_set_input_type(input,type)
 {
    try
    {
        var input2 = input.cloneNode(false);
        switch(type)
         {
           default:
             case 'text':
            {
                input2.type = 'text';
               break;
            }
            case 'password':
             {
                input2.type = 'password';
             }
       }
         input2.id = limput;
        input.parentNode.replaceChild(input2,input);
    }
    catch(e)
    {
        window.status = e.message;
    }
 }


function shoPwdText(){
	var svalue = document.getElementById('txtPassword').value;
	if( svalue == 'Password' ){
		document.getElementById('txtPassword').type = 'text';
		//user_set_input_type(document.getElementById('txtPassword'),'text');
	}
	
	
	
}
function hidePwdText(){
	
	document.getElementById('txtPassword').type = 'password';
	//user_set_input_type(document.getElementById('txtPassword'),'password');
		 
}

 function pwdFocus() {
            $('#faketxtPassword').hide();
            $('#txtPassword').show();
            $('#txtPassword').focus();
			$('#txtPassword').value='';
        }

 function pwdBlur() {
            if ($('#txtPassword').attr('value') == '') {
                $('#txtPassword').hide();
                $('#faketxtPassword').show();
            }
        }



