
//////////////////////////////////////////////////////////////////
// ManovrareSoft Software Solutions 							//
// Copies can not be made without written consent of 			//
// the author Mark Badaracco or being soley employed by 		//
// PageBusters Development Broup however, modifications  		//
// can be made without permission								//
// Any questions or concerns can by addressed by sending an 	//
// Email to Mark.Badaracco@PageBusters.com						//	
//																//
//																//
// General Javascript											//
// Site Administrator v4										//
//////////////////////////////////////////////////////////////////

var url = location.href;
var addon = "";
if(url.search(/admin/i) > 0)
	addon = "../";

function fancyCall()
{
	$('.fancybox').fancybox({ 
		'href'			: 	this.href, 
		'width' 		: 	'98%', 
		'height' 		: 	'98%', 
		'autoScale' 	: 	false, 
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	500, 
		'type' 			: 	'iframe' 
	});	
}


function toggleOffCheck(objCheck, blnCondtion, strIDToToggle, type)
{
	alert("WARNING: When checked, the application will place " + type + " above column 2's content.");
}
       
function openUploadWindow(windowName, elToFill)
{
	window.open('UploadForm.php?elToFill='+elToFill,windowName,'width=450,height=350');
}    

function returnValueToSelect(sValue, sText, objToFill)
{
	var arr = objToFill.split("~");
	var lngth = (arr.length-1);
	for (i=0;i<=lngth;i++)
	{
		myEl = document.getElementById(arr[i]);
		selVal = myEl.options.selectedIndex;
		lgth = myEl.options.length;
		myEl.options[lgth] = new Option(sText, sValue);
		myEl.value = sValue;
		
		if (i==0)
		{
			myEl.options.selectedIndex = lgth;
		}
		else
		{
			myEl.selectedIndex = selVal;
		}
	}
}

function fireSiteSwitch(obj)
{
	var val = obj.options[obj.selectedIndex].value;
	var txt = obj.options[obj.selectedIndex].text;
	//ABasic("changeSite.php?SystemID="+val, null);
	AWait("changeSite.php?SystemID="+val, null)
	//alert("You are now editing " + txt + ".");
}

function fireFields(csvFields)
{
	if(null != csvFields && "" != csvFields)
	{
		var arrf = csvFields.split(",");
		var lngth = (arrf.length-1);
		for (i=0;i<=lngth;i++)
		{
			if(null != document.getElementById(arrf[i]))
			{
				if(null != document.getElementById(arrf[i]+'Sample'))
				{
					document.getElementById(arrf[i]+'Sample').style.backgroundColor = document.getElementById(arrf[i]).value;
				}
			}
		}
	}
}

function FireTemplateFields(optIndex)
{	
	//Check all the fields do exist
	if(null != document.getElementById("BigSiteHeaderHeight_"+optIndex))
	{
		var valBigHeightElment = document.getElementById("BigSiteHeaderHeight_"+optIndex).value;
	}
	if(null != document.getElementById("BigSiteHeaderWidth_"+optIndex))
	{
		var valBigWidthElment = document.getElementById("BigSiteHeaderWidth_"+optIndex).value;
	}
	if(null != document.getElementById("SmallSiteHeaderHeight_"+optIndex))
	{
		var valSmlHeightElment = document.getElementById("SmallSiteHeaderHeight_"+optIndex).value;
	}
	if(null != document.getElementById("SmallSiteHeaderWidth_"+optIndex))
	{
		var valSmlWidthElment = document.getElementById("SmallSiteHeaderWidth_"+optIndex).value;
	}
	
	//Set the height and widths
	if(null != valBigHeightElment && null != valBigWidthElment && (undefined != valBigHeightElment && undefined != valBigWidthElment))
	{
		if(null != valSmlHeightElment && null != valSmlWidthElment && (undefined != valSmlHeightElment && undefined != valSmlWidthElment))
		{
			document.getElementById("BigSiteHeader").innerHTML = "<u><b>Width<b>:</u> "+valBigWidthElment+" px<br/><u><b>Height<b>:</u> "+valBigHeightElment+" px";
			document.getElementById("SmallSiteHeader").innerHTML = "<u><b>Width<b>:</u> "+valSmlWidthElment+" px<br/><u><b>Height<b>:</u> "+valSmlHeightElment+" px";
		}
	}
	//Warn them to select a template
	else
	{
		document.getElementById("BigSiteHeader").innerHTML = "Please select a template.";
		document.getElementById("SmallSiteHeader").innerHTML = "Please select a template.";
	}
}

function GatherSelect(element)
{
	var output = "";
	for (var i=0;i < element.options.length;i++) 
	{
		if (element.options[i].selected) 
		{
			output += element.options[i].value + ',';
		}
	}
	document.myForm.SubNavIDs.value = output;
}

