﻿// JScript File
function ValidateDeliveryOptions(source, arguments)
{
    rblDeliveryOptions_0 = document.getElementById('rblDeliveryOptions_' + 0);        
    rblDeliveryOptions_1 = document.getElementById('rblDeliveryOptions_' + 1);        
    if( (rblDeliveryOptions_0 != null) && (rblDeliveryOptions_1 != null) )
    {	
        if( (rblDeliveryOptions_0.checked == false) && (rblDeliveryOptions_1.checked != false) )
        {
            showmessage('Please select a delivery option');
            arguments.IsValid = false;    
        }
        else
        {
            arguments.IsValid = true;
        }
    }
}

var imageToSelectThumbNail;
function onOk() {
    if (imageToSelectThumbNail!= null)
    {
        $get('imgSelectedThumbnail').src = imageToSelectThumbNail;
    }
}

function ResetAllControls() {    
objItem = document.getElementById('rblDeliveryOptions_' + 0);        
if(objItem != null)
{	
    objItem.checked = false;
}	
objItem = document.getElementById('rblDeliveryOptions_' + 1);        
if(objItem != null)
{	
    objItem.checked = false;
}
document.getElementById("txtRecipientsLastName").value = "";
document.getElementById("txtRecipientsFirstName").value = "";
document.getElementById("txtRecipientsEmailAddress").value = "";
document.getElementById("txtSendersLastName").value = "";
document.getElementById("txtSendersFirstName").value = "";
document.getElementById("txtSendersEmailAddress").value = "";
document.getElementById("txtPersonalMessage").value = "";

CustomRequiredFieldValidator('lblRecipientsLastName', 'txtRecipientsLastName', '');
CustomRequiredFieldValidator('lblRecipientsFirstName', 'txtRecipientsFirstName', '');
CustomRequiredFieldValidator('lblRecipientsEmailAddress', 'txtRecipientsEmailAddress', '');
CustomRequiredFieldValidator('lblSendersLastName', 'txtSendersLastName', '');
CustomRequiredFieldValidator('lblSendersFirstName', 'txtSendersFirstName', '');
CustomRequiredFieldValidator('lblSendersEmailAddress', 'txtSendersEmailAddress', '');          

ValidatorEnable(Page_Validators[1],false);
ValidatorEnable(Page_Validators[2],false);
ValidatorEnable(Page_Validators[3],false);
ValidatorEnable(Page_Validators[4],false);
ValidatorEnable(Page_Validators[5],false);
ValidatorEnable(Page_Validators[6],false);
ValidatorEnable(Page_Validators[7],false);
ValidatorEnable(Page_Validators[8],false);
}
        
function CopyDataForPreview(DeliveryOptionPrompt, To, From) {   
    CheckValidation(DeliveryOptionPrompt);
    if (Page_ClientValidate()== true)
    {    
        ResetValidatorDisplay();
        $find("ModalPopupExtenderPreview").show();
        var index = $get('imgSelectedThumbnail').src.lastIndexOf('=');
        //alert($get('imgSelectedThumbnail').src.substring(index+1).replace("//", "/"));
        $get('imgPreviewSelectedImage').src = $get('imgSelectedThumbnail').src.substring(index+1).replace("//", "/").replace("ThumbNails", "Preview");            
        document.getElementById("divToRecipientsName").innerHTML = To + document.getElementById("txtRecipientsFirstName").value + ' ' +  document.getElementById("txtRecipientsLastName").value;
        document.getElementById("divPersonalizedMessage").innerHTML = document.getElementById("txtPersonalMessage").value;
        document.getElementById("divSendersName").innerHTML = From + document.getElementById("txtSendersFirstName").value + ' ' + document.getElementById("txtSendersLastName").value;           
     }
}

function EnableMandatoryFields()
{
     if (document.getElementById("rblDeliveryOptions_1").checked)
     {
        document.getElementById("spanEmail").style.visibility = "hidden";
     }
     else
     {
        document.getElementById("spanEmail").style.visibility = "visible";
     }
}

