var strBoxTop = "<div class=\"rBox\"><div class=\"rBox1\"><div class=\"rBoxBgBorder\"></div></div><div class=\"rBox2\"><div class=\"rBoxBg2\"><div class=\"rBoxBg\"></div></div></div><div class=\"rBox3\"><div class=\"rBoxBg3\"></div></div><div class=\"rBox4\"><div class=\"rBoxBg3\"></div></div><div class=\"rBox5\"><div class=\"rBoxBg\"></div></div></div><div class=\"rBoxContent\">";
var strBoxBottom = "</div><div class=\"rBox\"><div class=\"rBox5\"><div class=\"rBoxBg\"></div></div><div class=\"rBox4\"><div class=\"rBoxBg3\"></div></div><div class=\"rBox3\"><div class=\"rBoxBg3\"></div></div><div class=\"rBox2\"><div class=\"rBoxBg2\"><div class=\"rBoxBg\"></div></div></div><div class=\"rBox1\"><div class=\"rBoxBgBorder\"></div></div></div>";
function applyRoundedBox(arr){
	for(i=0; i<arr.length ; i++){
		//if(arr[i].className == "roundedBox" || (arr[i].id == "sidebar" && Trim(arr[i].innerHTML) != "<!-- InstanceBeginEditable name=\"Side Bar\" --><!-- InstanceEndEditable -->")){
		if(arr[i].className == "roundedBox"){
			arr[i].innerHTML = strBoxTop + arr[i].innerHTML + strBoxBottom;
		}
	}
}

/* Drop Down Menu Navigation (shortcuts) Code */
function land(ref, target)
{
	lowtarget=target.toLowerCase();
	if (lowtarget=="_self") {window.location=loc;}
	else {if (lowtarget=="_top") {top.location=loc;}
	else {if (lowtarget=="_blank") {window.open(loc);}
	else {if (lowtarget=="_parent") {parent.location=loc;}
	else {parent.frames[target].location=loc;};
	}}}
}

function jump(menu)
{
	ref=menu.choice.options[menu.choice.selectedIndex].value;
	splitc=ref.lastIndexOf("*");
	target="";
	if (splitc!=-1)
	{loc=ref.substring(0,splitc);
	target=ref.substring(splitc+1,1000);}
	else {loc=ref; target="_self";};
	if (ref != "") {land(loc,target);}
}


/* Pop-up Window Code*/
function MM_openBrWindow(theURL,winName,features) { 
	window.open(theURL,winName,features);
}

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]+"'");
}

function getObject(str) {
	var o;
	if (document.all){
		eval('o = document.all.' + str);
	} else if (document.getElementById){
		o = document.getElementById(str);
	}
	return o;
}

function confirmDate(dateStr) {
	dateStr = String(dateStr);
	var month = dateStr.substring(0, dateStr.indexOf("/"));
	var day   = dateStr.substring(dateStr.indexOf("/")+1, dateStr.lastIndexOf("/"));
	var year  = dateStr.substring(dateStr.lastIndexOf("/")+1, dateStr.length);
	if (!isNaN(month) && !isNaN(day) && !isNaN(year)) {
		if (year > 79 && year < 100)
			year = parseInt(year) + 1900;
		if (year > 0 && year < 79)
			year = parseInt(year) + 2000;
		if (month < 1 || month > 12 || day < 1 || day > 31 || year < 1800 || year > 2200)
			return false;
		else
		if (month == 2 && day > 29 && (year%400 == 0))
			return false;
		else
		if (month == 2 && day > 28 && (year%100 == 0) && (year%400 != 0))
			return false;
		else
		if (month == 2 && day > 29 && (year%4 == 0))
			return false;
		else
		if (month == 2 && day > 28 && (year%4 != 0))
			return false;
		else
		if (month == 9 && day > 30)
			return false;
		else
		if (month == 11 && day > 30)
			return false;
		else
		if (month == 4 && day > 30)
			return false;
		else
		if (month == 6 && day > 30)
			return false;
		else
			return true;
	}
	else
		return false;
}

function Trim(str){
	var ret=str+"";
	while(ret.length>0 && ret.substring(0,1)==" "){
		ret=ret.substring(1,ret.length);
	}
	while(ret.length>0 && ret.substring(ret.length-1,ret.length)==" "){
		ret=ret.substring(0,ret.length-1);
	}
	return ret;
}

function TrimText(str,len){
	if(str.length>len){
		alert("Please limit your message to "+len+" characters or fewer");
		str = str.substring(0,len)
	}
	return str;
}

function showRemaining(elm, dispID, maxLen) {
	var frm = elm.form;
	var disp = document.getElementById(dispID);
	disp.innerHTML = (maxLen-elm.value.length) + " characters remaining";
}

function replace(str,strFind,strReplace){
	var ret="";
	str=String(str);
	while(str.indexOf(strFind)>=0){
		ret+=str.substring(0,str.indexOf(strFind));
		ret+=strReplace;
		str=str.substring(str.indexOf(strFind)+strFind.length,str.length);
	}
	return ret+str;
}

function verifyEmail(eMail) {
	var posAt = eMail.indexOf("@");
	var posDotLast = eMail.lastIndexOf(".");
	if (posAt <= 0 || (posAt > posDotLast))
		return false;
	if (Trim(eMail) == "")
		return false;
	if (Trim(eMail).indexOf(" ")>=0)
		return false;
	return true;		
}

function MakeValidWebsite(str){
	str = Trim(str);
	str = replace(str," ","");
	if(str.substring(0,7).toLowerCase()=="http://"){
		return str.substring(7);
	}
	if(str.substring(0,6).toLowerCase()=="http//"){
		return str.substring(6);
	}
	if(str.substring(0,6).toLowerCase()=="http:/"){
		return str.substring(6);
	}
	if(str.substring(0,6).toLowerCase()=="htt://"){
		return str.substring(6);
	}
	var posDotLast = str.lastIndexOf(".");
	if (posDotLast <= 0)
		return "";
	return str;
}

