//cookie check for javascript enabled/disabled...
//if javascript is enabled the app will be able to read the correct value for cookie
document.cookie = 'javascript=true'

//Order processing display
var bCCFormSubmitted = false;

function submitCCForm()
{ 
	for(var i=0;i<document.forms.length;i++)
	{
		if(document.forms[i].name=='CCInfo')
		{
			document.forms[i].submit();
			bCCFormSubmitted = true;
			var btn = document.getElementById('clickButton');
			if(btn)
			{
				btn.src='/LegalEdUI/images/checkout/processing_blue.gif';
			}
		}
	}
}

function switchToProcessing(theImage)
{
	if(!bCCFormSubmitted)
	{
		theImage.src='/LegalEdUI/images/checkout/processing_blue.gif?1234';
		submitCCForm();
	}
}

function switchCursor(theImage)
{
	if (navigator.appVersion.indexOf("MSIE")!=-1)  // For IE
	{
		if(!bCCFormSubmitted)
		{
			theImage.style.cursor='hand';
			theImage.style.cursor='pointer';
		}
		else
		{
			theImage.style.cursor='wait';
		}
	}
	else										// For Other browsers
	{
		if(!bCCFormSubmitted)
		{
			theImage.style.cursor='pointer';
		}
		else
		{
			theImage.style.cursor='wait';
		}	
	}
}
//End Order processing display


function InvokeSearch()
{
	var strParam="";
	var bReturn;
	var sCategory = "";
	var sTopic = "";
	var sCategoryTitle = "";
	var sTopicTitle = "";
	var sSearchOpt;
	
	/*if (window.document.SearchForm.ByTitle.checked) 
		sSearchOpt=window.document.SearchForm.ByTitle.value;
	else
		sSearchOpt=window.document.SearchForm.ByISBN.value;*/
	
	strParam=replEscapeChar(window.document.SearchForm.searchCriteria.value);

	bReturn = IsSpaceOnly(strParam);

	if (bReturn) 
	{
		strParam= trimit(window.document.SearchForm.searchCriteria.value);
	}
	
	//if ((strParam=="" ) && ((window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value==0) || (window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value==null)))
	if (strParam=="" )
	{
			alert('Please enter your search criteria (may be a title, author, ISBN, or keyword).');
			return false;
	}		
	else if (strParam!="" ) 
	{			
			window.document.SearchForm.target = "resource window";
			window.document.SearchForm.action ="http://www.aspenpublishers.com/search.asp?Mode=SEARCH&keyword=" + escape(strParam)  + "&ISBN=&Author=&Sort=DEFAULT&profitcenter=30"
			window.document.SearchForm.submit();		
			return true;
	}

	
	/*if ((strParam!="" ) && (window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value!=0) && (window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value!=null))

		{		
			//sCategory = window.document.SearchForm.category.options[window.document.SearchForm.category.selectedIndex].value;
			//sTopic = window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value;
			
			//sCategoryTitle =window.document.SearchForm.category.options[window.document.SearchForm.category.selectedIndex].text;
			//sTopicTitle =window.document.SearchForm.topic.options[window.document.SearchForm.topic.selectedIndex].text;
			//window.document.SearchForm.action ="search.asp?Mode=SEARCH&keyword=" + escape(strParam) + "&Category=" + escape(sCategory) + "&Topic=" + escape(sTopic) + "&CategoryTitle=" + escape(sCategoryTitle) + "&TopicTitle=" + escape(sTopicTitle) + "&ISBN=&Author=&Sort=DEFAULT"
			window.document.SearchForm.action ="search.asp?Mode=SEARCH&keyword=" + escape(strParam) + "&Category=" + escape(sCategory) + "&Topic=" + escape(sTopic) + "&CategoryTitle=" + escape(sCategoryTitle) + "&TopicTitle=" + escape(sTopicTitle) + "&ISBN=&Author=&Sort=DEFAULT"
			window.document.SearchForm.submit();		
			return true;
		}
	*/
	//if ((strParam!="" ) && ((window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value==0)||(window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value==null)))
	/*
	else if ((strParam=="" ) && (window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value!=0) && (window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value!=null))
		{
			sCategory = window.document.SearchForm.category.options[window.document.SearchForm.category.selectedIndex].value;
			sTopic = window.document.SearchForm.topic[window.document.SearchForm.topic.selectedIndex].value;
			
			sCategoryTitle =window.document.SearchForm.category.options[window.document.SearchForm.category.selectedIndex].text;
			sTopicTitle =window.document.SearchForm.topic.options[window.document.SearchForm.topic.selectedIndex].text;

			window.document.SearchForm.action ="search.asp?Mode=BROWSE&Category=" + escape(sCategory) + "&Topic=" + escape(sTopic) + "&CategoryTitle=" + escape(sCategoryTitle) + "&TopicTitle=" + escape(sTopicTitle) + "&Sort=TITLE"
			window.document.SearchForm.submit();
			return true;
		}
	else	
		{
			if (!((window.document.SearchForm.category[window.document.SearchForm.category.selectedIndex].value==null) || (window.document.SearchForm.category[window.document.SearchForm.category.selectedIndex].value==0) || (window.document.SearchForm.category.value.indexOf("Choose")==0)))
				{
				alert("Please select the subcategory");
				}
			else
				{
				alert("Please enter a search string...");
				}
			return false;
		} 
	*/
}
function replEscapeChar(strKeyword)	{
	if (strKeyword.indexOf("+")>0)
		//replace the + sign with the some other character and parse it back in the posted asp page.
		return strKeyword.replace("+","~");
	else
		return strKeyword;
}
	