function ResetValidatorDisplay() {
    CustomRequiredFieldValidator('lblRecipientsLastName', 'txtRecipientsLastName', '');
    CustomRequiredFieldValidator('lblRecipientsFirstName', 'txtRecipientsFirstName', '');
    CustomRequiredFieldValidator('lblRecipientsEmailAddress', 'txtRecipientsEmailAddress', '');
    CustomRequiredFieldValidator('lblSendersLastName', 'txtSendersLastName', '');
    CustomRequiredFieldValidator('lblSendersFirstName', 'txtSendersFirstName', '');
    CustomRequiredFieldValidator('lblSendersEmailAddress', 'txtSendersEmailAddress', '');          
}
        
function CheckValidation(DeliveryOptionPrompt) {

objItemrblDeliveryOptions_0 = document.getElementById('rblDeliveryOptions_' + 0);        
objItemrblDeliveryOptions_1 = document.getElementById('rblDeliveryOptions_' + 1);        
if ( (objItemrblDeliveryOptions_0 != null) && (objItemrblDeliveryOptions_1 != null) )
{	
    if ( (objItemrblDeliveryOptions_0.checked == false) && (objItemrblDeliveryOptions_1.checked == false) )
    {	
        alert(DeliveryOptionPrompt);
        ValidatorEnable(Page_Validators[1],false);
        ValidatorEnable(Page_Validators[2],false);
        ValidatorEnable(Page_Validators[3],false);
        ValidatorEnable(Page_Validators[4],false);
        ValidatorEnable(Page_Validators[5],false);
        ValidatorEnable(Page_Validators[6],false);
        ValidatorEnable(Page_Validators[7],false);
        ValidatorEnable(Page_Validators[8],false);
    }            
    else
    {
        ValidatorEnable(Page_Validators[1],true);
        ValidatorEnable(Page_Validators[2],true);
        ValidatorEnable(Page_Validators[3],true);
        ValidatorEnable(Page_Validators[4],true);
        ValidatorEnable(Page_Validators[5],true);
        ValidatorEnable(Page_Validators[6],true);
        ValidatorEnable(Page_Validators[7],true);
        ValidatorEnable(Page_Validators[8],true);

        CustomRequiredFieldValidator('lblRecipientsLastName', 'txtRecipientsLastName', 'error');
        CustomRequiredFieldValidator('lblRecipientsFirstName', 'txtRecipientsFirstName', 'error');
        CustomRequiredFieldValidator('lblRecipientsEmailAddress', 'txtRecipientsEmailAddress', 'error');
        CustomRequiredFieldValidator('lblSendersLastName', 'txtSendersLastName', 'error');
        CustomRequiredFieldValidator('lblSendersFirstName', 'txtSendersFirstName', 'error');
        CustomRequiredFieldValidator('lblSendersEmailAddress', 'txtSendersEmailAddress', 'error');          
    }
    
    if (Page_ClientValidate()== true)
    {    
        ResetValidatorDisplay();
    }
}	       
 
         

objItem = document.getElementById('rblDeliveryOptions_' + 0);        
if(objItem != null)
{	
if ( objItem.checked )
    {
    ValidatorEnable(rfvRecipientsEmailAddress,true);
    }
else
    {
    ValidatorEnable(rfvRecipientsEmailAddress,false);
    }
}	

//        objItem = document.getElementById('rfvRecipientsEmailAddress');
//        var str='';
//        for(prop in objItem)
//        {
//            str+=prop + " value :"+ objItem[prop]+"<br>";        
//        }        
//        alert(objItem['isvalid']); 
//        document.write(str); 
}

