function doSubmit(myLocation) {
	document.searchForm.action = myLocation;
	document.searchForm.submit();
}

function formatEmail(myField) {
	myField.value = myField.value.toLowerCase();
	var myVal = myField.value;
	if(myVal!='' && !checkEmail(myVal)) {
		alert("Email does not appear to be formatted properly.");
		myField.focus();
		return false;
	}
}

function printpage() {
	window.print();  
}

function popup(arg) {
	if(arg=='Sample Report') {
		window.open("/images/SampleProject2.gif","sample_report","resizable=yes, width=950, height=750");
	} else if(arg=='CC Help') {
		window.open("/images/cvv2.gif","cc_help","resizable=yes, width=235, height=175");
	} else if(arg=='Graph') {
		window.open("/images/graph.gif","graph","resizable=no, width=550, height=450");
	} else if(arg=='Rules') {
		window.open("/content/bulletinBoardRules.jsp","rules","resizable=no, width=650, height=550");
	} else { 
		window.open(arg);
	}
}

function setSelectIndex(sel, val) {
	for (i=0;i<sel.options.length;i++) {
     	if (sel.options[i].value == val) {
      		sel.selectedIndex = i;
       		break;
       	}
    }
}

function setSelectIndexes(sel, val) {
	for (i=0;i<sel.options.length;i++) {
       	if (sel.options[i].value == val) {
       		sel.options[i].selected = true;
       		break;
       	}
    }
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {  begin = dc.indexOf(prefix);  if (begin != 0) return null; } else {  begin += 2;  }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {  end = dc.length;  }
    return unescape(dc.substring(begin + prefix.length, end));
}

function fixCapitalization(val) {
	return val.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()}); 
}

function openProfile(arg) {
	window.open("/profile/adProfile.jsp?profileID=" + arg,"ad_profile","resizable=no, width=500, height=425");
}

function openProfile2(arg, arg2) {
	window.open("/profile/adProfile.jsp?profileID=" + arg + "&adID=" + arg2,"ad_profile","resizable=no, width=500, height=240");
}

function openMap(arg, arg2, arg3, arg4, arg5) {
	window.open("/mapquest/advantage.jsp?address=" + arg + "&city=" + arg2 + "&stateProvince=" + arg3 + "&postalCode=" + arg4 + "&name=" + arg5,"map_live","resizable=no, width=625, height=675");
}

function openMapDemo() {
	window.open("/mapquest/demo.html","map_demo","resizable=no, width=625, height=675");
}

function openPlanDemo() {
	window.open("/projects/plansDemo.jsp","plan_demo","resizable=no, width=525, height=365");
}

function openPlans(arg) {
	//window.open("/projects/projectPlans.jsp?projectID=" + arg,"project_plans","resizable=yes, width=525, height=450, scrollbars=yes");
	window.open("/projects/projectPlans.jsp?projectID=" + arg,"project_plans","resizable=yes, width=685, height=650, scrollbars=no");
}

function openPlansAnnualUpgrade (projectId)
{
	window.location = "/account-administration/signup/plansAnnualUpgradePromo.jsp?projectId=" + projectId;
}

function openProjImageDemo() {
	window.open("/projects/imageDemo.jsp","image_demo","resizable=no, width=720, height=600");
}

function openProjImage(arg, arg2) {
	window.open("/projects/projImage.jsp?image=" + arg + "&name=" + arg2,"proj_image","resizable=no, width=720, height=600");
}

function openProjImage2(arg) {
	window.open("/projects/projImage2.jsp?projectID=" + arg,"proj_image2","resizable=no, width=750, height=750");
}

function openProjImage3(arg, arg2, arg3) {
	window.open("/projects/projImage3.jsp?projectID=" + arg + "&ssc=" + arg2 + "&mode=" + arg3,"proj_image3","resizable=yes, scrollbars=yes, width=950, height=750");
}

function openReferralDetails() {
	window.open("/projects/referralDetails.jsp","referralDetails","resizable=no, width=500, height=525");
}

function emailToFriend(arg) {
	window.open("/projects/emailToFriend.jsp?projectID=" + arg,"email_to_friend","resizable=yes, width=525, height=550, scrollbars=yes");
}

function sendBBNRequest(arg) {
	var requestWindow = window.open("/profile/bbnRequest.jsp?customerUserId=" + arg,"BBN_request","resizable=yes, width=400, height=250, scrollbars=yes");
	requestWindow.focus();
}

function viewBBNProfile(custId, custUserId) {
	var bbnProfile = window.open("/bbn/profileView.jsp?pcId=" + custId + "&pcuId=" + custUserId,"ProfileView","resizable=yes, width=950, height=750, scrollbars=yes");
	bbnProfile.focus();
}

function citiBankPromo() {
	window.open("/partners/citibank.jsp","citibank_lead","resizable=no, width=650, height=620, scrollbars=no");
}
 
function emailToContact(arg) {
	window.open("/projects/sendContactEmail.jsp?contactID=" + arg,"email_contact","resizable=yes, width=525, height=550, scrollbars=yes");
}
function openMultiAddresses(arg, arg2) {
	window.open("/projects/addressWindow.jsp?entityID=" + arg + "&entityTypeID=" + arg2,"address_page","resizable=yes, width=525, height=550, scrollbars=yes");
}

function formatPhone(myField) {
	var myVal = myField.value;
	var str = '';
	if(myVal != '') {			
		myVal = myVal.replace(/[^\d]/g,'');
		if(myVal.length<10) { 
			alert("Phone and Fax must include the full 10 digit number.\n(xxx) xxx-xxxx.");
			myField.focus();
			return false;				
		}
		str = "(" + myVal.substring(0,3) + ") " + myVal.substring(3,6) + "-" + myVal.substring(6,10);
		if(myVal.length>10) {
			str += " x" + myVal.substring(10, myVal.length);
		}
	}
	myField.value = str;
}

function checkSourceURL(myField) {
	var myVal = myField.value;
	if(myVal!='' && (myVal.indexOf("http://")!=0 && myVal.indexOf("https://")!=0)) {
		if(myVal.indexOf("www")==0) {
			myField.value = "http://" + myVal;
		} else {
			alert("Source URL missing 'HTTP://'.");
			myField.focus();
			return false;
		}
	}
}

function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
	{
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print) // opera
	{ 
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)  // ie
	{
		window.external.AddFavorite(url, title);
	}
}


function getXmlHttpRequest() {

	var xhr; 

   	try 
   	{ 
   		xhr = new XMLHttpRequest(); 
   	}                 
   	catch(err) 
   	{
		try
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(err2)
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}	   			   		
	}
	
	return xhr;
}