function IsSpaceOnly(s) 
{
	var i;
	for(i=0; i<=s.length-1; i++)	{
		if ((s.charAt(i) != ' ')) {
			return false;
		}
	}
	return true;	
}
function trimit(s)
{
	
	while (s.length!=0)
	{
		s = s.replace(" ","");	
	}
	return s;
}

function popWindow( url, width, height, allowScroll )
{
	var wnd;
	var scrollYesNo;
	
	if(allowScroll==true)
	{
		wnd = window.open( url,
					'_blank', 
					'height=' + height + ',width=' + width + ',location=no,menubar=no,scrollbars=yes,resizable=no,toolbar=no'
					);
	}
	else
	{
		wnd = window.open( url,
					'_blank', 
					'height=' + height + ',width=' + width + ',location=no,menubar=no,scrollbars=no,resizable=no,toolbar=no'
					);
	}

	wnd.focus();	
} // popWindow

function popupTimeline()
{
    return popWindow( '../law_students/timeline.asp', 600, 315, true );
} // popTimeline()

function validateSignupForm( frm )
{
	if( frm.first_name.value == "" ||
	    frm.last_name.value == "" ||
	    frm.email.value == "" )
	{
	    alert( "Please enter your first and last name, and your email address." );
	    return false;
	}
	else
	{
	    return true;
	}
} // validateSignupForm()

function validateSignupForm( frm )
{
	if( frm.first_name.value == "" ||
	    frm.last_name.value == "" ||
	    frm.email.value == "" )
	{
	    alert( "Please enter your first and last name, and your email address." );
	    return false;
	}
	else
	{
	    return true;
	}
} // validateSignupForm()

function validateRequestForm( frm )
{
	if( frm.first_name.value == "" ||
	    frm.last_name.value == "" )
	{
	    alert( "Please enter your first and last name." );
	    return false;
	}
	else
	{
	    return true;
	}
} // validateRequestForm()

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

function customerTypeChange(customerType, frm)
{
	var hiddenElement;

	for(var i=0;i<document.forms.length;i++)
	{
		//alert(document.forms[i].name);
		if(document.forms[i].name=='profile')
		{	
			for (var j=0;j<document.forms[i].length;j++)
			{
			if(document.forms[i].elements[j].name=='customer_type_change')
			{
				document.forms[i].elements[j].value = 'true';
				break;
			}		
			}
			document.forms[i].submit();
		}
	}
}

/********** Duke video specific javascript functions ************/
/*--BEGIN */

function switchToActiveTab(obj)
{
    document.getElementById('activeTab').id='';
    obj.id='activeTab';
    return false;
}

/* -- Used in the Youtube-like video listing page --*/
function showInline(elName)
{
	var theElemenet=document.getElementById(elName);
	if(theElemenet)
	{
		theElemenet.style.display="inline";
	}
}

