﻿//this allows you to preload images like this:
//preload('image1.gif','image2.gif');
var myimages = new Array();
function preloadCommonImages(){
    for (x = 0; x < preloadCommonImages.arguments.length; x++)
	{
		myimages[x] = new Image();
		myimages[x].src = imgCommonpath + preloadCommonImages.arguments[x];
    }
}

var myimages2 = new Array();
function preloadThemeImages() {
    for (x = 0; x < preloadThemeImages.arguments.length; x++) {
        myimages2[x] = new Image();
        myimages2[x].src = imgpath + preloadThemeImages.arguments[x];
    }
}

//this prevents the window from scrolling to the top on validation
window.scrollTo = function(){}

//for masking input
$(function($){
   applyMasks();
});

function applyMasks()
{
	$(".phone:not(.masked)").addClass('masked').mask("(999) 999-9999",{placeholder:" "});
	$(".zipcode:not(.masked)").mask("99999",{placeholder:" "}).addClass('masked');
	$(".ssn:not(.masked)").mask("999-99-9999",{placeholder:" "}).addClass('masked');
	$(".ein:not(.masked)").mask("99-9999999",{placeholder:" "}).addClass('masked');
	$(".date:not(.masked)").mask("99/99/9999", { placeholder: " " }).addClass('masked');
}

function popupWin(url, name, width, height, scrollbars)
{
	var win = window.open(url, name, "width=" + width + ",height=" + height + ",scrollbars=" + scrollbars + ",toolbar=no,addressbar=no,resizable=yes,menubar=no");
	if(win){ win.focus(); }
}


//***********************************************************************************************
//***********************************************************************************************
// methods for collapsing and expanding sections
//***********************************************************************************************
//***********************************************************************************************
function SectionVisibility_SetControls(PersistStateTextBox, ToggleButton, DivName){
	// this method is called by SectionVisibility_Toggle and sets the link text, button src, and visibility of the DIV	
	if(document.getElementById(DivName)){ //make sure the div is visible
		var tbox = document.getElementById(PersistStateTextBox);
		var state = tbox.value;	    
    	
		var btn = $("#"+ToggleButton);
		
		//alert(DivName + ': ' + state);
		//$('#'+DivName).slideToggle(400);
    	
		if(state=='show'){
			//document.getElementById(DivName).style.display = 'block';
			//animatedcollapse.toggle(DivName);
			//btn.src = btn.src.replace('down','up');
			btn.attr("title", 'Hide this section');
			btn.removeClass('buttonExpand')
			btn.addClass('buttonCollapse');
			$('#' + DivName).addClass('showMe');
			$('#' + DivName).removeClass('hideMe');
		}else{
			//document.getElementById(DivName).style.display = 'none';
			//animatedcollapse.toggle(DivName);
			//btn.src = btn.src.replace('up','down');
			//btn.setAttribute('title', 'Expand this section');
			btn.attr("title", 'Expand this section');
			btn.removeClass('buttonCollapse')
			btn.addClass('buttonExpand');
			$('#' + DivName).addClass('hideMe');
			$('#' + DivName).removeClass('showMe');
		}
	    
		//set the cursor back to default in case we had set it to the wait-cursor
		//document.body.style.cursor = 'default';
		//btn.style.cursor = 'pointer';
	}
		
}

function SectionVisibility_Toggle(PersistStateTextBox, ToggleButton, DivName){
	//Instead of just toggling the controls in response to the click,
	//we'll set a flag in a hidden field. Then we'll call a method which
	//will toggle the controls based on the flag value.
	//This way, the visibility state can be persisted after a post-back.
	var tbox = document.getElementById(PersistStateTextBox);
	
	if(tbox.value=='show'){
		tbox.value='hide';
		setCookie(PersistStateTextBox, 'hide', null, null, null, false);				
	}else{
		tbox.value='show';
		setCookie(PersistStateTextBox, 'show', null, null, null, false);			
	}	
	SectionVisibility_SetControls(PersistStateTextBox, ToggleButton, DivName);
}

