﻿///Resolve external links ( target="_blank" fix in XHTML )
function externalLinks( ) 
{ 
	if ( !document.getElementsByTagName ) return;
	
	var anchors = document.getElementsByTagName( "a" );
	
	for ( var i = 0; i < anchors.length; i++ ) 
	{
		var anchor = anchors[ i ];
		if ( anchor.getAttribute( "href" ) && anchor.getAttribute( "rel" ) == "external" ) 
		{
			anchor.target = "_blank";
		}
	}
} 

//text resizer
var tgs = new Array( 'div' , 'a' , 'label' , 'span' , 'p' );

var szs = new Array( '12px','14px' );

var intFontVar = getCookie("fontvar");

var startSz = 0;

function ts( trgt,inc ) 
{
	if ( !document.getElementById ) return;
	
	setCookie( "fontvar" , inc , 86400 );
	
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	
	sz = sz < 0 ? 0 : sz;
	sz = sz > ( szs.length - 1 ) ? szs.length - 1 : sz;
	
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) 
	{
	    cEl = d.getElementsByTagName( trgt )[ 0 ];
	}
	
	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) 
	{
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		
		for ( j = 0 ; j < cTags.length ; j++ ) 
		{
		    cTags[ j ].style.fontSize = szs[ sz ];
		}
	}
}



//flash fixing
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}



/**********************************
©Nifty Corners 
http://www.html.it/articoli/nifty/index.html
*/
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
var b=navigator.userAgent.toLowerCase();
if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
    return(false);
return(true);
}

function Rounded(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    AddTop(v[i],bk,color,size);
    AddBottom(v[i],bk,color,size);
    }
}

function RoundedTop(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddTop(v[i],bk,color,size);
}

function RoundedBottom(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rbottom";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
var i;
var s=[];
var selid="";
var selclass="";
var tag=selector;
var objlist=[];
if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    objlist.push(document.getElementById(selid));
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className==selclass){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

/*Show/Hide Element*/
function ShowHideAnswer( elID , sender )
{
    if( $( elID ).style.display == '' )
    {
        $( elID ).style.display = 'block';
        $( sender ).style.color = '#cc3333';
        $( sender ).style.textDecoration = 'underline';
    }
    else if( $( elID ).style.display == 'block' )
    {
        $( elID ).style.display = '';
        $( sender ).style.color = '#333';
        $( sender ).style.textDecoration = 'none';
    }
}

/*popup div*/
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj()
{
	if (document.getElementById)
	return document.getElementById("preview_div").style
}

function gettrailobjnostyle()
{
	if (document.getElementById)
	return document.getElementById("preview_div")
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="0px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",1);
}

function show(imagename,title,width,height)
{
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) 
	{
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 
		
    	newHTML = '<img src="' + imagename + '" border="0">';

		gettrailobjnostyle().innerHTML = newHTML;
		
	}
}

function followmouse(e)
{

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	gettrailobj().display="block";

}

/**
 * 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) {
    var today = new Date( );
	today.setTime( today.getTime( ) );
	
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires_date.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";
    }
}

/*disabling page with fade effect*/
function disablePage( strBoxID , strComboClassName )
{
    var x = document.getElementById('disformbox');
    x.style.width = "100%";
    x.style.height = screen.height + "px";
    //x.style.backgroundColor = '#000000';
    x.style.left = 0;
    x.style.visibility = 'visible';
    //changeOpac(10, 'disformbox');
    displayExplainBox();

    if( navigator.appVersion.indexOf("MSIE")!= -1 )
    {
        //findDropDownLists( document.getElementById( strBoxID ) , strComboClassName , false );
    }
} 

/*display explain ox*/
function displayExplainBox()
{
    var x = document.getElementById('insideexplain');
    x.style.visibility = 'visible';
    x.style.display = 'block';
    x.style.left = ( ( document.body.offsetWidth / 2 ) - ( x.offsetWidth / 2 ) ) + "px";
    x.style.top = ( ( document.body.offsetHeight / 2 ) - ( x.offsetHeight * 2 ) ) + "px";
}

function hideExplainBox()
{
    var x = document.getElementById('insideexplain');
    x.style.visibility = 'hidden';
    x.style.display = 'none';
}

/*find dropdown lists & display(true)/hide(false)*/
function findDropDownLists( objEl , strClassName , boolHideShow )
{
    for( var y in objEl.childNodes )
    {
        if( objEl.childNodes != null && typeof objEl.childNodes != "undefined" )
        {
            if( strClassName == objEl.childNodes[ y ].className )
            {
                objEl.childNodes[ y ].style.visibility = boolHideShow ? "visible" : "hidden";
            }
            //findDropDownLists( objEl.childNodes[ y ] , strClassName , boolHideShow );
        }
    }
}

/*enable page*/
function enablePage( strBoxID , strComboClassName )
{
    var x = document.getElementById('disformbox');
    x.style.visibility = 'hidden';
    
    if( navigator.appVersion.indexOf("MSIE")!= -1 )
    {
        //findDropDownLists( document.getElementById( strBoxID ) , strComboClassName , true );
    }
    
    hideExplainBox();
}

