// TPP JavaScript Document Main - © 2006 Phamily Business Entertainment

//rollover scripts
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
return;
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//show-hide layers scripts
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//popup new browser script
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//reloads the window if Nav4 resized
function MM_reloadPage(init) {  
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//NLHN Affiliates DDL redirect
function makeLinkTo(s) {window.top.location.href = s.options[s.selectedIndex].value; }

//redirect on click script
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//set text of status bar on event script
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

//set text of text field
function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

//NLHN Jump Menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// for main nav
	
function elemHighlight(e) {
	if(! e) return;
		
	e.style.backgroundColor="#607F94";
	e.style.cursor = "hand";		
}

function elemRestore(e) {
	if(! e) return;
	e.style.backgroundColor="#889FAF";
	e.style.backgroundColor="black";
}

function elemGo(e, strLink) {
	if(! e) return;
	e.style.cursor = "wait";
	if(strLink !=null && strLink !='') window.location.href=strLink;
}

// for sub nav
	
function elemSubHighlight(e) {
	if(! e) return;
		
	e.style.backgroundColor="#607F94";
	e.style.cursor = "hand";		
}

function elemSubRestore(e) {
	if(! e) return;
	e.style.backgroundColor="#889FAF";
	e.style.backgroundColor="#889FAF";
}

function elemSubGo(e, strLink) {
	if(! e) return;
	e.style.cursor = "wait";
	if(strLink !=null && strLink !='') window.location.href=strLink;
}
	
// for features links
function dvHighlight(e) {
	if(! e) return;
	e.style.backgroundColor="#607F94";
	e.style.cursor = "hand";
}

function dvHighlightGreen(e) {
	if(! e) return;
	e.style.backgroundColor="#45764a";
	e.style.cursor = "hand";
}

function dvHighlightFrontWhite(e) {
	if(! e) return;
	e.style.backgroundColor="#ffffff";
	e.style.cursor = "hand";
}
function dvHighlightFrontBlue(e) {
	if(! e) return;
	e.style.backgroundColor="#BFCED8";
	e.style.cursor = "hand";
}

function dvRestore(e) {
	if(! e) return;
	e.style.backgroundColor="#889FAF";
	
}

function dvRestoreGreen(e) {
	if(! e) return;
	e.style.backgroundColor="#57955E";
	
}

function dvRestoreFrontWhite(e) {
	if(! e) return;
	e.style.backgroundColor="#FFFFFF";
	
}
function dvRestoreFrontBlue(e) {
	if(! e) return;
	e.style.backgroundColor="#BFCED8";
	
}
function dvGo(e, strLink) {
	e.style.cursor = "wait";
	if(strLink !=null && strLink !='') window.location.href=strLink;
}

function setCommentDelete(iCommentID) {  
     var elem = document.getElementById("arrCommentID"); 
     var img = document.getElementById("imgDelete"+ iCommentID);
     
     imgOn = "images/templateElements/cnf.gif";
     imgOff = "images/templateElements/del.gif";
     
     strFile = img.src.substring(img.src.length-7, img.src.length);
         
	 if(!elem || !img) return; 
          
     if (strFile=="cnf.gif") {
			elem.value = elem.value.replace('|' + iCommentID + '|', '');
			elem.value = elem.value.replace(',,', ','); 
	 } else {
			elem.value += '|' + iCommentID + '|,';
	 }
	 
	 if(elem.value.substring(1) == ",") elem.value = elem.value.substring(2, elem.value.length);
	 if(elem.value.substring(elem.value.length) == ",") elem.value = elem.value.substring(1, elem.value.length-1);
	 
	 img.src = (strFile=="del.gif") ? imgOn : imgOff; 
}  


function jumpPage(strPage,strQueryString) {
	var strScriptName = strPage;
	window.location.href=strScriptName + "?" + strQueryString;
}

function emailAFriend(strRef)
{ 
	day = new Date();
	id = day.getTime();
	var str="toolbar=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=420,width=500"
	eval("emailAFriend" + id + " = window.open(strRef, '" + id + "', str);");
}

// login functions

function checkLogin(objForm) {
	var objValidatorUsername = document.getElementById("rfvUsername");
	var objValidatorPassword = document.getElementById("rfvPassword");
	
	objValidatorUsername.style.display = "none";
	objValidatorPassword.style.display = "none";
	
	var objUsername = objForm.username;
	var objPassword = objForm.password;
	
	if(! objUsername || ! objPassword) return false; 
	
	if(objUsername.value.length < 5) return fireValidator(objValidatorUsername);
	if(objPassword.value.length < 5) return fireValidator(objValidatorPassword);
	
	return true;
}
function checkRegistrationForm1(objForm) {
	var objValidatorEmail = document.getElementById("rfvEmail");
	var objValidatorUsername = document.getElementById("rfvUsername");
	var objValidatorFullName = document.getElementById("rfvFullName");
	var objValidatorPassword = document.getElementById("rfvPassword");
	var objValidatorPasswordCheck = document.getElementById("rfvPasswordCheck");
	var objValidatorCity = document.getElementById("rfvCity");
	var objValidatorStateProvince = document.getElementById("rfvStateProvince");
	var objValidatorCountry = document.getElementById("rfvCountry");
	var objValidatorPostalCode = document.getElementById("rfvPostalCode");
	var objValidatorTerms = document.getElementById("rfvTerms");
	var objValidatorPhoto = document.getElementById("rfvPhoto");
	
	var objValidatorErrors = document.getElementById("rfvErrors");
	
	objValidatorEmail.style.display = "none";
	objValidatorUsername.style.display = "none";
	objValidatorFullName.style.display = "none";
	objValidatorPassword.style.display = "none";
	objValidatorPasswordCheck.style.display = "none";
	objValidatorCity.style.display = "none";
	objValidatorStateProvince.style.display = "none";
	objValidatorCountry.style.display = "none";
	objValidatorPostalCode.style.display = "none";
	objValidatorTerms.style.display = "none";	
	objValidatorPhoto.style.display = "none";
	objValidatorErrors.style.display = "none";
	
	var objEmail = objForm.Email;
	var objUsername = objForm.Username;
	var objFullName = objForm.FullName;
	var objPassword = objForm.Password;
	var objPasswordCheck = objForm.Password2;
	var objCity = objForm.City;
	var objStateProvince = objForm.StateProvince;
	var objCountry = objForm.Country;
	var objPostalCode = objForm.PostalCode;
	var objTerms = objForm.Terms;
	var objFile = objForm.Photo;
	
	if(! objEmail || ! objUsername) return false; 
	
	var bIsError = false; 
	
	if(objEmail.value.length < 5) bIsError = fireValidator(objValidatorEmail);
	if(objUsername.value.length < 5 || objUsername.value.length > 25) bIsError = fireValidator(objValidatorUsername);
	if(objFullName.value.length < 1) bIsError = fireValidator(objValidatorFullName);
	if(objPassword.value.length < 5 || objPassword.value.length > 25) bIsError = fireValidator(objValidatorPassword);
	if(objPassword.value != objPasswordCheck.value) bIsError = fireValidator(objValidatorPasswordCheck);
	if(objCity.value.length < 1) bIsError = fireValidator(objValidatorCity);
	if(objStateProvince.value.length < 1) bIsError = fireValidator(objValidatorStateProvince);
	if(objCountry.value.length < 1) bIsError = fireValidator(objValidatorCountry);
	if(objPostalCode.value.length < 1) bIsError = fireValidator(objValidatorPostalCode);
	if(! objTerms.checked) bIsError = fireValidator(objValidatorTerms);
	
	if(! isValidImage(objFile.value) ) bIsError = fireValidator(objValidatorPhoto);
	
	if(bIsError) return false; 
	
	return true;
}

function checkManageAccountForm(objForm) {
	var objValidatorFullName = document.getElementById("rfvFullName");
	var objValidatorPassword = document.getElementById("rfvPassword");
	var objValidatorPasswordCheck = document.getElementById("rfvPasswordCheck");
	var objValidatorCity = document.getElementById("rfvCity");
	var objValidatorStateProvince = document.getElementById("rfvStateProvince");
	var objValidatorCountry = document.getElementById("rfvCountry");
	var objValidatorPostalCode = document.getElementById("rfvPostalCode");
		
	var objValidatorErrors = document.getElementById("rfvErrors");
	
	objValidatorFullName.style.display = "none";
	objValidatorPassword.style.display = "none";
	objValidatorPasswordCheck.style.display = "none";
	objValidatorCity.style.display = "none";
	objValidatorStateProvince.style.display = "none";
	objValidatorCountry.style.display = "none";
	objValidatorPostalCode.style.display = "none";
	objValidatorErrors.style.display = "none";
	
	var objFullName = objForm.FullName;
	var objPassword = objForm.Password;
	var objPasswordCheck = objForm.Password2;
	var objCity = objForm.City;
	var objStateProvince = objForm.StateProvince;
	var objCountry = objForm.Country;
	var objPostalCode = objForm.PostalCode;
	
	var bIsError = false; 
	
	
	
	if(objFullName.value.length < 1) bIsError = fireValidator(objValidatorFullName);
	if(objPassword.value.length < 5 || objPassword.value.length > 25) bIsError = fireValidator(objValidatorPassword);
	if(objPassword.value != objPasswordCheck.value) bIsError = fireValidator(objValidatorPasswordCheck);
	if(objCity.value.length < 1) bIsError = fireValidator(objValidatorCity);
	if(objStateProvince.value.length < 1) bIsError = fireValidator(objValidatorStateProvince);
	if(objCountry.value.length < 1) bIsError = fireValidator(objValidatorCountry);
	if(objPostalCode.value.length < 1) bIsError = fireValidator(objValidatorPostalCode);
		
	if(bIsError) return false; 
	
	return true;
}
function isValidImage(file) {
	allowSubmit = false;
	extArray = new Array(".gif", ".jpeg", ".jpg", ".png");
	if (!file) allowSubmit = true;
	while (file.indexOf("\\") != -1) {
		file = file.slice(file.indexOf("\\") + 1);
		ext = file.slice(file.indexOf(".")).toLowerCase();
	
		for (var i = 0; i < extArray.length; i++) {
			if (extArray[i] == ext) { allowSubmit = true; break; }
		}
	}
	return allowSubmit;
}


function checkCommentForm(objForm)
 {        
	var objValidatorTitle = document.getElementById("rfvCommentTitle");
	var objValidatorComment = document.getElementById("rfvCommentComment");
	
	objValidatorTitle.style.display = "none";
	objValidatorComment.style.display = "none";
	
	var objTitle = objForm.CommentTitle;
	var objComment = objForm.CommentComment;
	
	var bIsError = false;
	
	if(! objTitle || ! objComment) return false; 
	
	if(objTitle.value.length < 1)  bIsError = fireValidator(objValidatorTitle);
	if(objComment.value.length < 1)  bIsError = fireValidator(objValidatorComment);
	
	if(bIsError) return false; 
	
	return true;
}

function checkSearchForm(objForm)
 {        
	var objValidatorSearchText = document.getElementById("rfvSearchText");
	var objValidatorSearchTextType = document.getElementById("rfvSearchTextType");

	objValidatorSearchText.style.display = "none";
	objValidatorSearchTextType.style.display = "none";
		
	var objSearchText = objForm.SearchText;
		
	var bIsError = false;
	
	if(! objSearchText) return false; 
	
	if(objSearchText.value.length < 2)  bIsError = fireValidator(objValidatorSearchText);
	if(objSearchText.value.toLowerCase() =="the") bIsError = fireValidator(objValidatorSearchTextType);
		
	if(bIsError) return false; 
	
	return true;
}

function fireValidator(objValidator) {
	if(objValidator) objValidator.style.display = "block";
	
	var objValidatorErrors = document.getElementById("rfvErrors");
	if (objValidatorErrors) objValidatorErrors.style.display = "block";
	
	return true;
}

function doLogout(strPage) {
	if(confirm("Continue logging out?")) window.location.href="logout.asp?r=" + strPage;
}

function skipSurvey() {
	if(confirm("Skip the survey and forgo the 10,000 points?")) {
		window.location.href="membersignup3.asp";
	}
}

function togglePhotoEditor() {
	var dvPhotoPreview = document.getElementById("dvPhotoPreview");
	var dvPhotoEdit = document.getElementById("dvPhotoEdit");
	
	dvPhotoPreview.style.display = dvPhotoPreview.style.display == "block" ? "none" : "block";
	dvPhotoEdit.style.display = dvPhotoEdit.style.display == "block" ? "none" : "block";
}