function MakeParagraphs(atext) { 
	var atext = replace(atext,"'","`"); 
	var pos = atext.indexOf("\r\n\r\n"); 
	var retval = ""; 
	while (pos > -1) { 
		retval += "<p>"+atext.substr(0, pos)+"</p>"; 
		atext = atext.substr(pos+4, atext.length); 
		pos = atext.indexOf("\r\n\r\n"); 
	} 
	if(atext.length > 0) {
		retval += "<p>"+atext+"</p>"; 
	}
	retval = replace(retval,"\r\n","<br>");
	retval = replace(retval,"\r","");
	retval = replace(retval,"\n","");
	return retval;
}

function validateBusinessForm(f) {
	if (Trim(f.BusinessName.value)==""){
		alert("You must enter a business name.");
		f.BusinessName.select();
		f.BusinessName.focus();
		return false;
	}
	if (Trim(f.BusinessCity.value)==""){
		alert("You must enter a city.");
		f.BusinessCity.select();
		f.BusinessCity.focus();
		return false;
	}
	if (Trim(f.BusinessState.value)==""){
		alert("You must enter a state.");
		f.BusinessState.select();
		f.BusinessState.focus();
		return false;
	}
	if (Trim(f.BusinessWebsite.value)==""){
		alert("You must enter a website address.");
		f.BusinessWebsite.select();
		f.BusinessWebsite.focus();
		return false;
	}
	if (Trim(f.BusinessDescription.value)==""){
		alert("You must enter a description.");
		f.BusinessDescription.select();
		f.BusinessDescription.focus();
		return false;
	}
	if (f.BusinessDescription.value.length>1000){
		alert("Your description must be no longer than 1000 characters.");
		f.BusinessDescription.select();
		f.BusinessDescription.focus();
		return false;
	} 
	
	var obj = f.chkCategoryID;
	var count = 0;
	for (i=0; i< obj.length; i++) {
		if (obj[i].checked == true)
			count++;
	}
	if(count==0){
		alert("You must select at least one category.");
		f.chkCategoryID[0].focus();
		return false;
	}
	if(count>15){
		alert("You may select no more than 15 categories.");
		f.chkCategoryID[0].focus();
		return false;
	}
	if (!f.BusinessOrdersWebsite.checked && !f.BusinessOrdersPhone.checked){
		alert("Please indicate the store's eCommerce capabilities");
		f.BusinessOrdersWebsite.focus();
		return false;
	}
	/*
	if (Trim(f.BusinessShipDeadline.value)!=""){
		if(confirmDate(f.BusinessShipDeadline.value)==false){
			alert("You must either enter a valid date for your shipping deadline or leave the field blank");
			f.BusinessShipDeadline.select();
			f.BusinessShipDeadline.focus();
			return false;	
		}
	}
	*/
	if (f.BusinessAcceptTerms.checked==false){
		alert("You must accept the terms and conditions.");
		f.BusinessAcceptTerms.focus();
		return false;	
	}	
	return true;
}

function validateMemberForm(f) {
	if (Trim(f.BusinessName.value)==""){
		alert("You must enter a business name.");
		f.BusinessName.select();
		f.BusinessName.focus();
		return false;
	}
	if (Trim(f.BusinessCity.value)==""){
		alert("You must enter a city.");
		f.BusinessCity.select();
		f.BusinessCity.focus();
		return false;
	}
	if (Trim(f.BusinessState.value)==""){
		alert("You must enter a state.");
		f.BusinessState.select();
		f.BusinessState.focus();
		return false;
	}
	if (Trim(f.BusinessCity.value)==""){
		alert("You must enter a city.");
		f.BusinessCity.select();
		f.BusinessCity.focus();
		return false;
	}
	if (Trim(f.BusinessWebsite.value)==""){
		alert("You must enter a website address.");
		f.BusinessWebsite.select();
		f.BusinessWebsite.focus();
		return false;
	}
	if (Trim(f.BusinessDescription.value)==""){
		alert("You must enter a description.");
		f.BusinessDescription.select();
		f.BusinessDescription.focus();
		return false;
	}
	if (f.BusinessDescription.value.length>1000){
		alert("Your description must be no longer than 1000 characters.");
		f.BusinessDescription.select();
		f.BusinessDescription.focus();
		return false;
	} 
	
	var obj = f.chkCategoryID;
	var count = 0;
	for (i=0; i< obj.length; i++) {
		if (obj[i].checked == true)
			count++;
	}
	if(count==0){
		alert("You must select at least one category.");
		f.chkCategoryID[0].focus();
		return false;
	}
	if(count>15){
		alert("You may select no more than 15 categories.");
		f.chkCategoryID[0].focus();
		return false;
	}
	if (!f.BusinessOrdersWebsite.checked && !f.BusinessOrdersPhone.checked){
		alert("Please indicate the store's eCommerce capabilities");
		f.BusinessOrdersWebsite.focus();
		return false;
	}
	/*
	if (Trim(f.BusinessShipDeadline.value)!=""){
		if(confirmDate(f.BusinessShipDeadline.value)==false){
			alert("You must either enter a valid date for your shipping deadline or leave the field blank");
			f.BusinessShipDeadline.select();
			f.BusinessShipDeadline.focus();
			return false;	
		}
	}
	*/
	if (f.BusinessAcceptTerms.checked==false){
		alert("You must accept the terms and conditions.");
		f.BusinessAcceptTerms.focus();
		return false;	
	}	
	return true;
}