function UpdatePagingControlDisplay(PagingControlLinkButton, divPagingControlLinkButton, PageNumber) {       
for (var x = 1; x <= 12; x++)
{
    msg = "panelShowHide"+ x;
    ShowHideControl(msg, 'block');
}

var msg = "";           
var showhide = "";           

for (var x = 1; x <= 3; x++)
{
    msg = "divPagingControlLinkButton"+ x;
    objItem = document.getElementById(msg);
    if(objItem != null)
    {
     objItem.innerHTML = "<a id=\"PagingControlLinkButton" + x + "\" href=\"javascript:UpdatePagingControlDisplay(\'PagingControlLinkButton" + x + "\', \'divPagingControlLinkButton" + x + "\', \'" + x + "\')\">" + x + "</a>";;
    }
}   
            
//alert( parseInt(PageNumber));
if ( parseInt(PageNumber) == 1 )
{             
    for (var x = 5; x <= 12; x++)
    {
        msg = "panelShowHide"+ x;
        ShowHideControl(msg, 'none');
    }            
}
else if ( parseInt(PageNumber) == 2 )
{             
    for (var x = 1; x <= 4; x++)
    {
        msg = "panelShowHide"+ x;
        ShowHideControl(msg, 'none');
    }
    for (var x = 9; x <= 12; x++)
    {
        msg = "panelShowHide"+ x;
        ShowHideControl(msg, 'none');
    }
}       
else if ( parseInt(PageNumber) == 3 )
{             
    for (var x = 1; x <= 8; x++)
    {
        msg = "panelShowHide"+ x;
        ShowHideControl(msg, 'none');
    }
}       
document.getElementById(divPagingControlLinkButton).innerHTML = PageNumber;
}

function ShowHideControl(msg, showhide){
    objItem = document.getElementById(msg);
    //alert(msg);
    //alert(showhide);
    if(objItem != null)
    {
        objItem.style.display = showhide;
    }
}        

function CustomRequiredFieldValidator(ControlLbl, ControlValue, ErrorClass)
{
var aControltovalidate = document.getElementById(ControlLbl);	    
if(aControltovalidate != undefined)
{            
    document.getElementById(ControlLbl).className = '';
    if ((document.getElementById(ControlValue).value.length) == 0 ){                       
      if ( ControlLbl == 'lblRecipientsEmailAddress' )
      {       
        var objItem = document.getElementById('rblDeliveryOptions_' + 0);        
        if(objItem != null)
        {	
            if ( objItem.checked )
            {
                document.getElementById(ControlLbl).className = ErrorClass;
            }
        }	
      }
      else
      {  
        document.getElementById(ControlLbl).className = ErrorClass;
      }
	 }
     else
     {        
        if ( ( ControlLbl == 'lblRecipientsEmailAddress' ) && (!IsSyntacticallyValidEmail(document.getElementById(ControlValue).value)) )
        {       
            document.getElementById(ControlLbl).className = ErrorClass;
        }
        else if ( ( ControlLbl == 'lblSendersEmailAddress' ) && (!IsSyntacticallyValidEmail(document.getElementById(ControlValue).value)) )
        {       
            document.getElementById(ControlLbl).className = ErrorClass;
        }
        else
            document.getElementById(ControlLbl).className = '';
     }			
 }
}

function IsSyntacticallyValidEmail(str) {  
// are regular expressions supported?  
var supported = 0;  
if (window.RegExp) {    
var tempStr = "a";    
var tempReg = new RegExp(tempStr);    
if (tempReg.test(tempStr)) supported = 1;  }  
if (!supported)    
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);  
var r1 = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");  
return (r1.test(str) );
}

function OpenPatientQAWindow(url) {
varReturn = window.showModalDialog(url,"Dialog Arguments Value","dialogHeight: 312px; dialogWidth: 400px; center: Yes; help: yes; resizable: No; status: no;scroll=yes"); 
}

function ShowPatientQAWindow() {
    var availHeight = getWindowHeight();
    var availWidth = getWindowWidth();
    var indicatorWidth = 400;
    var indicatorHeight = 312;
    var top = (availHeight/2) - (indicatorHeight/2);
    var yOffset = getScrollTop();
    var left = (availWidth/2) - (indicatorWidth/2);
    var top = ((availHeight/2)+yOffset) - (indicatorHeight/2);
    document.getElementById("PatientQAWindow").style.top = top + "px";
    document.getElementById("PatientQAWindow").style.left = left + "px";
    document.getElementById("PatientQAWindow").style.visibility = 'visible';
    
    window.frames['iWarning'].document.body.scrollTop = 0;
}

function HidePatientQAWindow() {
	window.parent.document.getElementById("PatientQAWindow").style.visibility = 'hidden';
}

function getWindowWidth() {
	return filterResultsHelper (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function getWindowHeight() {
	return filterResultsHelper (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function getScrollLeft() {
	return filterResultsHelper (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function getScrollTop() {
	return filterResultsHelper (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filterResultsHelper(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

