
// pop up window
// example: <a href=javascript:openWin('preview.php','Preview','')>preview</a>
function openWin(theURL,winName,features) {
	newWin = window.open(theURL,winName,features);
	newWin.focus();
}

// validate email address
// if valid return true 
function validEmail(str) {
	// are regex supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

// for select drop down navigation menus
function jumpMenu(targ,selObj,restore){
	if (selObj.options[selObj.selectedIndex].value != "") {
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
	if (restore) selObj.selectedIndex=0; 
	}
}

var rollflag = false;

function imgLoad() {  // called with init()
    if (document.images) {
		// load mag issues
		var issue_date = '20050404';
		var proto = window.location.protocol;
		
		cvr_east = new Image(); cvr_east.src = proto+"//www.insurancejournal.com/img/cover_east_"+issue_date+".jpg";
		cvr_midwest = new Image(); cvr_midwest.src = proto+"//www.insurancejournal.com/img/cover_midwest_"+issue_date+".jpg";
		cvr_southeast = new Image(); cvr_southeast.src = proto+"//www.insurancejournal.com/img/cover_southeast_"+issue_date+".jpg";
		cvr_southcentral = new Image(); cvr_southcentral.src = proto+"//www.insurancejournal.com/img/cover_southcentral_"+issue_date+".jpg";
		cvr_west = new Image(); cvr_west.src = proto+"//www.insurancejournal.com/img/cover_west_"+issue_date+".jpg";

        return (rollflag = true);  // set the flag and let the function know know it can work
    }
}

function imgSwap(imgName,newImage) {
    if (document.images && (rollflag == true)) {
        document[imgName].src = eval(newImage + ".src");
    }
}

function onLoadInit() { // function to call functions that should be called "onload"
	imgLoad();
}

function toggleVisible(x)
{
	if (document.getElementById(x).style.display == 'none') {
		//document.getElementById(divid).style.visibility = 'visible';
		document.getElementById(x).style.display = '';
	} else {
		//document.getElementById(divid).style.visibility = 'hidden';
		document.getElementById(x).style.display = 'none';
	}
}


/***** START COOKIE FUNCTIONS */

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

/***** START EXPANDING DIV FUNCTIONS */

// ----------------------------------------
// container for our div properties 
//	name - name of div
// increment - resize increment
// interval - interval speed
// closeh - height when closed
// openh - height when open
// currenth - current height
// done - done moving?
// sizer - holds interval
// status - open, closed, move, or null
// toggle_open - toggle "open" button or text
// toggle_close - toggle "close" button or text
// content_open - content when open
// content_close - content when closed
// ----------------------------------------

var xdiv = new Array();

function new_xdiv(divname,closeh,openh) {
  xdiv[divname] = new Array();
	xdiv[divname]['name'] = divname; // name of div
	xdiv[divname]['increment'] = 1; // resize increment
	xdiv[divname]['interval'] = 15; // interval speed
	xdiv[divname]['closeh'] = closeh; // start height
  xdiv[divname]['openh'] = openh; // end height
  xdiv[divname]['currenth'] = xdiv[divname]['closeh']; // current height
  xdiv[divname]['done'] = null; // done moving?
  xdiv[divname]['sizer'] = null; // holds interval
  xdiv[divname]['status'] = null; // open, closed, move, or null
  xdiv[divname]['toggle_open'] = '<span onclick="javascript:xdiv_open(\''+divname+'\');">Expand +</span>'; // toggle "open" button or text
  xdiv[divname]['toggle_close'] = '<span onclick="javascript:xdiv_close(\''+divname+'\');">Close -</span>'; // toggle "close" button or text
  xdiv[divname]['content_open'] = 'open'; // content when open
  xdiv[divname]['content_close'] = 'closed'; // content when closed
}

function xdiv_grow(divname)
{
	// test if we're done opening / closing
	if (xdiv[divname]['currenth'] >= xdiv[divname]['openh']) {
		clearInterval(xdiv[divname]['sizer']);
  	document.getElementById(divname+'_content').innerHTML = xdiv[divname]['content_open'];
		xdiv[divname]['status'] = 'complete';
    document.getElementById(divname+'_content').style.display = 'block';
	} else {
  	xdiv[divname]['currenth'] += xdiv[divname]['increment'];
    document.getElementById(divname+'_content').style.height = xdiv[divname]['currenth'] + 'px';
	}
}

function xdiv_shrink(divname)
{
	// test if we're done opening / closing
	if (xdiv[divname]['currenth'] <= xdiv[divname]['closeh']) {
		clearInterval(xdiv[divname]['sizer']);
  	document.getElementById(divname+'_content').innerHTML = xdiv[divname]['content_close'];
    xdiv[divname]['status'] = 'complete';
	} else {
  	xdiv[divname]['currenth'] -= xdiv[divname]['increment'];
    document.getElementById(divname+'_content').style.height = xdiv[divname]['currenth'] + 'px';
	}
}

function xdiv_open(divname)
{
	if (xdiv[divname]['status'] != 'busy')
	{
   	document.getElementById(divname+'_toggle').innerHTML = xdiv[divname]['toggle_close'];
		
  	xdiv[divname]['currenth'] = xdiv[divname]['closeh'];
  	xdiv[divname]['status'] = 'busy';
		
  	xdiv[divname]['sizer'] = setInterval("xdiv_grow(\'"+divname+"\');", xdiv[divname]['interval']);
  }
	
 	document.getElementById(divname+'_content').innerHTML = xdiv[divname]['content_open'];
}

function xdiv_close(divname)
{
	if (xdiv[divname]['status'] != 'busy')
	{
//    document.getElementById('adcontent').style.display = 'none';
  	document.getElementById(divname+'_toggle').innerHTML = xdiv[divname]['toggle_open'];
		
  	xdiv[divname]['currenth'] = xdiv[divname]['openh'];
		xdiv[divname]['status'] = 'busy';
  	
  	xdiv[divname]['sizer'] = setInterval("xdiv_shrink(\'"+divname+"\');", xdiv[divname]['interval']);
	}
}

/***** END EXPANDING DIV FUNCTIONS */
