	var currTab = "";
	
	function initBlockUI()
	{
        $.blockUI.defaults.css = { 
                    border: 'none', 
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .5, 
                    width: '30%',
                    top: '40%',
                    left: '35%',
                    textAlign: 'center',
                    margin: 0,
                    color: '#fff' ,
                    cursor: 'wait'
                };
        $(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
	}
	
	function closeTabs(id){
		var $ctn = $('.tabOff');
    
    	for( var i = 0, n = ($ctn.length + 1);  i < n;  ++i ) {
	        var element = $ctn[i];
	        if ($('#ctntab' + i).is(':visible') && (id!=currTab)) {
				$('#ctntab' + i).toggle(500);
				var currentImg = $('#tab'+i).attr('src');
				$('#tab'+i).attr('src', $('#tab'+i).attr('hover'));
				$('#tab'+i).attr('hover', currentImg);
			}
	    }
	
	}
	
	//Banner
	$(document).ready(function() {
       	$(function() {
			
			if(document.getElementById('sponser')) 
			{
			  $('#sponser a').attr('href', 'http://www.safetynational.com');
              
			  var id = $('#sponser img').attr('id');
			  
			  if($('#sponser img').attr('src').indexOf('../') != -1) {
				 
					 
				 if(id) {
					src_link = '../corner_img/SafetyNationa2.gif';
				 } else {
					src_link = '../corner_img/468x60-Elephant-Ad.gif';
					$('#sponser a').attr('href', 'http://www.reduceyourworkerscomp.com');
				 }
					 
			  } else {
				
				 if(id) {
					src_link = 'corner_img/SafetyNationa2.gif';
				 } else {
					src_link = 'corner_img/468x60-Elephant-Ad.gif';
					$('#sponser a').attr('href', 'http://www.reduceyourworkerscomp.com');
				 }
			  }
			  $('#sponser img').attr('src', src_link);
			}
	
        });
    });
	
	$(document).ready(function() {
       	$(function() {
			/*
				Check if the clicked botton is purchase or (request and submit)
			*/
			$('.thickbox').click(function() {
				var value = $(this).attr('value');
				try {
					if(value.indexOf('PURCHASE')=='0')
					{ 
						$('p.purchaseSubtitle').html("Please note that placing this order request generates an email that is sent to our Billing department. For your security, you will be contacted by one of our representatives to complete your order.<br /><br />Please note that a Sales tax rate @ 8.875% applies to all sales within New York State.");
					}
					else 
					{
						$('p.purchaseSubtitle').text('');
					}
				 } catch(ex){}
			 });
			
        });
    });
	
	
	$(document).ready(function() {
       	$(function() {
			 
			//open sampePage
			$('.sampePage').click(function() {
				var link = $(this).attr('alt');
				gotoPage(link);
			 });
			
        });
    });

	
	$(document).ready(function() {
       	$(function() {
			 
			//open External window
			$('.externalWindow').click(function() {
				var link = $(this).attr('alt');
				openNewPage(link);
			 });
			
        });
    });

	/* campersky added 5/15/2009 -start */
	/*
		use by 
		partners_wctoolkit_survey.html
		partners_wctoolkit_home.html
	*/
	$(document).ready(function() {
		$(function() {
			  // if img is click
			  $('.title_img').click(function() {

					if ($('#sub'+this.id).is(':visible')) 
					{
						$(this).attr('src','corner_img/leftmenu_plus.gif');
						$('#sub'+this.id).toggle(10);
					}
					else
					{
						$(this).attr('src','corner_img/leftmenu_minus.gif');
						$('#sub'+this.id).toggle(10);
					}
					
			  });
			  // title is click
			  $('.title_txt').click(function() {
				
				var img_id = $(this).siblings(".title_img").attr("id");
					
					if ($('#sub'+img_id).is(':visible')) 
					{
						$('#'+img_id).attr('src','corner_img/leftmenu_plus.gif');
						$('#sub'+img_id).toggle(10);
					}
					else
					{
						$('#'+img_id).attr('src','corner_img/leftmenu_minus.gif');
						$('#sub'+img_id).toggle(10);
					}
				
			  });
		});
	});
	//campersky added 5/15/2009 -end
	
  	$(document).ready(function() {
		
		/*
			$('.tabBtn').click(function() {
		
				var id = $(this).attr('id');
				closeTabs(id);
				currTab = id;
			if ($('#ctn' + id).is(':visible')) {
				var newSrc = $('#'+id).attr("src").replace("_on","_off");
				$('#'+id).attr("src",newSrc);
			
			} else {
				var newSrc = $('#'+id).attr("src").replace("_off","_on");
				$('#'+id).attr("src",newSrc);
			}
			 $('#ctn' + id).toggle(500);
			 
			 return false;
			 });


			$(function() {
			
			$('.tabBtn').hover(function() {
				if($(this).attr('id') == currTab){
					return;
				}
				var currentImg = $(this).attr('src');
				$(this).attr('src', $(this).attr('hover'));
				$(this).attr('hover', currentImg);
			}, function() {
				if($(this).attr('id') == currTab){
					return;
				}
				var currentImg = $(this).attr('src');
				$(this).attr('src', $(this).attr('hover'));
				$(this).attr('hover', currentImg);
			});
		});
		
		*/
			
		/* start camper */
		/* 
		 * @description: corner leftmenu enhancement
		 *	
		 * @date: 02/13/2009
		 *
		 */
		
		var curTab = '';
		var il = '';
		$(function() {
							
			$('.tabBtn').hover(
			
				function() { // mouseover 
					
				//if(this.parentNode.nodeName == 'A') this.parentNode.removeAttribute('href'); //remove attribute href, cause javascript error
					
					curTab = $(this).attr('id'); 
					changePosition(curTab);
					$('#'+curTab).attr('style',"cursor:pointer;");
			
					if($('#'+curTab).attr('src').indexOf('off') != -1)
					{
						$('#'+curTab).attr('src' , $('#'+curTab).attr('src').replace('off','on'));
					}
					
					$('#ctn'+this.id).show();
					
					$('#ctn'+this).bind('mouseout',function() {
						$('#ctn'+this.id).hide();
					});
					
					$(this).bind('click',function() {
						clickTab(curTab, $('#'+curTab).attr('src'));
					});
							
					for(var j=1; j<=numOfImg(document.getElementsByTagName('img')); j++)
					{
						var ctntabNth = $('#ctntab' + j + '_new').attr('id');
						
						if(($('#'+ctntabNth).is(':visible')) && (ctntabNth!='ctn'+curTab))
						{
							if($('#tab'+j+'_new').attr('src').indexOf('on') != -1) 
							{
								src_link = 'corner_img/new_tabs/tab'+j+'_off_new.png';
								if($('#tab'+j+'_new').attr('src').indexOf('../') != -1) {
									src_link = '../corner_img/new_tabs/tab'+j+'_off_new.png';
								}
								$('#tab'+j+'_new').attr('src', src_link);
								$('#'+ctntabNth).hide();
							} 
						}
					}
					
					
				
				}, 
				function() { // mouseout 
					
						$('#ctn'+curTab).bind('mouseover',function() {
							$('#'+curTab).attr('src' , $('#'+curTab).attr('src').replace('off','on'));	
							$('#ctn'+curTab).show();
						});	
					
						$('#ctn'+curTab).bind('mouseout',function() {
							$('#'+curTab).attr('src' , $('#'+curTab).attr('src').replace('on','off'));	
							$('#ctn'+curTab).hide();
						});	
					
					//if(this.parentNode.nodeName == 'A') this.parentNode.removeAttribute('href'); //remove attribute href, cause javascript error
					$(this).bind('click',function() {
						clickTab(curTab, $('#'+curTab).attr('src'));
					});
				}); 
		});
		
		$(function() {
			$('.tabOff').hover(	function() {},function() {
				$(this).hide();
			
			}); 
		});	
	});
	
	function clickTab(currntTab, curTabImg) {
				
		if($('#'+currntTab).attr('src').indexOf('on') != -1)
		{
			$('#'+currntTab).attr('src' , curTabImg.replace('on','off'));	
			//$('#ctn'+currntTab).hide();
		} 
		else 
		{
			$('#'+currntTab).attr('src' , curTabImg.replace('off','on'));	
			//$('#ctn'+currntTab).show();
		}
		$('#ctn'+currntTab).toggle();	
	}
	
	function numOfImg(imgElement) {
		var count = 0;
		for(var k=0; k<imgElement.length; k++)
		{
			if(imgElement[k].className == 'tabBtn')
			{
				count++;
			}
		}
		
		return count;
	}
	
	function changePosition(currntTab){
		if(currntTab){
			/*
			if(currntTab.indexOf('11_new')!=-1)  $('#ctn'+currntTab).attr('style',"top: 150px;");
			else if(currntTab.indexOf('12_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 318px;");
			else if(currntTab.indexOf('2_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 28px;");
			else if(currntTab.indexOf('3_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 58px;");
			else if(currntTab.indexOf('4_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 86px;");
			else if(currntTab.indexOf('5_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 117px;");
			else if(currntTab.indexOf('6_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 145px;");
			else if(currntTab.indexOf('7_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 174px;");
			else if(currntTab.indexOf('8_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 203px;");
			else if(currntTab.indexOf('9_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 232px;");
			else if(currntTab.indexOf('10_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 261px;");
			else if(currntTab.indexOf('1_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 0px;");
			*/
			if(currntTab.indexOf('11_new')!=-1)  $('#ctn'+currntTab).attr('style',"top: 140px;");
			else if(currntTab.indexOf('12_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 318px;");
			else if(currntTab.indexOf('2_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 145px;");
			else if(currntTab.indexOf('3_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 174px");
			else if(currntTab.indexOf('4_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 203px;");
			else if(currntTab.indexOf('5_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 232px;;");
			else if(currntTab.indexOf('6_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 28px");
			else if(currntTab.indexOf('7_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 58px;;");
			else if(currntTab.indexOf('8_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 86px");
			else if(currntTab.indexOf('9_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 117px");
			else if(currntTab.indexOf('10_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 261px;");
			else if(currntTab.indexOf('1_new')!=-1) $('#ctn'+currntTab).attr('style',"top: 0px;");
		}	
	}


var setMenDefualtObj = '';
function setMenu(i){
		changePosition($('#tab'+i).attr('id'));
		
		$('#ctntab'+i).toggle(500);
		
		var currentImg = $('#tab'+i).attr('src');
		$('#tab'+i).attr('src', $('#tab'+i).attr('hover'));
		$('#tab'+i).attr('hover', currentImg);
		setMenDefualtObj = $('#tab'+i);
}


function showMore(report){
	if ($("#mcopy"+report).is(':visible')) {
		closeReport(report);
	} else{
		$("#mlink"+report).hide();
		$("#mcopy"+report).show();
		$("#close"+report).show();
		$("#cta"+report).show(500);
		$("#prod"+report).removeClass("prod").addClass("prodon");
	}
}

function closeReport(report){
	$("#mlink"+report).show();
	$("#mcopy"+report).hide();
	$("#close"+report).hide();
	$("#cta"+report).hide(500);
	$("#prod"+report).removeClass("prodon").addClass("prod");
}



//added by camper 11-17-08
function sub_menu(ahref_id,ulist_id){
	var ulist = document.getElementById(ulist_id)
	if(ulist.style.display =="block"){
		$('#'+ulist_id).toggle(100);	
		ulist.style.display = "none";
		ahref_id.style.textDecoration="underline";
	}else {
		$('#'+ulist_id).toggle(500);	
		ahref_id.style.textDecoration="none";
		ulist.style.display ="block";
	}
}


function goto_SamePage(given_link){
	var browser=navigator.appName;

	if(browser=="Microsoft Internet Explorer"){
		window.location.href(given_link);
	}else {
		window.location = given_link;
	}

}



/* topmenu script */
function setTopMenu(menu){
	window.frames.iframeTopMenu.setDefault(menu);
}

function setTopMenu(menu, bannerFlag){
	
	window.frames.iframeTopMenu.setDefaultParams(menu, bannerFlag);
}


var htmlEncode = function (source, display, tabs) {
	var i, s, ch, peek, line, result,
		next, endline, push,
		spaces;
	
	// Stash the next character and advance the pointer
	next = function () {
		peek = source.charAt(i);
		i += 1;
	};
	
	// Start a new "line" of output, to be joined later by <br />
	endline = function () {
		line = line.join('');
		if (display) {
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			line = line.replace(/(^ )|( $)/g, '&nbsp;');
		}
		result.push(line);
		line = [];
	};
	
	// Push a character or its entity onto the current line
	push = function () {
		if (ch < ' ' || ch > '~') {
			line.push('&#' + ch.charCodeAt(0) + ';');
		} else {
			line.push(ch);
		}
	};
	
	// Use only integer part of tabs, and default to 4
	tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
	
	result = [];
	line = [];

	i = 0;
	next();
	while (i <= source.length) { // less than or equal, because i is always one ahead
		ch = peek;
		next();
		
		// HTML special chars.
		switch (ch) {
		case '<':
			line.push('&lt;');
			break;
		case '>':
			line.push('&gt;');
			break;
		case '&':
			line.push('&amp;');
			break;
		case '"':
			line.push('&quot;');
			break;
		case "'":
			line.push('&#39;');
			break;
		default:
			// If the output is intended for display,
			// then end lines on newlines, and replace tabs with spaces.
			if (display) {
				switch (ch) {
				case '\r':
					// If this \r is the beginning of a \r\n, skip over the \n part.
					if (peek === '\n') {
						next();
					}
					endline();
					break;
				case '\n':
					endline();
					break;
				case '\t':
					// expand tabs
					spaces = tabs - (line.length % tabs);
					for (s = 0; s < spaces; s += 1) {
						line.push(' ');
					}
					break;
				default:
					// All other characters can be dealt with generically.
					push();
				}
			} else {
				// If the output is not for display,
				// then none of the characters need special treatment.
				push();
			}
		}
	}
	endline();
	
	// If you can't beat 'em, join 'em.
	result = result.join('<br />');

	if (display) {
		// Break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/ {2}/g, ' &nbsp;');
	}
	
	// tada!
	return result;
}
/* topmenu script */



function validateEmail(v)
{
    if(!IsEmailValid(ltrim(document.getElementById(v).value)))
    {
        return "Please enter a valid email address.";
    } 
    return "";
}

function ltrim(str) {
    logme(str);
    return str.replace(/^\s+/g, '');
}

function validateFields(va)
{
    var indicator = "&nbsp;<image src=\"corner_img/asterisk.png\"/>";
    var i;
    for (i = 0; i < va.length; ++i)
    {
        document.getElementById(va[i][0]).nextSibling.innerHTML = "";
    }
    for (i= 0; i < va.length; ++i)
    {
        logme(va[i][0]);
        if (ltrim(document.getElementById(va[i][0]).value) == "")
        {
            document.getElementById(va[i][0]).nextSibling.innerHTML = indicator;
            return va[i][1];
        }
        if (va[i][2] != null)
        {
            var msg = va[i][2](va[i][0]);
            if (msg != "") 
            {
                document.getElementById(va[i][0]).nextSibling.innerHTML = indicator;
                return msg;
            }
        }
    }
    return "";
}

var logme = function(x)
{
    if (typeof(console) != 'undefined')
    {
        console.log(x);
    }
}


function submitEmailNew(container, bindataID, onSuccessFN)
{
    var createUploadForm = function(id, fileElementId, data)
    {
        //create form	
        var formId = 'jUploadForm' + id;
        var fileId = 'jUploadFile' + id;
        
        var eForm = '<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>';
        
        var form = $(eForm);	
        if(data)
        {
            for(var i in data)
            {
                $('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);
            }			
        }		
        $('<input type="hidden" name="fuck" value="ouch" />').appendTo(form);
        var oldElement = $('#' + fileElementId);
        logme("OLD ELEMENT "+oldElement);
        var newElement = $(oldElement).clone();
        $(oldElement).attr('id', fileId);
        $(oldElement).before(newElement);
        $(oldElement).appendTo(form);


        
        //set attributes
        $(form).css('position', 'absolute');
        $(form).css('top', '-1200px');
        $(form).css('left', '-1200px');
        $(form).appendTo('body');		
        return form;
    }


    var createUploadIframe = function(id, uri)
    {
            //create frame
            var frameId = 'jUploadFrame' + id;
            var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';
            if(window.ActiveXObject)
            {
                if(typeof uri== 'boolean'){
                    iframeHtml += ' src="' + 'javascript:false' + '"';

                }
                else if(typeof uri== 'string'){
                    iframeHtml += ' src="' + uri + '"';

                }	
            }
            iframeHtml += ' />';
            jQuery(iframeHtml).appendTo(document.body);

            return jQuery('#' + frameId).get(0);			
    }

    var id = new Date().getTime();
    logme("ID "+id);
    var frame = createUploadIframe(id, false);
    logme(frame);
    var frameId = 'jUploadFrame' + id;




    var form = createUploadForm(id, bindataID, container)
    logme(form);


    jQuery(form).attr('action', "mail_generic_2.php");
    jQuery(form).attr('method', 'POST');
    jQuery(form).attr('target', frameId);
    jQuery(form).attr('encoding', 'multipart/form-data');      			
    jQuery(form).submit();
    
    logme("submitted");
    
    logme("loading the form");
    
    var uploadCallback = function(v)
    {
        $.unblockUI();
        logme("doc loaded "+frameId);
        var io = document.getElementById(frameId);
        logme(io);
        logme(io.contentWindow);
         var responset = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
         var response = eval("(" + responset + ")");
         logme(response);
         logme(response["error"]);
         logme(response.error);
         if (response.error != 0)
         {
            alert(response.msg);
            return;
         }
         onSuccessFN();
    }
    
    $('#' + frameId).load(uploadCallback);
    $.blockUI();

}


function onFormFieldError(fieldid, focusid, msg)
{
    document.getElementById(fieldid).nextSibling.innerHTML = "<p style='color:red'>"+msg+"</p>";
    document.getElementById(focusid).focus();
}


function checkAtLeastOneBox(msgid, arr)
{
    var divid = arr[0];
    var msg = arr[1]
    var boxes = $("div.#"+divid+" input");
    logme(boxes);
    checked = false;
    firstbox = "";
    boxes.each(
        function(idx, el)
        {
            if (firstbox == "") firstbox = $(el).attr("id");
            if ($(el).attr("checked")) checked = true;
        }
    );
    logme(checked);
    logme(firstbox);
    logme(msgid);
    if (!checked && firstbox != "")
    {
        onFormFieldError(msgid, firstbox, msg);
        return msg;
    }
    return "";
}

function validateFields2(va)
{
    var i;
    for (i = 0; i < va.length; ++i)
    {
        var tp = typeof(va[i][0]);
        if (tp == "string")
        {
            document.getElementById(va[i][0]).nextSibling.innerHTML = "";
        }
        else
            document.getElementById(va[i][1]).nextSibling.innerHTML = "";
        
    }
    for (i= 0; i < va.length; ++i)
    {
        logme("XYYY "+i);
        var tp = typeof(va[i][0]);
        logme(i);
        logme(tp);
        if (tp == "function")
        {
            // allows direct functin check
            // 
            msg = va[i][0](va[i][1], va[i][2]);
            if (msg != 0)
            {
                return msg;
            }
        }
        else
        {

            if (ltrim(document.getElementById(va[i][0]).value) == "")
            {
                var err = 1;
                // double check hack for IE8's select and dropdowns
                try
                {
                    var qd = $("#"+va[i][0]);
                    if (qd.val() != "")
                    {
                        err = 0;
                    }
                }
                catch(err)
                {
                    // do nothing -- err will be 1
                }
                if (err == 1)
                {
                    onFormFieldError(va[i][0], va[i][0], va[i][1]);
                    return va[i][1];
                }
            }
            if (va[i][2] != null)
            {
                var msg = va[i][2](va[i][0]);
                if (msg != "") 
                {
                    onFormFieldError(va[i][0], va[i][0], msg);
                    return msg;
                }
            }
        }
    }
    return "";
}