function P7_ExpMenu()
{
	//If this isn't Microsoft Internet Explorer
	//if(navigator.appVersion.indexOf("MSIE")==-1)
	//{
	//	//Leave
	//	return;
	//}
		
	var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';

	//Only will count up to ten
	for(i=0;i<10;i++)
		{
			//g is the menubar overall list
			g=document.getElementById(bv+nn);
			
			//Check to see if there is a menu bar here
			if(g)
				{
					//in this class lets get the array of List-Items
					lg = g.getElementsByTagName("LI");
					
					//If there is List-Items
					if(lg)
						{
							//How many are there, lets loop through them all
							for(k=0;k<lg.length;k++)
								{
									//dynamic function simulating the css active/hover on an LI (doesn't exist in IE)
									lg[k].onmouseover=function()
										{
											//Whats the name of the class
											c=this.className;
											//replace is with the class its supposed to be
											cl=(c)?c+' '+cs:cs;
											
											this.className=cl;
										};
										
									//dynamic function simulating the css off active/off hover on an LI (doesn't exist in IE)
									lg[k].onmouseout=function()
										{
											//Whats the name of the class
											c = this.className;
											
											//replace is with the class its supposed to be
											this.className=(c)?c.replace(r,''):'';
										};
								}
						}
				}
				
			nn=i+1;
			
		}
}
	
function CheckErrors()
{
	var daFrom = document.getElementById("myForm");
	var msg = "";
	
	if(null != daFrom)
	{
		msg += checkText("FirstName", "First name");
		msg += checkText("LastName", "Last name");
		msg += checkText("EmailAddress", "Email address");
		msg += checkText("PhoneNumber", "Phone number");
		msg += checkText("Debt", "Amount of debt");
	}
	else
		msg = "An unexpected error occured, please call the number to reach a representative.";	
	
	
	if(msg != "")
	{
		alert("Errors were detected on the form please correct and resubmit.\n\r\n\r" + msg);
		return false;
	}
	else
		return true;
}
	
function checkText(strElementID, strName)
{
	var el = document.getElementById(strElementID);
	if(null != el)
	{
		if(undefined != el.value)
		{
			switch(el.type)
			{
				case "text":
					if("" != el.value)
						return "";

					else
						return " - " + strName + " is a required field.\n\r";
				break;	
				
				case "select-one":
						
					if("" != el.selectedIndex > 0)
						return "";
					
					else
						return " - " + strName + " is a required field.\n\r";
				break;
				
				case "radio":
					if(!el)
						return "";
					var elLength = el.length;
					if(elLength == undefined)
					{
						if(!el.checked)
							return " - " + strName + " is a required field.\n\r";
						else
							return "";
					}
					else
						return "";

				break;
				
			}
		}
		else
			return " - " + strName + " is a required field.\n\r";
	}
	else
		return " - " + strName + " was not present on the form. Please contact us by phone.\n\r	";
	
}

function popTerms(strLink)
{
	var w = window.open(strLink, "popTerms",'width=850, height=650');	
}

function LogDocsDownload(DocID)
{
	var newURL = addon+"Common/LogActions.php?Action=DownloadDoc&DocID="+DocID;
	if(DocID != '')
		ABasic(newURL, "nothing");
}

function LogBrochureDownload(DocID)
{
	var newURL = addon+"Common/LogActions.php?Action=DownloadBrochure&DocID="+DocID;
	if(DocID != '')
		ABasic(newURL, "nothing");
}

function LogUpload(DocID)
{
	var newURL = addon+"Common/LogActions.php?Action=UploadDoc&DocID="+DocID;
	if(DocID != '')
		ABasic(newURL, "nothing");
}

function LogEditUpload(DocID)
{
	var newURL = addon+"Common/LogActions.php?Action=EditUploadDoc&DocID="+DocID;
	if(DocID != '')
		ABasic(newURL, "nothing");
}

function LogDocsLogin()
{
	var newURL = addon+"Common/LogActions.php?Action=LoginDoc";
	ABasic(newURL, "nothing");
}

function LogBrochureLogin()
{
	var newURL = addon+"Common/LogActions.php?Action=LoginBrochure";
	ABasic(newURL, "nothing");
}

function LogDocsLogout()
{
	var newURL = addon+"Common/LogActions.php?Action=LogoutDoc";
	ABasic(newURL, "Logout");	
}

function LogBrochureLogout()
{
	var newURL = addon+"Common/LogActions.php?Action=LogoutBrochure";
	ABasic(newURL, "Logout");	
}

function LogDocsRegister(UserEmail)
{
	var newURL = addon+"Common/LogActions.php?Action=DocsRegistered&UserEmail="+ UserEmail;
	ABasic(newURL, "nothing");	
}

function LogBrochureRegister(UserEmail)
{
	var newURL = addon+"Common/LogActions.php?Action=BrochureRegistered&UserEmail="+ UserEmail;
	ABasic(newURL, "nothing");	
}

function CheckSiteDocs(obj)
{
	if(obj.checked == true)
	{
		var objSD = document.getElementById("SiteDocs");	
		objSD.checked = false;
	}
}

function CheckBrochure(obj)
{
	if(obj.checked == true)
	{
		var objSD = document.getElementById("Brochure");	
		objSD.checked = false;
	}
}

