﻿// JScript File

$(document).ready(function() {
     $('ul').each(function(index){
        var list = $(this);
        var original_height = list.height();
        var currentId = $(this).attr('id');
        var listItem =  'ul#' + currentId + ' li';
        var spanID = 'span#' + currentId.replace('ul','sp');
        var hrefID = 'a#' + currentId.replace('ul','toggle');
        var reqLength = 5;
        
        if( currentId == 'ulDirSubdirectoryList' || $(this).attr('class') == 'ulSubcategoryItems' || $(this).attr('class') == 'ulPackageContent' || currentId == 'ulRecommendedAgreements'){
            return false;        
        }
        
       if ($(listItem).length > reqLength){
            list.css({height:$(listItem).height()*5}); 
            if (hrefID != 'a#'){
                 $(hrefID).click(function() {
                        if($(hrefID).html() == 'read more...'){
                            list.animate({height:original_height})
                            $(hrefID).html('show less...');
                            return false;  
                        }
                        else
                        {
                             list.animate({height:$(listItem).height()*5})
                            $(hrefID).html('read more...');
                            return false;  
                        }
                 });   
             }
       }
       else
       {      
            list.css({height:$(listItem).height()*$(listItem).length});
            if(spanID != 'span#')
            {
              $(spanID).hide(); 
            }  
       } 
      
    });
    
    if($('#divAgreementList').length > 0){ 
        $('#divTextOffer').height($('#divAgreementList').height() - 20);
    }  
    
    //$('myOjbect').css('background-image', 'url("' + imageUrl + '")');
    $('a#aMoreOptions').click(function(){
    
        if ($('#divSearchArea').css().height() != '330'){
            $('#divBullseye').css({'background-image' : 'url(images/searchbaropen_03.jpg)' , 'height' : '330px'});
		    $('#divSearchRightCurve').css({'background-image' : 'url(images/searchbaropen_06.jpg)' , 'height' : '330px'});
		    $('#divSearch').css({'background-image' : 'url(images/searchbaropen_04.jpg)' , 'height' : '330px'});
		    $('#divSearchArea').animate({'height' : '330px'});
		   return false;   
        }
        else{
            $('#divBullseye').css({'background-image' : 'url(images/searchbar_03.jpg)' , 'height' : '120px'});
		    $('#divSearchRightCurve').css({'background-image' : 'url(images/searchbar_06.jpg)' , 'height' : '120px'});
		    $('#divSearch').css({'background-image' : 'url(images/searchbar_04.jpg)' , 'height' : '120px'});
		    $('#divSearchArea').animate({'height' : '105px'});
		   return false;   
        }
		
	});
	
	if($('#divAPPreviewBody').length > 0){
		$('#divAPLeftMargin').height($('#divAgreementPreviewBorder').height());
		$('#divAPRightMargin').height($('#divAgreementPreviewBorder').height() - 57);
	}
	
	$('a#aMoreFilters').click(function(){
	    var orgHeight = $('#divSiteMasterSearchContent').css().height();
	    
	    if($('#cssTxtSearch').length > 0){
	       $('#divSiteMasterSearchContent').animate({'height' : '190px'});
           $('a#aMoreFilters').css({'visiblility':'hidden'}) 
            return false; 
	    }
	    
	    if(orgHeight != '190'){
            $('#divSiteMasterSearchContent').animate({'height' : '190px'});
           $('a#aMoreFilters').css({'visiblility':'hidden'}) 
            return false; 
	    }
	    else{
            $('#divSiteMasterSearchContent').animate({'height' : '90px'});
            return false;  
	    }
	});
});

$(document).keypress(function(e)
{
    if(e.keyCode === 13)
    {
        e.preventDefault();
        return false;
    }
});

function pageLoad(sender, args)
{   
	$('a#aSearchDocument').click(function(){
	    if ($('#divAgreementContentSearch').css().height() != '20'){
	        $('#divAgreementContentSearch').animate({'height' : '20px'});
	        return false;
	    }
	    else{
	        $('#divAgreementContentSearch').animate({'height' : '150px'});
	       $('a#aSearchDocument').text('Search This Document');  
	        return false;
	    }
	});
	
	$('a#aExpandSubDirFilters').click(function(){
	    if ($('#divSubDirListFilter').css().height() != '0'){
	        $('#divSubDirListFilter').animate({'height' : '0'});
	       	$('a#aExpandSubDirFilters').text('Show More Filters');  
	        return false;
	    }
	    else{
	        $('#divSubDirListFilter').animate({'height' : '120px'});
	       $('a#aExpandSubDirFilters').text('Hide Filters');  
	        return false;
	    }
	});
}

function changeSiteSecurity(mustSecure, targetPage)
{
    if (mustSecure == 1)
    {
        document.location.href = encodeURI( "http://www.techagreements.com/" + targetPage );
    }
    else
    {
        document.location.href = encodeURI( "http://www.techagreements.com/" + targetPage );
    }
}

function checkEnter(e)
{ //e is event object passed from function invocation
    var characterCode //literal character code will be stored in this variable

    if(e && e.which)
    { //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else
    {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
        
         if(characterCode === 13)
        {
            e.preventDefault();
        }
    }

    if(characterCode == 13)
    { //if generated character code is equal to ascii 13 (if enter key)
        return true
    }
    else
    {
        return false
    }
}

function checkEnterTest(e, buttonid)
{ //e is event object passed from function invocation
    var characterCode //literal character code will be stored in this variable
    var bt = document.getElementById(buttonid);  

    if(e && e.which)
    { //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else
    {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (bt)
    {   
        if(characterCode == 13)
        { //if generated character code is equal to ascii 13 (if enter key)
            bt.click();   
            _gaq.push(['_trackPageview', '/inDocSearch.aspx']);
            return false;
        }
        else
        {
            return false
        }
    }
}

function ClickLink() {
  document.getElementById('anchorPayment').click();
//    document.getElementById('txtEmail').scrollIntoView(true);
}

function Focus(objname, waterMarkText) {
    obj = document.getElementById(objname);
    if (obj.value == waterMarkText) {
        obj.value = "";
        obj.className = "NormalTextBox";
        if (obj.value == "Search Term" || obj.value == "" || obj.value == null) {
            obj.style.color = "black";
        }
    }
}

function Blur(objname, waterMarkText) {
    obj = document.getElementById(objname);
    if (obj.value == "") {
        obj.value = waterMarkText;
        if (objname != "txtPwd") {
            obj.className = "WaterMarkedTextBox";
        }
        else {
            obj.className = "WaterMarkedTextBoxPSW";
        }
    }
    else {
        obj.className = "NormalTextBox";
    }

    if (obj.value == "Search Term" || obj.value == "" || obj.value == null) {
        obj.style.color = "gray";
    }
}
