// +++++++++++  START MAIN NAVIGATION ++++++++++++

//home page

//Initialize Main Menu OnLoad
function setNavigation(section, page) {
	glb_section = "sub-nav-" + section;
	var x = document.getElementById(section);
	if(x){
		YAHOO.util.Dom.removeClass( x, x.getAttribute("offClass"));
		YAHOO.util.Dom.addClass( x, x.getAttribute("onClass")); 
		ShowDiv(onele = "sub-nav-" + section);
		var ele = document.getElementById(page);
		ele.className='sub-nav-selected';
	}
}

//initialize main menu
if(typeof header_init == 'function') { 
	YAHOO.util.Event.onDOMReady(header_init);
}


//stroll back to original selection
gbl_stroll_back = 0;
function menu_stroll_back(id){
	var stroll_back = function() { 
		var NewMainNav = document.getElementById(glb_section).getAttribute("sectionname");
		var OldMainNav = document.getElementById(id).getAttribute("sectionname");
		if (OldMainNav == null){
			//activated from main nav button (td)
			HideDiv("sub-nav-" + id); 
			ShowDiv(glb_section);
			setMainButtonOn(document.getElementById(glb_section).getAttribute("sectionname"));
			//alert(glb_section);
			//alert(id);
			setMainButtonOff(id);	
		}else{
			//activated from sub menu
			HideDiv(id); 
			ShowDiv(glb_section);
			setMainButtonOff(OldMainNav);
			setMainButtonOn(NewMainNav);
		}
	};
	gbl_stroll_back = setTimeout(stroll_back, 2200);
}
 
//set main nav button on
function setMainButtonOn(id) {
	var x = document.getElementById(id);
	if(x){
		YAHOO.util.Dom.removeClass( x, x.getAttribute("offClass"));
		YAHOO.util.Dom.addClass( x, x.getAttribute("onClass")); 
	}
}

//set main nav button off
function setMainButtonOff(id) {
	var x = document.getElementById(id);
	if(x){
		YAHOO.util.Dom.addClass( x, x.getAttribute("offClass"));
		YAHOO.util.Dom.removeClass( x, x.getAttribute("onClass")); 
	}
}

//set sub nav button off
function subNavOnMouseOut(id){
	clearTimeout(gbl_stroll_back);
	//if last selection is not equal to reset selection
	if(id != glb_section){
		getResetButton = document.getElementById(glb_section).getAttribute("sectionname");
		getCurrentButton = document.getElementById(id).getAttribute("sectionname");
		menu_stroll_back(id);
	}

}

//main nav button mouse out
function NavOnMouseOver(id){
	clearTimeout(gbl_stroll_back);
	//turn on button
	setMainButtonOn(id);
	//turn off buttons
	var arLen=gbl_subsections.length;
	for ( var i=0, len=arLen; i<len; ++i ){
		if(gbl_subsections[i] != id){
			//alert(gbl_subsections[i]);
			setMainButtonOff(gbl_subsections[i]);
		}
	}
	var subNav = "sub-nav-" + id;
	//turn off other subnavs
	var arLen=gbl_subsections.length;
	for ( var i=0, len=arLen; i<len; ++i ){
		var offele = "sub-nav-" + gbl_subsections[i];
		if(offele != subNav){
			//alert(offele);
			HideDiv(offele);
		}
	}	
	//turn on subnav
	ShowDiv(subNav);
	
}



function ShowDiv(DivName)
{
 elem = document.getElementById(DivName);
	 if(elem){
		 elem.style.display = "block";
	 }
}

function HideDiv(DivName)
{ 
 elem = document.getElementById(DivName);
	 if(elem){
		elem.style.display = "none";
	 }
}

function NavOnMouseOut(id){
	menu_stroll_back(id);
}



// +++++++++++  END MAIN NAVIGATION ++++++++++++


function switchNewsTabs(switchTo){	
	// content section
	var indNewsBox = document.getElementById("industrynews-box-content");
	var NewsBox = document.getElementById("news-box-content");
	// tabs
	var indNewsTab = document.getElementById("industrynews-box-tab");
	var NewsTab = document.getElementById("news-box-tab");
	// new bottom
	var NewsBottom = document.getElementById("news-box-bottom");
	var indNewsBottom = document.getElementById("industrynews-box-bottom");
	
	if( switchTo == 'news'){
		YAHOO.util.Dom.removeClass(NewsBox, "fse-hidden");
		YAHOO.util.Dom.removeClass(NewsBottom, "fse-hidden");
		YAHOO.util.Dom.addClass(NewsTab, "selected");
		YAHOO.util.Dom.addClass(indNewsBox, "fse-hidden");	
		YAHOO.util.Dom.removeClass(indNewsTab, "selected");	
		YAHOO.util.Dom.addClass(indNewsBottom, "fse-hidden");
	}else{
		YAHOO.util.Dom.removeClass(indNewsBox, "fse-hidden");
		YAHOO.util.Dom.addClass(indNewsTab, "selected");
		YAHOO.util.Dom.addClass(NewsBox, "fse-hidden");	
		YAHOO.util.Dom.removeClass(NewsTab, "selected");	
		YAHOO.util.Dom.addClass(NewsBottom, "fse-hidden");
		YAHOO.util.Dom.removeClass(indNewsBottom, "fse-hidden");
	}
}

/* ****************************************************** */
/*         COMMON FUNCTIONS
/* ****************************************************** */


