﻿// JScript File

var popupWinodw;
var selectionClear;
var mySearchUrl     = 'http://connect.me.com.au/lookatme/search/mysearches.aspx?id='
var searchResultUrl = 'http://connect.me.com.au/lookatme'
var searchCondition;

function showPreview(url)
{
    popupWindow = window.open(url,'popupWindow','height=600,width=800,status=yes,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no');                
    popupWindow.focus();
    //window.location.replace(url)
}

function setField(selectField)
{     
    if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtDateOperator.value == '0' || selectField.value=='Between')
    {
        document.aspnetForm.ctl00$ContentPlaceHolder1$txtDateOperator.value = selectField.selectedIndex
        document.aspnetForm.submit()
    }
    else
    {
       document.aspnetForm.ctl00$ContentPlaceHolder1$txtDateOperator.value = selectField.selectedIndex
    } 
}

function setSelected()
{
    var arySelected
    var index
    var chkIndex
    
    if (selectionClear == true)
    {
        document.aspnetForm.txtSelectedId.value = ''
    }
    else
    {            
        if (document.aspnetForm.chkSelected)
        {
            arySelected = document.aspnetForm.txtSelectedId.value.split(',')      
            for (index = 0; index < arySelected.length; index++)
            {
                for (chkIndex = 0; chkIndex < document.aspnetForm.chkSelected.length; chkIndex++)
                {
                    window.status = 'Setting the selected search results'
                    
                    if (document.aspnetForm.chkSelected[chkIndex].value == arySelected[index])
                    {
                        document.aspnetForm.chkSelected[chkIndex].checked = true
                        break;
                    }            
                }
            }
            window.status = 'Done'
        }
    }
}

function Save() 
{    

    window.mode = "save";
    popupWindow = window.open('MySearchDialogue.aspx','popupWindow','height=235,width=550,status=yes,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no');
    popupWindow.focus();     
}

function PublicSave() 
{    
    var arySelected
    var index
    
       
    arySelected = (document.aspnetForm.txtSelectedId.value + ',').split(',')
    if (document.aspnetForm.txtSelectedId.value.length > 0)
    {
        window.mode             = "publicsave";
        for (index = 0; index < arySelected.length; index++)
        {
            if (arySelected[index].length > 0)
            {
                if (index == 0)
                {
                    window.MySearchId       = arySelected[index];
                }
                else
                {
                    window.MySearchId = window.MySearchId + ',' +  arySelected[index];
                }
            }
        }
        window.MySearchTitle    = 'Selected - Search Result';                     
        popupWindow = window.open('MySearchDialogue.aspx','popupWindow','height=260,width=630,status=yes,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no');
        popupWindow.focus();
    }
    else
    {
        alert('Please select the search result (using the check boxes) to save into My Searches.\n\nMinimum of 1 search result should be selected before saving')
    }
}

function emailMessage()
{
    var arySelected
    var index
    
       
    arySelected = (document.aspnetForm.txtSelectedId.value + ',').split(',')    
    if (document.aspnetForm.txtSelectedId.value.length > 0)
    {
        window.mode             = "message";
        for (index = 0; index < arySelected.length; index++)
        {
            if (arySelected[index].length > 0)
            {
                if (index == 0)
                {
                    window.MySearchId       = searchResultUrl + arySelected[index];
                }
                else
                {
                    window.MySearchId = window.MySearchId + '\n' + searchResultUrl + arySelected[index];
                }
            }
        }
        window.MySearchTitle    = 'Selected - Search Result';                     
        popupWindow = window.open('MySearchDialogue.aspx','popupWindow','height=575,width=700,status=yes,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no');
        popupWindow.focus();
    }
    else
    {
        alert('Please select the search result (using the check boxes) to include in the email message.\n\nMinimum of 1 search result should be selected to generate an email message')
    }
}

function setValue(target, source)
{  
    if (target.value.length == 0)
    {
        target.value = source.value
    }
}

function setMessage(field)
{
    var arySelected
    var arySelectedNew
    var index
    var isFound = false
 
    if (field.checked == true)
    {
        if (document.aspnetForm.txtSelectedId.value.length > 0)
        {
            document.aspnetForm.txtSelectedId.value = document.aspnetForm.txtSelectedId.value + ',' + field.value
        }
        else
        {
            document.aspnetForm.txtSelectedId.value = field.value
        }
    }
    else
    {   
    
        var indexFound
                          
        arySelected                     = document.aspnetForm.txtSelectedId.value.split(',')
        document.aspnetForm.txtSelectedId.value  = ''        
        for (indexFound = 0; indexFound < arySelected.length; indexFound++)
        {
            if (arySelected[indexFound] != field.value)
            {
                if (document.aspnetForm.txtSelectedId.value.length > 0)
                {
                    document.aspnetForm.txtSelectedId.value = document.aspnetForm.txtSelectedId.value + ',' + arySelected[indexFound]
                }
                else
                {
                    document.aspnetForm.txtSelectedId.value = arySelected[indexFound]
                }
            }
        }                    
     }     
}
