﻿// JScript File

var itemID = 0;

function getWSDL()
{
    //TODO: need to replace this with actual in production
    mainWebService.useService("http://localhost/ACPN/webservices/wsacpnmain.asmx?WSDL","NewsEmailService");
}

function getResult()
{
    var itemID = event.result.value;
    if (itemID > 0 && itemID != "undefined")
    {  
        returnValue.innerText = "Your submission was successful&#33; You are now signed up for our e-mail list.";
    }
    else
    {
        returnValue.innerText = "Sorry! Our system seems to be having problems. Please try again later."; 
    }    
}

function addNewsEmail()
{
    itemID = mainWebService.NewsEmailService.callService("addNewsEmail", txtNewsEmail.value);
}

var _num = "";
var _timer = null;

function addNewsEmailP() {
  var inputText = document.getElementById("txtNewsEmail").value;

  if ((inputText == null) || (inputText.length == 0) || (inputText == "0"))
    return; // need no service

  if (echeck(inputText) == false) 
    { 
        document.getElementById("returnValue").style.paddingBottom="27px";
        document.getElementById("returnValue").innerHTML = "Sign up for our email list and stay in the loop";
        return;
    } 

  if (proxies.IsActive()) {
    // try again later...
    // _timer = window.setTimeout(CalcPrimeFactors, 300, "javascript");
    return;
  } // if

  proxies.wsACPNMain.addNewsEmail.func = displayResult;  // hook up a method that gets the response
  proxies.wsACPNMain.addNewsEmail(inputText); // now call the server
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

// The return value is passed to this function as a parameter
function displayResult (retVal) {
    //alert("Your submission was successful&#33; You are now signed up for our e-mail list." + retVal);
   if (retVal > 0 && retVal != "undefined")
        {
            document.getElementById("returnValue").style.paddingBottom="14px";
            document.getElementById("returnValue").innerHTML = "<br>Your submission was successful&#33; You are now signed up for our e-mail list.";
        } 
   else 
        {
            document.getElementById("returnValue").style.paddingBottom="14px";
            document.getElementById("returnValue").innerHTML = "Sorry! Our system seems to be having problems. Please try again later.";
        } 
}

function sendFeedback()
{
  var tb = document.getElementById("feedback");
  var inputText = tb.value;

  if ((inputText == null) || (inputText.length == 0) || (inputText == "0"))
    return; // need no service

  if (proxies.IsActive()) {
    // try again later...
    // _timer = window.setTimeout(CalcPrimeFactors, 300, "javascript");
    return;
  } // if

  proxies.wsACPNMain.addFeedback.func = displayFeedbackResult;   // hook up a method that gets the response
  proxies.wsACPNMain.addFeedback(inputText);                            // now call the server
  tb.value = "";
}

function displayFeedbackResult (retVal) {
   if (retVal > 0 && retVal != "undefined")
        document.getElementById("returnFeedbackValue").innerHTML = "Thank you for taking the time to send your comments. Your feedback is invaluable to us in serving you better.";
   else 
        document.getElementById("returnFeedbackValue").innerHTML = "Sorry! Our system seems to be having problems. Please try again later.";
}

function handleKeyPress(e, btn)
{
   var butt = document.getElementById(btn);
   var key = e.keyCode || e.which;
   if (key == 13)
   {
        butt.click();
       return false;
   } 
}

function goSearch(searchTxtbox)
{
    var tb = document.getElementById(searchTxtbox);
    window.location = "pro_search.aspx?SearchTerm=" + tb.value;
   //window.location="pro_search.aspx?SearchTerm=" + searchValue.value 
}

function goPublicSearch(searchTxtbox)
{
    var tb = document.getElementById(searchTxtbox);
    window.location.href = "search.aspx?SearchTerm=" + tb.value;
   return false; 
}