function exit(appURL,msg){	
	//msg = ' Are you sure you wish to Cancel your registration?	';
	if(confirm(msg)){
		window.location= appURL + '/index.cfm';
	}
	
}
//JS Trim Function - Pass it Text and Minimum String length
function Ck4Spaces(txt,minlength) {
	chkKeyword = txt.replace(/\s+$/gi, "");
	chkKeyword = chkKeyword.replace(/^\s/gi, "");
	if(chkKeyword.length<minlength){
		return false;		
	}
}

function chkPasswords(){
	var email  = document.frm_register.email;
	var email2 = document.frm_register.email2;
	if (email.value!= email2.value){
		alert("The email and confirmation email addresses do not match. Please re-enter your email address.	")
		email.value=""
		email2.value=""
		email.focus()
		return false;
	}

	var pswrd  = document.frm_register.password;
	var pswrd2 = document.frm_register.password2;
	if (pswrd.value!= pswrd2.value){
		alert("Please re-type your password to verify that you entered it correctly.")
		pswrd.value=""
		pswrd2.value=""
		pswrd.focus()
		return false;
	}
	return true;
}

function selectOther(selectVal){
	var ele = document.getElementById('other');
	var tr_ele = document.getElementById('tr_other');
	if(selectVal==0){
		ele.disabled=false;
		tr_ele.style.display='block';
	}else{
		ele.disabled=true;
		tr_ele.style.display='none';
	}
}




//use this to get the text within the FCK editor to validate
function getFCK_editor_text(inName){
	var oEditor = FCKeditorAPI.GetInstance(inName);
	var oDOM = oEditor.EditorDocument;
	var strFCKEditorText = "";
	if (document.all)// If I.E.
	{
	strFCKEditorText = oDOM.body.innerText;
	}
	else 
	{
	var r = oDOM.createRange();
	r.selectNodeContents(oDOM.body);
	strFCKEditorText = r.toString();
	}
	return strFCKEditorText;
} 


/*
	OnChange="setCompany();"
	function setCompany(){
		selection = document.getElementById("operationType");
		alert(selection);

		if ( selection.value == 'None' ){
			company = document.getElementById("Company");
			company.value = selection.value;
		}
	}
*/

/* ****************************************************** */
/*                  Content Submission Section
/* ****************************************************** */

function content_upl_type(on, off1, off2){
	document.getElementById(off1).style.display="none";
	document.getElementById(off2).style.display="none";
	document.getElementById(on).style.display="block";
}

//display correct form on page load (if needed);
if(typeof initialize_form == 'function') { 
	YAHOO.util.Event.onDOMReady(initialize_form);
}

function validateEditor_Event(){
	var x = getFCK_editor_text('eventtext');
	if(Ck4Spaces(x,1)==false){
		alert('Please enter the Event Detail.	');
		return false
	}else{ 
		return true;
	}
}
function validateEditor_News(){
	var x = getFCK_editor_text('newstext');
	if(Ck4Spaces(x,1)==false){
		alert('Please enter the News Detail.	');
		return false
	}else{ 
		return true;
	}
}

/*
if(typeof header_init == 'function') { 
	YAHOO.util.Event.onDOMReady(header_init);
}
*/

//sponsor profile popup
function SponsorWebsite(URL,target) {
	//,width=#attributes.width#,height=#attributes.height#,left=#attributes.frmLeft#,top=#attributes.frmTop#
	if(target != '_self'){
		day = new Date();
		id = day.getTime();
		var windowprops = "toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1";
		eval("page" + id + " = window.open(URL, '" + id + "', windowprops);");
	}else{
		window.location = URL;	
	}
}

function popUpWindow(URL,width,height) {
	day = new Date();
	id = day.getTime();
	var windowprops = "toolbar=0,location=0,directories=0,status=0, " +"menubar=0,scrollbars=1,resizable=1,width=" + width + ",height=" + height + ",left=0,top=0";
	eval("page" + id + " = window.open(URL, '" + id + "', windowprops);");
}

//============  CLASSIFIED POST SUBMISSION VALIDATION ==============================*//

function resetClassifiedForm(){
	myForm = document.frm_classifieds;
	myForm.keyword.value='';
	myForm.cid.selectedIndex=0;
	myForm.submit();
}

function dspListingType(val){
	var n = val.indexOf('|');
	var x = val.substr(n+1,val.length);
	var	x = x.toUpperCase();
	var myEle = document.getElementById('dealType');
	var myFormEle = document.frm_postad.dealType;
	//if(x=='NEW'){myEle.style.display='block';myFormEle.disabled=false;}else{myEle.style.display='none';myFormEle.disabled=true;}
	if(x=='NEW'){myFormEle.disabled=false;myFormEle.selectedIndex=0;}else{myFormEle.disabled=true;myFormEle.selectedIndex=-1;}
}

function Agree2Terms(){
	myForm = document.frm_postad_disclaimer;
	if(myForm.agreetoTerms.checked==false){
		alert('Please click the checkbox to Agree to the Terms or click Cancel.	');
		return false;
	}else{
		myForm.submit();
	}

}


//*============ REGISTRATION============ *//
function selectDstType(groupid){
	var url = 'ajax/ajx_getDistributors.cfm?groupid=' + groupid;
	Fse.Ajax.updateContent( url, 'ajx_results' ,'')	
};


//*============ LRW Events ============ *//
function LRW_Events(id){
	var myLink = 'includes/inc_disp_paypal_product_dtl.cfm?id=' + id;
	Fse.DialogManager.show('lrwDialog',{src:myLink});
}