/*on mouse over in table row */
function hoverRow(trRow)
{
	for(var c=0; c<trRow.cells.length; c++)
	{
		trRow.cells[c].style.backgroundColor = '#d3dee8';
		trRow.cells[c].style.textDecoration = 'underline';
		//trRow.cells[c].style.color = '#fff';
	}
}

/*on mouse out in table row */
function unHoverRow(trRow,ROWID)
{
    if( $(ROWID) != null && typeof $(ROWID) != "undefined" )
    {
        if( $(ROWID).style.visibility != 'visible' )
        {
            for(var c=0; c<trRow.cells.length; c++)
	        {
		        trRow.cells[c].style.backgroundColor = '#eff2f5';
		        trRow.cells[c].style.textDecoration = 'none';
		        //trRow.cells[c].style.color = '#333';
	        }    
        }
    }
}

function unhideRow( ROWID , senderRow , RETURNBOX , cHash, aHash)
{
    var browser = navigator.appName
    
    if( $(ROWID) != null && typeof $(ROWID) != "undefined" )
    {
        if( $(ROWID).style.display == '' )
        {
            hoverRow( senderRow );
            $(ROWID).style.visibility = 'visible';
            browser == "Microsoft Internet Explorer" ? $(ROWID).style.display = 'block' : $(ROWID).style.display = 'table-row'
            
            setAjaxCallUpdater('/agencies/displaycar.aspx?a=' + aHash+ '&c=' + cHash , RETURNBOX , {evalScripts: true, asynchronous:true});
        }
        else
        {
            unHoverRow( senderRow );
            $(ROWID).style.visibility = 'hidden';
            $(ROWID).style.display = '';
        }
    }
}


/********loans list********/
function unhideLoanRow( ROWID , senderRow , RETURNBOX , lHash)
{
    var browser = navigator.appName
    
    if( $(ROWID) != null && typeof $(ROWID) != "undefined" )
    {
        if( $(ROWID).style.display == '' )
        {
            hoverRow( senderRow );
            $(ROWID).style.visibility = 'visible';
            browser == "Microsoft Internet Explorer" ? $(ROWID).style.display = 'block' : $(ROWID).style.display = 'table-row'
            
            setAjaxCallUpdater('/members/getloanproperties.aspx?l=' + lHash, RETURNBOX , {evalScripts: true, asynchronous:true});
        }
        else
        {
            unHoverRow( senderRow );
            $(ROWID).style.visibility = 'hidden';
            $(ROWID).style.display = '';
        }
    }
}

/*******on mouse over in table row*******/
function hoverLoanRow(trRow, ROWID)
{
	for(var c=0; c<trRow.cells.length; c++)
	{
		trRow.cells[c].style.backgroundColor = '#d3dee8';
		trRow.cells[c].style.textDecoration = 'underline';
		$('ldelete_' + ROWID).src = '/assets/images/members/loan_list_delete_hover.gif';
		$('lprop_' + ROWID).src = '/assets/images/members/loan_list_info_hover.gif';
	}
}

/*******on mouse out in table row********/
function unHoverLoanRow(trRow,ROWID)
{
    if( $(ROWID) != null && typeof $(ROWID) != "undefined" )
    {
        if( $(ROWID).style.visibility != 'visible' )
        {
            for(var c=0; c<trRow.cells.length; c++)
	        {
		        trRow.cells[c].style.backgroundColor = '#eff2f5';
		        trRow.cells[c].style.textDecoration = 'none';
		        //trRow.cells[c].style.color = '#333';
	        } 
	        
	        $('ldelete_' + ROWID).src = '/assets/images/members/loan_list_delete.gif';
            $('lprop_' + ROWID).src = '/assets/images/members/loans_list_info.gif';   
        }
    }
}

/*AJAX tool functions - http://www.script.aculo.us - */
var ajax;

///updater ajax call
function setAjaxCallUpdater( url , div , arroptions )
{
	$(div).innerHTML = '<img src="/agencies/assets/images/indicator.gif" />'
 	ajax = new Ajax.Updater(
 		div,
 		url,
 		arroptions
	);
}

///updater ajax call(no indicator)
function setAjaxCallUpdaterNoIndicator( url , div , arroptions )
{
 	ajax = new Ajax.Updater(
 		div,
 		url,
 		arroptions
	);
}

/**
 * Preloading of images
 * 
 * @var Array preloadArray is global for access from other scripts 
 * to get the 'src' property of image
 */
var preloadArray = new Array( );

function preloadImages( )
{
	if (document.images)
	{
		var imgFiles = preloadImages.arguments;
		
		for ( var i = 0; i < imgFiles.length; i++ )
		{
			preloadArray[ i ] = new Image;
			preloadArray[ i ].src = imgFiles[ i ];
		}
	}
}	


/**
 * Find X object position
 * 
 * @return Integer Position X
 */ 
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft ;
}

/**
 * Find Y object position
 * 
 * @return Integer Position Y
 */
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/**
 * Fields marking effects
 * @param Object Element
 * @void 
 */
 function focusfield( _el )
 {
    if( _el != null && typeof _el != "undefined" )
    {
        _el.style.backgroundColor = "#f1f1f1";   
    }
 }

 function blurfield( _el )
 {
    if( _el != null && typeof _el != "undefined" )
    {
        _el.style.backgroundColor = "#f7f7f7";   
    }
 }