function ShowImage(strType, strImageName, sysID, MLID)
{
	var w = window.open("Data/ShowImage.php?Type="+strType+"&ImageName="+strImageName+"&SysID="+sysID+"&MLID="+MLID, "popTerms",'width=700, height=550');	
}

function ActivateTab(strTabID)
{
	var tabObj = document.getElementById(strTabID);
	
	var ComTab = document.getElementById("ComListings");
	var ResTab = document.getElementById("ResListings");
	var LndTab = document.getElementById("LndListings");
	var InvTab = document.getElementById("InvListings");
	var BusTab = document.getElementById("BusListings");	
	
	var BioTab = document.getElementById("Bio");
	var ContactTab = document.getElementById("Contact");
	
	
	if(null != tabObj)
	{
		//Deactivate all tabs
		ComTab.className = 'hidden';
		ResTab.className = 'hidden';
		BioTab.className = 'hidden';
		BusTab.className = 'hidden';
		LndTab.className = 'hidden';
		InvTab.className = 'hidden';
		ContactTab.className = 'hidden';
		
		//Activate clicked tab
		tabObj.className = 'visible'
	}
	
}


function SetMLID(MLID)
{
	var mlidObj = document.getElementById("MLID");

	if(null != mlidObj)
		mlidObj.value = MLID;
		
}


function CheckDynErrors()
{
	var Form = document.getElementById("myForm");	
	
	if(undefined != Form && null != Form)
	{
		var ErrorMessage = '';		
		var arrID = (Form.ReqdFields.value).split("~");
		var arrTxt = (Form.ReqdText.value).split("~");
		var lngth = (arrID.length-1);
		var firstObject = '';
		
		for (i=0;i<=lngth;i++)
		{
			if(undefined != document.getElementById(arrID[i]) && null != document.getElementById(arrID[i]) )
			{
				if(DetermineValue(document.getElementById(arrID[i]), document.getElementById('type'+arrID[i]).value) == false)
				{				
					if(ErrorMessage == '')
						document.getElementById(arrID[i]).focus();
					
					highlightErrors(document.getElementById(arrID[i]));		
					
					ErrorMessage += "\"" + arrTxt[i] + "\" is not defined.\n";
					
					
				}
				else if(arrID[i] == "ContactCaptcha")
				{
					
					if(url.search(/localhost/i) > 0 || url.search(/msws1/i) > 0 || url.search(/mspcadmin/i) > 0 )
						AWaitaddon = "";
					else
						AWaitaddon = "/";
					
					AWait(AWaitaddon + "Common/capchaCheck.php?val=" + document.getElementById(arrID[i]).value, "capVal");
					
					if(document.getElementById("capValInput").value != "true")
						ErrorMessage += "\"" + arrTxt[i] + "\" is incorrect.\n";	
				}
			}
			else	
				ErrorMessage += "\"" + arrTxt[i] + "\" is not defined.\n";
			
			
		}
		
		if (ErrorMessage != "")
		{
			alert("The following errors must be corrected before we will accept your request:\n\n" + ErrorMessage + '\nPlease review and make corrections as neccesary.');
			return false;			
		}
		else
			return true;
	}
	else
		alert("An error occured. Please contact us by phone.");	
	
}


function highlightErrors(obj)
{
	obj.style.backgroundColor ='yellow';
}


function DetermineValue(obj, strType)
{
	switch(strType)
	{
		case "select":
		case "states":
			return Select(obj);
			break;
			
		case "textbox":	
		case "captcha":	
			
			return Textbox(obj);
			break;	
			
		case "checkbox":	
			return Checkbox(obj);
			break;

		case "radio":	
			return Radio(obj);
			break;
		
		default: 
			return false;
			break;
	}
	
}




function Textbox(obj)
{
	if(obj.value != "")
		return true;
	else
		return false;
}

function Radio(obj)
{
	if(obj.value != "")
		return true;
	else
		return false;
}

function Checkbox(obj)
{
	var Selected = false;
	for (var i=0; i < obj.length; i++)
	{
		if (obj[i].checked && Selected == false)
			Selected = true;
	}

	return Selected;
}

function Select(obj)
{
	if(obj.options[obj.selectedIndex].value != "")
		return true;
	else
		return false;
}


function OpenPanel(strPanels, objCaller)
{
	var arr = strPanels.split(",");
	var lngth = (arr.length-1);
	for (i=0;i<=lngth;i++)
	{
		if (document.getElementById(arr[i]).id == arr[i])
		{
			document.getElementById(arr[i]).className = 'visible';	
			document.getElementById('tab'+arr[i]).className = 'current';		
		
		}
		
	}
	

}

function HidePanel(strPanels)
{
	var arr = strPanels.split(",");
	var lngth = (arr.length-1);
	for (i=0;i<=lngth;i++)
	{
		if (document.getElementById(arr[i]).id == arr[i])
		{
			document.getElementById(arr[i]).className = 'hidden';	
			document.getElementById('tab'+arr[i]).className = 'none';
		}
	}
}


