﻿// JScript File
       
function GetNoReturn()
{
    PPS.PPSWebService.GetServerTime();
    //alert("This method does not return a value.");
}


function GetHints()
{
PPS.PPSWebService.GetHints("NIL", SucceededCallback);
}


function AddEmails(param)
{


// //alert(param);
    if(document.getElementById(param).value=="")
    {
       //alert('Please enter an email address');
  document.getElementById(param).focus();
       return false;
}
      
    if(isValidEmail(document.getElementById(param).value) == false)
    {
//alert('Please enter a valid email address');
document.getElementById(param).value = "";
document.getElementById(param).focus();
}
else
{
   var txtEmail= document.getElementById(param);
//   //alert(txtEmail.value);
PPS.PPSWebService.AddEmail(txtEmail.value, SucceededCallback);
document.getElementById(param).value = "";
}
    
}


// This function calls the Web service method and 
// passes the event callback function.  
function GetTime()
{
    PPS.PPSWebService.GetServerTime(SucceededCallback);
}


// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
//    var RsltElem = document.getElementById("ResultId");
//    RsltElem.innerHTML = result;
////alert(result);      


if(result== "true")
{
//newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;;
newPathname = "";
pathArray = window.location.pathname.split( '/' );
for(i = 1; i<pathArray.length-1; i++ ) 
{
newPathname += "/";
newPathname += pathArray[i];
}


//newPathname +="/thankyou.aspx";
newPathname +="/thankyou.aspx";
newURL = window.location.protocol + "//" + window.location.host + newPathname;
window.location = newURL;


} 
//else
//alert("Not Successful");
        


 
}




function AddEmailsForLP(param)
{


// //alert(param);
    if(document.getElementById(param).value=="")
    {
       //alert('Please enter an email address');
  document.getElementById(param).focus();
       return false;
}
      
    if(isValidEmail(document.getElementById(param).value) == false)
    {
//alert('Please enter a valid email address');
document.getElementById(param).value = "";
document.getElementById(param).focus();
}
else
{
   var txtEmail= document.getElementById(param);
//   //alert(txtEmail.value);
PPS.PPSWebService.AddEmail(txtEmail.value, SucceededCallbackForLP);
document.getElementById(param).value = "";
}
    
}






function SucceededCallbackForLP(result, eventArgs)
{
    // Page element to display feedback.
//    var RsltElem = document.getElementById("ResultId");
//    RsltElem.innerHTML = result;
////alert(result);      


if(result== "true")
{
//newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;;
newPathname = "";
pathArray = window.location.pathname.split( '/' );
for(i = 1; i<pathArray.length-1; i++ ) 
{
newPathname += "/";
newPathname += pathArray[i];
}


//newPathname +="/thankyou.aspx";
newPathname +="../../thankyou.aspx";
newURL = window.location.protocol + "//" + window.location.host + newPathname;
window.location = newURL;


} 
//else
//alert("Not Successful");
        


 
}


//function SucceededInsertCallback(result, eventArgs)
//{
//    // Page element to display feedback.
// if(result== "true")
// //redirect to thankyou page
// else
// //do not redirect
//        
//}




// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
}


 function isValidEmail(email)
 {   
    if (email.indexOf("@") < 1) 
    { //  must contain @, and it must not be the first character
        return false;
    }
    else if (email.lastIndexOf(".") <= email.indexOf("@")) 
    {  // last dot must be after the @
        return false;
    }
    else if (email.indexOf("@") == email.length)
    {  // @ must not be the last character
        return false;
    }
    else if (email.indexOf("..") >=0)
    { // two periods in a row is not valid
return false;
    }
    else if (email.indexOf(".") == email.length)
    {  // . must not be the last character
return false;
    }
    return true;
}