//***********************************************************************************************
//***********************************************************************************************
// methods for working with cookies via client-side code
//***********************************************************************************************
//***********************************************************************************************
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
	//if no expiry was passed, set it to a year from now
	if(expires == null){
		expires = new Date();
		expires.setHours(expires.getHours() + (365 * 24));
	}
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function toggleCompsView(view)
{
	var summ_display = '';
	var detail_display = '';
	
	if(view == 'detail')
	{
		summ_display = 'none';
		detail_display = '';
		
		$get('divCompsViewLink1').style.display = 'none';
		$get('divCompsViewLink2').style.display = '';
	}
	else
	{
		summ_display = '';
		detail_display = 'none';
		
		$get('divCompsViewLink1').style.display = '';
		$get('divCompsViewLink2').style.display = 'none';
	}
	
	var tbl = $get('tblComps');
	var cells = tbl.getElementsByTagName("td");
	
	for (var i=0;i<cells.length;i++) 
	{
		if(cells[i].className == "summary")
		{
			cells[i].style.display = summ_display;
		}
		else if(cells[i].className == "detail")
		{
			cells[i].style.display = detail_display;
		}
	}
}

function toggleNewTransSection(div, toggleLink, speed)
{
	$('#'+div).slideToggle(speed,function(){
		if($('#'+toggleLink).html() == '-')
		{
			$('#'+toggleLink).html('+');
		}
		else
		{
			$('#'+toggleLink).html('-');
			runOptionalCodeOnNewTransSectionOpen(div);
		}
	});
}
function closeNewTransSection(div, toggleLink, speed)
{
	$('#'+div).slideUp(speed,function(){
		$('#'+toggleLink).html('+');		
	});
}
function openNewTransSection(div, table, toggleLink, speed)
{
	$('#'+table).removeClass('newTransHeader_disabled');
	$('#'+table).addClass('newTransHeader');
	
	$('#'+div).slideDown(speed,function(){
		$('#'+toggleLink).html('-');
		$('#'+toggleLink).removeAttr('disabled');
		$('#'+toggleLink).attr("href","javascript:toggleNewTransSection('" + div + "','" + toggleLink + "'," + speed + ");");
		runOptionalCodeOnNewTransSectionOpen(div);			
	});
}
function runOptionalCodeOnNewTransSectionOpen(divName)
{
	var funcExists = eval('typeof ' + divName + '_optionalCode == \'function\'');
	if(funcExists == true)
	{
		eval(divName + '_optionalCode();');
	}
}

function JQscroll(obj, offset) {
    if (location.pathname.replace(/^\//, '') == obj.pathname.replace(/^\//, '') && location.hostname == obj.hostname) {
        var jQuerytarget = jQuery(obj.hash);
        jQuerytarget = jQuerytarget.length && jQuerytarget || jQuery('[name=' + obj.hash.slice(1) + ']');
        if (jQuerytarget.length) {
            var targetOffset = jQuerytarget.offset().top + offset;
            jQuery('html,body').stop().animate({ scrollTop: targetOffset }, 500, 'swing');
            return false;
        }
    }
}

function addMarginPublicLogin() {
    if ($("#pageIDWrapper")) {
        $("#pageIDWrapper").attr('style', 'margin-top:15px;')
    }
}

function removeMarginPublicLogin() {
    if ($("#pageIDWrapper")) {
        $("#pageIDWrapper").attr('style', 'margin-top:0px;')
    }
}


//(function($) {
//    $(document).ready(function() {
//        $('.styleswitch').click(function() {
//            switchStylestyle(this.getAttribute("rel"));
//            return false;
//        });
// });

//    function switchStylestyle(styleName) {
//        $('link[@rel*=style][title]').each(function(i) {
//            this.disabled = true;
//            if (this.getAttribute('title') == styleName) this.disabled = false;
//        });

//    }
//})(jQuery);
