﻿// JScript File

//used for showing mouse over images
function mouseOverImage(inputImg) {
    inputImg.src = inputImg.src.replace("_normal", "_over");

}
//used for showing mouse over images
function originalImage(inputImg) {
    inputImg.src = inputImg.src.replace("_over", "_normal");
}

//utility function to get drop down value
function getDropdownValue(dropdown) {
    try{
        if (dropdown) {
            if (dropdown.length) {
                var len = dropdown.length;
                for (i = 0; i < len; ++i) {
                    if (dropdown.options[i].selected) {
                        var value = dropdown.options[i].value;
                        if(value && value!=null){
                            if (value == '0' || value == '-1') {
                                return '';
                            } else {
                                return value;
                            }
                        }else{
                            return '';
                        }
                    }
                }
            } else {
                return '';
            }
        } else {
            return '';
        }
    }catch(e) {
       return '';
    }
}

//set the context key, for autocomplete list
function setContextKeyForAC(selectedItem, id) 
{          
    var ac = getDropdownValue(selectedItem); 
    if(!id) {
        id='SuburbAutoComplete1';
    }         
    $find(id).set_contextKey(ac);
}
        
// calling Iframe methods to show google map mouse over info window
function callIFrameGoogleMap(label) 
{   
    var frames = window.frames; 
    if(!frames){
        frames = window.parent.frames;
    }
    // need to fix this, but by name it does not work in all the browser
    // and also sequence is not same on all the browsers
    for (var i = 0; i < frames.length; i++) { 
        // do something with each subframe as frames[i]
        try{
            frames[i].window.showMapDetails(label);          
            break;
        }catch(e){            
        }
    }       
 }
 
 // calling Iframe methods to show google map mouse over info window
function callGoogleMap(label) 
{   
   showMapDetails(label);          
   
 }
 function fnShowPopUp_GoogleMap_LatLon_Common(label)
{    
     for (var i = 0; i < frames.length; i++) 
     { 
        // do something with each subframe as frames[i]
        try
        {
            frames[i].window.showMapDetails(label);          
            if(window.parent.document.getElementById('footer'))
            {        
                window.parent.document.getElementById('footer').focus();
            }
            break;
        }
        catch(e)
        {            
        }
    }    
}
function fnShowPopUp_GoogleMap_Address_Common(label) 
{
    for (var i = 0; i < frames.length; i++) 
     { 
        // do something with each subframe as frames[i]
        try
        {
            frames[i].window.showMapDetails(label);          
            if(window.parent.document.getElementById('footer'))
            {        
                window.parent.document.getElementById('footer').focus();
            }
            break;
        }
        catch(e)
        {            
        }
    }
}
 
 function openPopUpWindow(url,height,width) {  
    var w = 800, h = 600; 
    try{
       w = screen.width;
       h = screen.height;
    }catch(e) {
    }
    var leftPos = (w-width)/2, topPos = (h-height)/3;
    var features = 'top='+topPos+',bottom=50,left='+leftPos+',right=50,width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes';
    var newWindow= window.open(url,'miehmap',features);    
}

// to make left and right column on sumary list page same.
function equalDivs() {
 try{
    var height_left = 0;
    var height_right = 0;    
    if(document.getElementById('content_body').clientHeight) {
        height_left=document.getElementById('content_body').clientHeight;
        height_right =document.getElementById('ctl00_right_content_panel').clientHeight;
    } else if( document.getElementById('content_body').offsetHeight){
        height_left=document.getElementById('content_body').offsetHeight;
        height_right =document.getElementById('ctl00_right_content_panel').offsetHeight;
    } 
    // top title and footer height sum
    var diff = 32;  
    if((height_left + diff) > (height_right)) {     
        // minor adjustment   
        document.getElementById('content_body').style.height=height_right - diff - 15+"px";
        document.getElementById('content_body').style.overflow="auto";
    }   
    }catch(e) {
        // if browser does not suppor then forget it
    }
}

//To validate Transaction Id entered to approve premium article 
function fnValidateTransactionId(_objCtrl, txtControlId, varArticleId)
{                           
    if(_objCtrl && txtControlId)
    {       
        var varDivId = 'divErrorMessage_'+varArticleId;
        document.getElementById(varDivId).innerHTML='';
        
        //Compare text with Approve        
        if(_objCtrl.innerHTML == "Approve")
        {            
            if(document.getElementById(txtControlId))
            {
                var RegularExpression = /^\d{1}[\d|\w]{16}$/;  
                if (document.getElementById(txtControlId).value.search(RegularExpression)==-1)
                {                                      
                    document.getElementById(varDivId).innerHTML='Please provide a valid Transaction Id to continue.';
                    return false;
                }
                else       
                {                    
                    return true;                
                }
            }
            else
            {
                document.getElementById(varDivId).innerHTML='Please provide a valid Transaction Id to continue.';
                return false;            
            }
        }
        else
        {            
            return true;
        } 
    } 
    else
    {
        //document.getElementById('divErrorMessage').innerHTML='Please provide a valid Transaction Id to continue.';
        //return false;
        
        return true;
    }
}

function fnAllowNumbers(evt)
{
    var keyName = (evt.which) ? evt.which : event.keyCode         
    if (keyName > 31 && (keyName < 48 || keyName > 57))
        return false;
    return true;
}
function fnAllowPhoneNumbers(evt) {
    var keyName = (evt.which) ? evt.which : event.keyCode
    if (keyName == 32 || keyName == 43)
        return true;
    else if (keyName > 31 && (keyName < 48 || keyName > 57))
        return false;
    return true;
}
function fnMoveFocus()
{                        
    if(window.parent)
    {                    
        var varTop = document.documentElement.scrollHeight;
        window.scrollTo(0,varTop);
    }
    else
    {
        var varTop = document.documentElement.scrollHeight;
        window.scrollTo(0,varTop);
    }
}

function fnMoveFocus_Tourism()
{                        
    if(window.parent)
    {                    
        var varTop = document.documentElement.scrollHeight;
        window.scrollTo(0,varTop-150);
    }
    else
    {
        var varTop = document.documentElement.scrollHeight;
        window.scrollTo(0,varTop-150);
    }
}