/* -- Used in the Youtube-like video listing page --*/
function hideInline(elName)
{
	var theElemenet=document.getElementById(elName);
	if(theElemenet)
	{
		theElemenet.style.display="none";
	}
}
/*--END */
/********** Learning Center Traning functions *****************/
/*--BEGIN */
function showhideContent(elName, elImageName)
{
	var theElement=document.getElementById(elName);
	var theImageElement=document.getElementById(elImageName);
	if (theImageElement.tagName == "LI")
	{
		if(theImageElement.style.listStyleImage.indexOf("images/buttons/softminus.gif") > 0)
		{
			theImageElement.style.listStyleImage = "url(../UI/images/buttons/softplus.gif)";
			theImageElement.title="Click here to expand";
		}
		else
		{
			theImageElement.style.listStyleImage = "url(../UI/images/buttons/softminus.gif)";
			theImageElement.title="Click here to collapse";
		}	
	}
	else
	{
		if(theImageElement.src.indexOf("images/buttons/softminus.gif") > 0)
			{
				theImageElement.src="../UI/images/buttons/softplus.gif";
				theImageElement.title="Click here to expand.";								
			}
		else
			{
				theImageElement.src="../UI/images/buttons/softminus.gif";
				theImageElement.title="Click here to collapse.";				
			}    
	}		    
	if(theElement)
	{
	     theElement.style.display = (theElement.style.display == 'none') ? 'block' :'none';
	}  
	var iItemsExpanded, iOriginalItems, iItemsCollapsed;
	iItemsExpanded = 0;
	iOriginalItems = 0;
	iItemsCollapsed= 0;
	for(i = 0; i < 15; i++) {
		liElName = "liTips" + i;
		divElName = "divTips" + i;
		var liElement = document.getElementById(liElName);
		var divElement = document.getElementById(divElName);
		if (liElement != null && divElement != null){
			iOriginalItems = iOriginalItems + 1;
			if(divElement.style.display == "block")
				iItemsExpanded = iItemsExpanded + 1;
			else
				iItemsCollapsed = iItemsCollapsed +1
			}
	}	
	
	var aElement = document.getElementById("ExpandCollapse");   
	if(iOriginalItems == iItemsExpanded)
	{
		aElement.innerHTML = "[Collapse All]";
		aElement.onclick = function(){ExpandcollapseAll('collapse');}
		
	}
	if(iOriginalItems == iItemsCollapsed)
	{
		aElement.innerHTML = "[Expand All]";
		aElement.onclick = function(){ExpandcollapseAll('expand');}
		
	}
	if(elName == "divTipsContent")
	{
		if(theImageElement.src.indexOf("images/buttons/softminus.gif") > 0)
		{
			aElement.innerHTML = "[Expand All]";
			aElement.onclick = function(){ExpandcollapseAll('expand');}
		}
		else
		{
			aElement.innerHTML = "";
		}
	}	
	
}
function ExpandcollapseAll(action)
{
	var divElName,liElName;
	
	var aElement = document.getElementById("ExpandCollapse");
	if(action == "collapse"){
		aElement.innerHTML = "[Expand All]";
		aElement.onclick = function(){ExpandcollapseAll('expand');}
	}
	else
	{
		aElement.innerHTML = "[Collapse All]";
		aElement.onclick = function(){ExpandcollapseAll('collapse');}
	}	
	for(i = 0; i < 11; i++) {
		liElName = "liTips" + i;
		divElName = "divTips" + i;
		var liElement = document.getElementById(liElName);
		var divElement = document.getElementById(divElName);
		if (liElement != null && divElement != null){
			if(action == "collapse"){
				divElement.style.display = 'none';
				liElement.style.listStyleImage = "url(../UI/images/buttons/softplus.gif)";
				liElement.title="Click here to expand";
			}
			else
			{
				divElement.style.display = 'block';
				liElement.style.listStyleImage = "url(../UI/images/buttons/softminus.gif)";
				liElement.title="Click here to collapse";
			}
		}
	}
}
function CareerTypeCheckBoxes(checkboxval)
{
var aElement1 = document.getElementById("career_type3");
var aElement2 = document.getElementById("career_type2");
var aElement3 = document.getElementById("career_type1");
var aElement4 = document.getElementById("graduation_month");
var aElement5 = document.getElementById("graduation_year");


if ((checkboxval=='career_type3') && (aElement1.checked==false))
{
aElement4.disabled=false;
aElement5.disabled=false;
}
if ((checkboxval=='career_type3') && (aElement1.checked==true))
{
aElement2.checked=false;
aElement3.checked=false;
aElement4.options[0].selected=true;
aElement5.options[0].selected=true;
aElement4.disabled=true;
aElement5.disabled=true;
}
if (checkboxval=='career_type2')
{
aElement1.checked=false;
aElement3.checked=false;
aElement4.disabled=false;
aElement5.disabled=false;
}
if (checkboxval=='career_type1')
{
aElement1.checked=false;
aElement2.checked=false;
aElement4.disabled=false;
aElement5.disabled=false;
}
}
/*--END */
