//Proof and review...
function Popup(Url, PopupName, dl_width, dl_height)
{
	var x = 0, y = 0; // default values

	if (document.all)
	{
		x = window.screenTop + 100;
		y = window.screenLeft + 100;
	}
	else if (document.layers)
	{
		x = window.screenX + 100;
		y = window.screenY + 100;
	}
	
	TheNewWin = window.open(Url, PopupName, "left=" + x + ", screenX=100,top=" + y + ", screenY=100, scrollbars=yes, resizable=no, width="+dl_width+", height="+dl_height+", status=no, resizable=1");
	TheNewWin.focus();
}

function lospopup(Url, PopupName, dl_width, dl_height)
{
	var x = 0, y = 0; // default values

	if (document.all)
	{
		x = window.screenTop + 100;
		y = window.screenLeft + 100;
	}
	else if (document.layers)
	{
		x = window.screenX + 100;
		y = window.screenY + 100;
	}
	
	TheNewWin = window.open(Url, PopupName, "left=" + x + ", screenX=100,top=" + y + ", screenY=100, scrollbars=0,  width="+dl_width+", height="+dl_height+", status=0, resizable=0");
	//TheNewWin.blur();
}

//Survey...
function PopupSurvey(Url, PopupName)
{
	var x = 0, y = 0; // default values

	if (document.all)
	{
		x = window.screenTop + 100;
		y = window.screenLeft + 100;
	}
	else if (document.layers)
	{
		x = window.screenX + 100;
		y = window.screenY + 100;
	}
	
	TheNewWin = window.open(Url, PopupName, "left=" + x + ", screenX=100,top=" + y + ", screenY=100, scrollbars=yes, resizable=no, status=no, resizable=1");
	//TheNewWin.blur();
}

//COUNTING SYMBOLS BEGIN
//Graduation Information; Return address labels; Certificate of Appreciation
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);


function TrimStringL (sInString)
{
    return sInString.replace( /^\s+/g, "" );// strip leading
}

function TrimStringR (sInString)
{
    return sInString.replace( /\s+$/g, "" );// strip trailing
}

function getSelectionStart (input)
{
	if (is_gecko)
    {
		return input.selectionStart;
    }
	
	//ie get selection start
	var start = Math.abs(document.selection.createRange().moveStart("character", -1000000));
	return start;  
	/*var range = document.selection.createRange ();
	var isCollapsed = range.compareEndPoints ("StartToEnd", range) == 0;
	if (!isCollapsed)
    	range.collapse (true);
    var b = range.getBookmark ();
	var res = b.charCodeAt (2) - 2;
	
	if (typeof document.body.style.maxHeight != "undefined") {
	  return (res - 1);//IE 7, mozilla, safari, opera 9
	} else {//IE6, older browsers
	  return res;
	}*/
}

function getSelectionEnd (input)
{
	if (is_gecko)
    {
		return input.selectionEnd;
    }
    
    //ie get selection end
	var end = Math.abs(document.selection.createRange().moveEnd("character", -1000000));
	return end;
	/*
	var range = document.selection.createRange ();
	var isCollapsed = range.compareEndPoints ("StartToEnd", range) == 0;
	if (!isCollapsed)
    	range.collapse(false);
    var b = range.getBookmark ();
	var res = b.charCodeAt (2) - 2;
	
	if (typeof document.body.style.maxHeight != "undefined") {
		return (res - 1);//IE 7, mozilla, safari, opera 9
	} else {//IE6, older browsers
		return res;
	}*/
}

function setSelectionRange (input, start, end)
{
	if (is_gecko)
    {
		input.setSelectionRange (start, end);
	}
    else
    {
		//ie set selection range
		var range = input.createTextRange ();
		range.collapse (true);
		range.moveStart ("character", start);
		range.moveEnd ("character", end - start);
		range.select ();
	}
}

function fieldManipulate (line, chars_str, chars_num)
{
	var obj = document.getElementById (line);
    var old_length = obj.value.length;
    var caret_pos_start = getSelectionStart (obj);
    var caret_pos_end = getSelectionEnd (obj);
    
    obj.value = TrimStringL(obj.value);
    var new_length = obj.value.length;
    caret_pos_start = caret_pos_start - (old_length - new_length);

    if (caret_pos_start < 0)
    {
        caret_pos_start = 0;
    }
    
    caret_pos_end = caret_pos_end - (old_length - new_length)
    
    if (!(caret_pos_start == new_length && obj.value.charAt(new_length - 1) == ' '))
    {
        obj.value = TrimStringR(obj.value);
        
        if (caret_pos_start > new_length)
        {
            caret_pos_start = new_length;
            caret_pos_end = new_length;
        }
        else
        {
            if (caret_pos_end > new_length)
            {
                caret_pos_end = new_length;
            }
        }
    }
    
    setSelectionRange (obj, caret_pos_start, caret_pos_end);
}

function changeRemainingChars (line, chars_str, chars_num)
{
    fieldManipulate (line, chars_str, chars_num);
    
    var obj = document.getElementById (line);
    var chars = document.getElementById (chars_str);
	chars.value = chars_num - obj.value.length;
}

function changeRemainingCharsProof (line, chars_str, chars_num)
{
    fieldManipulate (line, chars_str, chars_num);
    
    var obj = document.getElementById (line);
    var chars = document.getElementById (chars_str);
	chars.value = chars_num - obj.value.length;
}
//COUNTING SYMBOLS END 

/*
//all steps (previous button, left menu links)
function alertLostData ()
{
   return confirm ( 'If you continue you will lose any changes on this page.' +
   					'\nContinue?' );
}
*/

//all steps (disable submit buttons - prev, save, next) BEGIN
function submitonce()
{
	var submit_name_field = document.getElementById('submit_name');
	
	if (submit_name_field.value == '1')
	{
		submit_name_field.value = '0';
		return true;
	}
	else
	{
		return false;
	}
}

//for possible predefine with preliminary events
function prelimFunc(){return true;}

function submitFunc(key_string)
{
	switch(key_string)
	{
		/*case 'next':
			return submitonce();
			break*/
		case 'next':
            if (prelimFunc()) {
              return submitonce();
            } else
            	return false;
            break
            
		case 'save':
			return submitonce();
			break
			
		case 'prev':
			{
				return submitonce();
				
				/*
				if (alertLostData ())
				{
					return submitonce();
				}
				else
				{
					return false;
				}
				*/
				
				/*var submitonceVar = submitonce();
				
				if (submitonceVar)
				{
					return alertLostData ();
				}
				else
				{
					return submitonceVar;
				}*/
			}
			
			break
		
		case 'choice_continue':
			return submitonce();
			break
		
		case 'choice_new':
			return submitonce();
			break
		
		case 'docheckout':
			{
				if (validateCheckout ())
				{
					return submitonce();
				}
				else
				{
					return false;
				}
			}
			
			break
			
		case 'nsv':
			{
				if (validateStep11 ())
				{
					return submitonce();
				}
				else
				{
					return false;
				}
			}
			
			break
				
		default:
			return true;
	}
}
//all steps (disable submit buttons - prev, save, next) END

//Graduation Information
function checkSelectedCharsLimit (line, chars_num, limit_area)
{
	var line = document.getElementById (line);
    var limit_area = document.getElementById (limit_area);
        
    if (line && (line.selectedIndex != 0))
    {
        if (line.options[line.selectedIndex].text.length > chars_num)
        {
            line.selectedIndex = 0;
            limit_area.style.display = '';
        }
        else
        {
            limit_area.style.display = 'none';
        }
    }
}

//Graduation Information
function checkGradNameCharsLimit (chars_num, chars_str, limit_area_str, field, fnameLabel, mnameLabel, lnameLabel)
{
    var chars = document.getElementById (chars_str);
    var limit_area = document.getElementById (limit_area_str);
    
    //var graduate_title1 = document.getElementById ('graduate_title1');
    var fname = document.getElementById ('fname');
    var mname = document.getElementById ('mname');
    var lname = document.getElementById ('lname');
    var suffixes = document.getElementById ('suffixes');
    
    //if is called from field - trimming spaces
    if (field != '')
    {
        fieldManipulate (field, chars_str, chars_num);
    }
    
    //counting begin
    var count_chars = 0;
    
    //if (graduate_title1.selectedIndex != 0)
    //{
    //    count_chars = count_chars + graduate_title1.options[graduate_title1.selectedIndex].text.length + 1;
    //}
    
    if ((fname.value.length != 0) && (fname.value != fnameLabel))
    {
        count_chars = count_chars + fname.value.length + 1;
    }

    if ((mname.value.length != 0) && (mname.value != mnameLabel))
    {
        count_chars = count_chars + mname.value.length + 1;
    }
    
    if ((lname.value.length != 0) && (lname.value != lnameLabel))
    {
        count_chars = count_chars + lname.value.length;
    }
    
    if (suffixes.selectedIndex != 0)
    {
        count_chars = count_chars + 1 + suffixes.options[suffixes.selectedIndex].text.length;
    }
    
    if (count_chars > chars_num)
    {
        chars.value = chars_num - count_chars;//0;
        limit_area.style.display = '';
    }
    else
    {
        chars.value = chars_num - count_chars;
        limit_area.style.display = 'none';
    }
}

//Graduation Information
function checkLocationTimeCharsLimit (chars_num, chars_str, limit_area_str, field)
{
    var chars = document.getElementById (chars_str);
    var limit_area = document.getElementById (limit_area_str);
    
    var loc = document.getElementById ('location');
    var loc_own = document.getElementById ('location_own');
    var time = document.getElementById ('time');
    
    //if is called from field - trimming spaces
    if (field != '')
    {
        fieldManipulate (field, chars_str, chars_num);
    }
    
    //counting begin
    var count_chars = 0;
    var count_chars_loc = 0;
    var count_chars_time = 0;
    
    if (loc && !loc.disabled)//dropdown location
    {
	    if (loc.selectedIndex != 0)
	    {
	        count_chars_loc = loc.options[loc.selectedIndex].text.length;
	    }
    }
    else//text field location
    {
    	if (loc_own.value.length != 0)
	    {
	        count_chars_loc = loc_own.value.length;
	    }
    }
    
    if (time.selectedIndex != 0)//dropdown time
    {
        count_chars_time = time.options[time.selectedIndex].text.length;
    }
    
    if ((count_chars_loc != 0) && (count_chars_time != 0))
    {
    	count_chars = count_chars_loc + 1 + count_chars_time;
    }
    else
    {
    	count_chars = count_chars_loc + count_chars_time;
    }
    
    if (count_chars > chars_num)
    {
        chars.value = chars_num - count_chars;//0;
        limit_area.style.display = '';
    }
    else
    {
        chars.value = chars_num - count_chars;
        limit_area.style.display = 'none';
    }
}

//Graduation Information
//add 2nd Degree, Major, H/M sections
function show_dmh2_js()
{
	document.getElementById('show_dmh2').value = 1;
	document.getElementById ('section_dm2').style.display = '';
	document.getElementById ('section_h2').style.display = '';
	document.getElementById ('add_dmh2_link').style.display = 'none';
}

//Graduation Information
//remove 2nd Degree, Major, H/M sections
function remove_dmh2_js()
{
	document.getElementById('show_dmh2').value = 0;
	document.getElementById ('section_dm2').style.display = 'none';
	document.getElementById ('section_h2').style.display = 'none';
	document.getElementById ('add_dmh2_link').style.display = '';
}

//Graduation Information
//2nd Degree, Major, H/M section
/*function check2ndSections ()
{
	var optional = document.getElementById ('optional');
	
	var section_2nd_active = document.getElementById ('section_2nd_active');
	var section_2nd_readonly = document.getElementById ('section_2nd_readonly');
*/	
	/*var degree_two = document.getElementById ('degree_two');
	var degree_own_two = document.getElementById ('degree_own_two');
	var degree_own_two_tr = document.getElementById ('degree_own_two_tr');
	
	var major_two = document.getElementById ('major_two');
	var major_own_two = document.getElementById ('major_own_two');
	var major_own_two_tr = document.getElementById ('major_own_two_tr');
	
	var honors_minor_two = document.getElementById ('honors_minor_two');
	var honors_minor_two_own = document.getElementById ('honors_minor_two_own');
	var degree_own_two_tr = document.getElementById ('degree_own_two_tr');*/
	
	
/*	if (optional.selectedIndex != 0)//dropdown optional
    {
        section_2nd_active.style.display = '';
    	section_2nd_readonly.style.display = 'none';
*/    	
        /*degree_two.disabled = false;
        major_two.disabled = false;
        honors_minor_two.disabled = false;*/
/*    }
    else
    {
    	section_2nd_active.style.display = 'none';
    	section_2nd_readonly.style.display = '';
*/   	
    	/*degree_two.selectedIndex = 0;
        degree_two.disabled = true;
        degree_own_two.disabled = true;
        degree_own_two_tr.style.display = 'none';
        
        major_two.selectedIndex = 0;
        major_two.disabled = true;
        major_own_two.disabled = true;
        major_own_two_tr.style.display = 'none';
        
        honors_minor_two.selectedIndex = 0;
        honors_minor_two.disabled = true;
        honors_minor_two_own.disabled = true;
        major_own_two_tr.style.display = 'none';*/
/*    }
}
*/

//Graduation Information, Proof & Review dropdown's functions BEGIN
function js_dropdown(limit_main, key_string, limit_tr_string, own_tr_string, select_string, text_field_string, left_chars_string)
{
	switch(key_string)
	{
		case 'schools':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'schools_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'schools';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'school_own_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'school_own';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.grad_info.school_own.disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
		
		case 'degree_1':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'degree_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'degree';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'degree_own_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'degree_own';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
			
		case 'degree_2':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'degree_two_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'degree_two';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'degree_own_two_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'degree_own_two';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
		
		case 'major_1':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'major_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'major';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'major_own_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'major_own';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
		
		case 'major_2':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'major_two_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'major_two';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'major_own_two_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'major_own_two';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
		
		case 'honors_minor_1':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'honors_minor_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'honors_minor';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'honors_minor_own_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'honors_minor_own';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
		
		case 'honors_minor_2':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'honors_minor_two_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'honors_minor_two';
			var el_select_string = document.getElementById ( select_string );
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'honors_minor_two_own_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'honors_minor_two_own';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
			}
			else
			{
				checkSelectedCharsLimit(select_string, limit_main, limit_tr_string);
			}
			
			break
		
		case 'location':
			var limit_tr_string = typeof(limit_tr_string) != 'undefined' ? limit_tr_string : 'location_limit';
			var select_string = typeof(select_string) != 'undefined' ? select_string : 'location';
			var el_select_string = document.getElementById ( select_string );
			var left_chars_string = typeof(left_chars_string) != 'undefined' ? left_chars_string : 'location_own_chars';
			
			if (el_select_string.value == 'own')
			{
				var own_tr_string = typeof(own_tr_string) != 'undefined' ? own_tr_string : 'location_own_tr';
				var text_field_string = typeof(text_field_string) != 'undefined' ? text_field_string : 'location_own';
				
				el_select_string.selectedIndex = '0';
				el_select_string.disabled = true;
				document.getElementById ( own_tr_string ).style.display = '';
				document.getElementById ( text_field_string ).disabled = false;
				document.getElementById ( limit_tr_string ).style.display = 'none';
				checkLocationTimeCharsLimit(limit_main, left_chars_string, limit_tr_string, '');
			}
			else
			{
				checkLocationTimeCharsLimit(limit_main, left_chars_string, limit_tr_string, '');
			}
			
			break
	}
}
//Graduation Information, Proof & Review dropdown's functions END

/*
//Announcement Packages
var skusJS = new Array (new Array());
    
function checkSelectedSets (parent_pack, addSetSKU)
{
    var x = skusJS[parent_pack];
    var flag = false;
    var addEl = document.getElementById ('skus[' + parent_pack + '][' + addSetSKU + ']');
    
    for (var i = 0; i < x.length; i++)
    {
        var el = document.getElementById ('skus[' + parent_pack + '][' + x[i] + ']');
        
        if (el.options[el.selectedIndex].value != 0)
        {
            flag = true;
        }
    }
    
    if (flag)
    {
        addEl.disabled = false;
    }
    else
    {
        addEl.selectedIndex = 0;
        addEl.disabled = true;
    }
}
*/

//CHECK SELECTED PACKAGE'S SETS BEGIN
//Announcement Packages
var skusJS = new Array (new Array());
var JSvalue_parent_SKU = '';
var JSvalue_set_SKU = '';
    
function checkSelectedSets (parent_pack_sets, addSetSKU, parent_pack_addSetSKU)
{
    var x = skusJS[parent_pack_sets];
    var flag = false;
    var addEl = document.getElementById ('skus[' + parent_pack_addSetSKU + '][' + addSetSKU + ']');
    
    for (var i = 0; i < x.length; i++)
    {
        var el = document.getElementById ('skus[' + parent_pack_sets + '][' + x[i] + ']');
        
        if (el.options[el.selectedIndex].value != 0)
        {
            flag = true;
        }
    }
    
    if (flag)
    {
        addEl.disabled = false;
    }
    else
    {
        addEl.selectedIndex = 0;
        addEl.disabled = true;
    }
}

function checkSelectedSetsValue (addSetSKU, parent_pack_addSetSKU)
{
	var y = skusJS;
	var addEl = document.getElementById ('skus[' + parent_pack_addSetSKU + '][' + addSetSKU + ']');
	var disabled_flag = true;
    
    for (var key in y)
    {
    	if ((key + '') != 0)
    	{
    		checkSelectedSets (key, addSetSKU, parent_pack_addSetSKU)
    		
    		if (!addEl.disabled)
    		{
    			return;
    		}
    	}
    }
}
//CHECK SELECTED PACKAGE'S SETS END

//Steps: "Package upgrades", "The essentials" alerts BEGIN
function dropdownSelectAlert (key_string, elIdName)
{
	var el = document.getElementById (elIdName);
	
	if (el.options[el.selectedIndex].value != 0)
    {
        alerts (key_string);
    }
}

function alerts (key_string)
{
	switch(key_string)
	{
		case 'logo_alert':
			//alert ('Please select logo!');
			break
			
		case 'initials_alert':
			//alert ('Please fill the monogram field!');
			break
			
		case 'addr_logo_alert':
			//alert ('Please select logo and make sure the address fields are not empty!');
			//alert ('Please make sure the address fields are not empty!');
			break
			
		case 'addr_initials_alert':
			//alert ('Please fill the monogram field and make sure the address fields are not empty!');
			//alert ('Please fill the monogram field and make sure the address fields are not empty!');
			break
		
		case 'addr_alert':
			alert ('Please make sure the address fields are not empty!');
			break
	}
}
//Steps: "Package upgrades", "The essentials" alerts END

//Return address labels; Envelope Seals; Thank You Cards
function checkUpCheckbox (checkboxName, string_active, number_active, string_readonly, number_readonly)
{
	var ch = document.getElementById (checkboxName);
    
    if (ch.checked)
    {
        for (var i = 1; i <= number_readonly; i++)
        {
            var el_id = document.getElementById (string_readonly + i);
            el_id.style.display = 'none';
        }
        
        for (var i = 1; i <= number_active; i++)
        {
            var el_id = document.getElementById (string_active + i);
            el_id.style.display = '';
        }
    }
    else
    {
        for (var i = 1; i <= number_active; i++)
        {
            var el_id = document.getElementById (string_active + i);
            el_id.style.display = 'none';
        }
        
        for (var i = 1; i <= number_readonly; i++)
        {
            var el_id = document.getElementById (string_readonly + i);
            el_id.style.display = '';
        }
    }
}

//Return address labels; Envelope Seals; Thank You Cards
function additionalProductSections (checkboxId, sectionId)
{
	var ch = document.getElementById (checkboxId);
    var section = document.getElementById (sectionId);
    
    if (ch.checked)
    {
        section.style.display = '';
    }
    else
    {
        section.style.display = 'none';
    }
}

//Return address labels
function checkAddPrCheckbox (checkboxName, fieldIdName, fieldIdName2)
{
	var ch = document.getElementById (checkboxName);
    var el_id = document.getElementById (fieldIdName);
    
    if (fieldIdName2 != '')
    {
        var el_id2 = document.getElementById (fieldIdName2);
    }
    
    if (ch.checked)
    {
        el_id.style.display = 'none';
        
        if (fieldIdName2 != '')
        {
            el_id2.style.display = '';
        }
    }
    else
    {
        el_id.style.display = '';
        
        if (fieldIdName2 != '')
        {
            el_id2.style.display = 'none';
        }
    }
}

/*
//Certificate of Appreciation
function checkMainChangeFreeField (main, free)
{
	if (document.getElementById (main).value == '')
	{
		document.getElementById (free).readOnly = true;
	}
	else
	{
		document.getElementById (free).readOnly = false;
	}
}
*/

//Certificate of Appreciation
function chechCertFields()
{
	for ( var i = 0; i < cntArr; i++ )
  	{
  		if (document.getElementById ('arr[' + i + '][main]').value == '')
  		{
  			return false;
  		}
  		
  		if (document.getElementById ('arr[' + i + '][free]').value == '')
  		{
  			return false;
  		}
  	}
  	
  	return true;
}

//ADD Certificate of Appreciation BEGIN
//Certificate of Appreciation
function addRow (el, main_limit, text_field_size, tabindex, cert_class_key, href, arr_values)
{
 	var newRow1;
	var newRow2;
	var newCell1;
	var newCell2;
	var tbl = document.getElementById ('certificates');//id of the table
    var fields = new Array ();
    var main_v = '';
    var free_v = '';
    
    if (arr_values)
    {
    	main_v = arr_values[el]['main'];
    	free_v = arr_values[el]['free'];
    }
    
	fields [ 0 ] = new Array ();
 	fields [ 0 ][ 0 ] = '<nobr>' + cntTmp + ' Certificate $' + price + '</nobr>';
 	fields [ 0 ][ 1 ] = '<nobr>';
 	fields [ 0 ][ 1 ] += '<input tabindex="' + tabindex + '" name="arr[' + el + '][main]" id="arr[' + el + '][main]" class="textbox10grey" style="width: 222px" value="' + main_v + '" onkeyup="changeRemainingChars ( \'arr[' + el + '][main]\', \'main_chars' + el + '\', ' + main_limit + ' );" maxlength="' + main_limit + '" size="' + text_field_size + '" type="text">';
 	fields [ 0 ][ 1 ] += '&nbsp;<input tabindex="-1" name="main_chars' + el + '" id="main_chars' + el + '" class="textbox10grey" style="width: 14px" value="' + main_limit + '" size="3" maxlength="3" readonly="readonly" type="text">';
 	fields [ 0 ][ 1 ] += '&nbsp;&nbsp;<a tabindex="' + tabindex + '" class="px10_red" href="#' + href + '" onClick = "deleteRow(' + (el + 1) + ');">Remove</a>';
 	fields [ 0 ][ 1 ] += '<script>\n changeRemainingChars ( \'arr[' + el + '][main]\', \'main_chars' + el + '\', ' + main_limit + ' ); \n </script>';
 	fields [ 0 ][ 1 ] += '</nobr>';
    
    cntTmp += 1;
     
 	fields [ 1 ] = new Array ();
 	fields [ 1 ][ 0 ] = cntTmp + ' Certificate  (Free)';
	fields [ 1 ][ 1 ] = '<nobr>';
 	fields [ 1 ][ 1 ] += '<input tabindex="' + tabindex + '" name="arr[' + el + '][free]" id="arr[' + el + '][free]" class="textbox10grey" style="width: 222px" value="' + free_v + '" onkeyup="changeRemainingChars ( \'arr[' + el + '][free]\', \'free_chars' + el + '\', ' + main_limit + ');" maxlength="' + main_limit + '" size="' + text_field_size + '" type="text">';
 	fields [ 1 ][ 1 ] += '&nbsp;<input tabindex="-1" name="free_chars' + el + '" id="free_chars' + el + '" class="textbox10grey" style="width: 14px" value="' + main_limit + '" size="3" maxlength="3" readonly="readonly" type="text">';
 	fields [ 1 ][ 1 ] += '<script>\n changeRemainingChars ( \'arr[' + el + '][free]\', \'free_chars' + el + '\', ' + main_limit + '); \n </script>';
 	fields [ 1 ][ 1 ] += '</nobr>';
 	
 	newRow1 = tbl.insertRow (tbl.rows.length);
 	newRow1.className = arrClasses[cert_class_key];
 	newRow2 = tbl.insertRow (tbl.rows.length);
 	newRow2.className = arrClasses[cert_class_key];

    for (var j = 0; j < 2; j++)
    {
        newCell1 = newRow1.insertCell ( j );
        newCell2 = newRow2.insertCell ( j );
        //newCell.setAttribute ( 'className', '' );
        //newCell.setAttribute ( 'colSpan', '' );
        //newCell.setAttribute ( 'height', '' );
        newCell1.innerHTML = fields [ 0 ][ j ];
        newCell2.innerHTML = fields [ 1 ][ j ];
    }
    
    cntTmp += 1;
}

function addRows (brRows, main_limit, text_field_size, tabindex, href, arr_values)
{
	for ( var i = 0; i < brRows; i++ )
  	{
  		addRow (cntArr, main_limit, text_field_size, tabindex, nextClassKey, href, arr_values);
  		cntArr += 1;
  		if (nextClassKey == 0) {nextClassKey = 1;}
 		else {nextClassKey = 0;}
  	}
}

/*
function addRow (el, main_limit, text_field_size, tabindex)
{
 	var newRow1;
	var newRow2;
	var newCell1;
	var newCell2;
	var tbl = document.getElementById ('certificates');//id of the table
    var fields = new Array ();
     
 	fields [ 0 ] = new Array ();
 	fields [ 0 ][ 0 ] = '<nobr>' + cntTmp + ' Certificate $' + price + '</nobr>';
 	fields [ 0 ][ 1 ] = '<nobr>';
 	fields [ 0 ][ 1 ] += '<input tabindex="' + tabindex + '" name="arr[' + el + '][main]" id="arr[' + el + '][main]" class="textbox10grey" style="width: 222px" value="" onkeyup="changeRemainingChars ( \'arr[' + el + '][main]\', \'main_chars' + el + '\', ' + main_limit + ' ); checkMainChangeFreeField ( \'arr[' + el + '][main]\', \'arr[' + el + '][free]\' );" maxlength="' + main_limit + '" size="' + text_field_size + '" type="text">';
 	fields [ 0 ][ 1 ] += '&nbsp;<input tabindex="-1" name="main_chars' + el + '" id="main_chars' + el + '" class="textbox10grey" style="width: 14px" value="' + main_limit + '" size="3" maxlength="3" readonly="readonly" type="text">';
 	fields [ 0 ][ 1 ] += '<span class="header_table_blk">&nbsp;Available</span>';
 	fields [ 0 ][ 1 ] += '<script>\n changeRemainingChars ( \'arr[' + el + '][main]\', \'main_chars' + el + '\', ' + main_limit + ' ); \n </script>';
 	fields [ 0 ][ 1 ] += '</nobr>';
    
    cntTmp += 1;
     
 	fields [ 1 ] = new Array ();
 	fields [ 1 ][ 0 ] = cntTmp + ' Certificate  (Free)';
	fields [ 1 ][ 1 ] = '<nobr>';
 	fields [ 1 ][ 1 ] += '<input tabindex="' + tabindex + '" name="arr[' + el + '][free]" id="arr[' + el + '][free]" class="textbox10grey" style="width: 222px" value="" onkeyup="changeRemainingChars ( \'arr[' + el + '][free]\', \'free_chars' + el + '\', ' + main_limit + ');" maxlength="' + main_limit + '" size="' + text_field_size + '" type="text" readonly="readonly">';
 	fields [ 1 ][ 1 ] += '&nbsp;<input tabindex="-1" name="free_chars' + el + '" id="free_chars' + el + '" class="textbox10grey" style="width: 14px" value="' + main_limit + '" size="3" maxlength="3" readonly="readonly" type="text">';
 	fields [ 1 ][ 1 ] += '<span class="header_table_blk">&nbsp;Available</span>';
 	fields [ 1 ][ 1 ] += '<script>\n changeRemainingChars ( \'arr[' + el + '][free]\', \'free_chars' + el + '\', ' + main_limit + '); \n </script>';
 	fields [ 1 ][ 1 ] += '</nobr>';
 	newRow1 = tbl.insertRow (tbl.rows.length - 1);
 	newRow1.className='light-grey';
 	newRow2 = tbl.insertRow (tbl.rows.length - 1);

    for (var j = 0; j < 2; j++)
    {
        newCell1 = newRow1.insertCell ( j );
        newCell2 = newRow2.insertCell ( j );
        //newCell.setAttribute ( 'className', '' );
        //newCell.setAttribute ( 'colSpan', '' );
        //newCell.setAttribute ( 'height', '' );
        newCell1.innerHTML = fields [ 0 ][ j ];
        newCell2.innerHTML = fields [ 1 ][ j ];
    }
    
    cntTmp += 1;
}

function addRows (brRows, main_limit, text_field_size, tabindex)
{
	if (cntArr == 0 || chechCertFields())
	{
		for ( var i = 0; i < brRows; i++ )
	  	{
	  		addRow (cntArr, main_limit, text_field_size, tabindex);
	  		cntArr += 1;
	  	}
	}
	else
	{
		alert ('There are empty fields');
	}
}
*/
//ADD Certificate of Appreciation END

//DELETE Certificate of Appreciation BEGIN
//Certificate of Appreciation
function deleteRow (el)
{
	//get table data without the deleted element BEGIN
	var tbl = document.getElementById ('certificates');//id of the table
	var len = tbl.rows.length;
	var dataArr = new Array();
	var j = 0;
	
	for (var i = 1; i <= (len / 2); i++)
	{
		if (i == el)
		continue;
		
		var dataArrInner = new Array();
		dataArrInner['main'] = document.getElementById(eval("'arr[' + (i - 1) + '][main]'")).value;
		dataArrInner['free'] = document.getElementById(eval("'arr[' + (i - 1) + '][free]'")).value;
		dataArr[j] = dataArrInner;
		j++;
	}
	//get table data without the deleted element END
	
	/*
	//delete couple rows (main/free) BEGIN
	tbl.deleteRow ((el - 1)*2);
	tbl.deleteRow ((el - 1)*2);
	cntTmp -= 2;
	cntArr -= 1;
	//delete couple rows (main/free) END
	*/
	
	//delete all table rows BEGIN
	for (var i = 1; i <= (len); i++)
	{
		tbl.deleteRow (0);
	}
	//delete all table rows END
	
	//generate table rows BEGIN
	cntArr = 0;
	cntTmp = cntTmpFree + 1;
	nextClassKey = 0;
	
	addRows(dataArr.length, main_limit, text_field_size, tabindex, href, dataArr);
	//generate table rows END
}
//DELETE Certificate of Appreciation END

/*
//Graduation Information - change school alert + submit form on comfirm
function alertChangeSchool ()
{
	if (confirm ( 'If you continue your order will be reseted and you will lose order data.' +
   					'\nContinue?' ))
	{
   		document.getElementById('change_school').value = 1; document.grad_info.submit ();
	}
}
*/

//Graduation Information - forgot password alert + submit form on comfirm
function alertForgotPassword ()
{
	if (confirm ( 'This will generate a new password and send it to your e-mail address on file. Would you like to proceed?' ))
	{
   		document.getElementById('forgot_password').value = 1; document.grad_info.submit ();
	}
}

//Automatically Jumping To The Next Field BEGIN
var downStrokeField;

function autojump(fieldName, nextFieldName, fakeMaxLength)
{
	var myForm = document.forms[document.forms.length - 1];
	var myField = myForm.elements[fieldName];
	
	myField.nextField = myForm.elements[nextFieldName];
	
	if (myField.maxLength == null)
	{
		myField.maxLength = fakeMaxLength;
	}
	
	myField.onkeydown = autojump_keyDown;
	myField.onkeyup = autojump_keyUp;
}

function autojump_keyDown()
{
	this.beforeLength = this.value.length;
	downStrokeField = this;
}

function autojump_keyUp()
{
	if (
	   (this == downStrokeField) && 
	   (this.value.length > this.beforeLength) && 
	   (this.value.length >= this.maxLength)
	   )
	{
		this.nextField.focus();
	}
	
	downStrokeField = null;
}
//Automatically Jumping To The Next Field END

//Remove/Add field label BEGIN
function removeFieldLabel(fieldIdName, fieldLabel, classNameString)
{
	var el_id = document.getElementById (fieldIdName);
	
	if (el_id.value == fieldLabel){
	   el_id.className = classNameString;
	   el_id.value = '';
	}
}

function addFieldLable(fieldIdName, fieldLabel, classNameString)
{
	var el_id = document.getElementById (fieldIdName);
	
	if (el_id.value == ''){
	   el_id.className = classNameString;
	   el_id.value = fieldLabel;
	}
}
//Remove/Add field label END

//Shopping Cart Verification BEGIN
function echeck(str)
{
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	
	if (str.indexOf(at) == -1){
	   return "Invalid Email \n";
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr){
	   return "Invalid Email \n";
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr){
	    return "Invalid Email \n";
	}

	if (str.indexOf(at, (lat + 1)) != -1){
	    	return "Invalid Email \n";
	}

	if (str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot){
	    return "Invalid Email \n";
	}

	if (str.indexOf(dot, (lat + 2)) == -1){
	    return 'Invalid Email \n';
	}
	
	if (str.indexOf(" ") != -1){
		return 'Invalid Email \n';
	}
		return '';			
}
	
function validateForm ()
{
	var error = 0;
	var msg = "Error(s) found:\n";
	var school = document.getElementById ('school_name');
	var email = document.getElementById ('email');
	var confirm_email = document.getElementById ('confirm_email');
	
	if (!school.value)
	{
		error = 1;
		msg += ' - ' + "Please enter school name!\n";
	}
	
	if (email.value)
	{
		var check_email = echeck(email.value);
		
		if (check_email)
		{
			error = 1;
			msg += ' - ' + check_email;
		}
		else
		{
			if (email.value != confirm_email.value)
			{
				error = 1;
				msg += ' - ' + "Confirm My Email field didn't match My Email field!\n";
			}
		}
	}
	
	if (error)
	{
		alert (msg);
	}
	else
	{
		var form = document.getElementById ('theform');
		form.submit ();
	}
}

function changeColor (field_id)
{
	var field = document.getElementById(field_id);
	var container = document.getElementById('accept_proof_container');
	//alert (container.className);
	if (field.checked == true)
	{
		container.className='mandatory_filled';
	} 
	else
	{
		container.className='mandatory_empty';
	}
}

function validateCheckout ()
{
	var error = 0;
	var msg = "Error(s) found:\n";
	var checkout_form = document.getElementById ('checkout_form');

	var payment_type;
	
	var payment_type_phone = document.getElementById ('payment_type_phone');
	var payment_type_card = document.getElementById ('payment_type_card');
	var payment_type_echeck = document.getElementById ('payment_type_echeck');
	
	if (payment_type_echeck.checked)
	{
		payment_type = payment_type_echeck;
	}

	if (payment_type_card.checked)
	{
		payment_type = payment_type_card;
	}

	if (payment_type_phone.checked)
	{
		payment_type = payment_type_phone;
	}

	var cc_num = document.getElementById ('cc_num');
	var cc_cvv = document.getElementById ('cc_cvv');
	var ccexpMonth = document.getElementsByName ('cc_exp_Month')[0];
	var ccexpYear = document.getElementsByName ('cc_exp_Year')[0];
	var cc_card_holder = document.getElementById ('cc_card_holder');
	var cc_address1 = document.getElementById ('cc_address1');
	var cc_city = document.getElementById ('cc_city');
	var cc_zip = document.getElementById ('cc_zip');
	var cc_phone = document.getElementById ('cc_phone');
	var cc_state_id = document.getElementById ('cc_state_id');
	var email = document.getElementById ('email');


	if (payment_type.value)
	{
		switch(payment_type.value)
		{
			case 'card':
				if (!cc_num.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your credit card!\n";
				}
	
				if (!cc_cvv.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your cvv code!\n";
				}
				
				var today = new Date();
				var month = today.getMonth();
				month++;
				var year = today.getFullYear();
				
				if (!ccexpMonth.value || ccexpMonth.value == 0 )
				{
					error = 1;
					msg += ' - ' + "Please Select Expiration Date Month!\n";
				}
	
				if (!ccexpYear.value || ccexpYear.value == 0)
				{
					error = 1;
					msg += ' - ' + "Please Select Expiration Date Year!\n";
				}
				
				if (!error)
				{
					if (ccexpYear.value == year )
					{
						if (ccexpMonth.value < month )
						{
							error = 1;
							msg += ' - ' + "Your credit card is expired, please select a valid expiration date !\n";
						}
					}
					else if (ccexpYear.value < year )
					{
						error = 1;
						msg += ' - ' + "Your credit card is expired, please select a valid expiration date !\n";
					}
				}
				
				break
		  
			case 'echeck':
	
				var check_number = document.getElementById ('check_number');
				var bank_name = document.getElementById ('bank_name');
				var bank_address = document.getElementById ('bank_address');
				var bank_city = document.getElementById ('bank_city');
				var bank_state_id = document.getElementById ('bank_state_id');
				var routing_number = document.getElementById ('routing_number');
				var account_number = document.getElementById ('account_number');
				//var drivers_license  = document.getElementById ('drivers_license');
				//var drivers_license_state  = document.getElementById ('drivers_license_state');
				
				
				//if (drivers_license_state.value == 0)
				//{
				//	error = 1;
				//	msg += ' - ' + "Please select driver license state!\n";
				//}
	
				//if (!drivers_license.value)
				//{
				//	error = 1;
				//	msg += ' - ' + "Please enter driver license!\n";
				//}

				if (!check_number.value)
				{
					error = 1;
					msg += ' - ' + "Please enter check number!\n";
				}
				else if (!IsNumeric(check_number.value))
				{
					error = 1;
					msg += ' - ' + "Check number must be numeric value!\n";
				}
	
				if (!bank_name.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your bank name!\n";
				}
	
				if (!bank_address.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your bank address!\n";
				}
	
				if (!bank_city.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your bank city!\n";
				}
	
				if (bank_state_id.value == 0)
				{
					error = 1;
					msg += ' - ' + "Please select your bank state!\n";
				}

				if (!routing_number.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your bank routing number!\n";
				}
	
				
				if (!account_number.value)
				{
					error = 1;
					msg += ' - ' + "Please enter your bank account number!\n";
				}
				else if (!IsNumeric(account_number.value))
				{
					error = 1;
					msg += ' - ' + "Account number must be numeric value!\n";
				}
				else 
				{
					var strl = fitLengthInterval(account_number.value,5,25);
	
					if (strl == 'short')
					{
						error = 1;
						msg += ' - ' + "Account number must be numeric value 5 digits to 25 in length!\n";
					}
	
					if (strl == 'long')
					{
						error = 1;
						msg += ' - ' + "Account number must be numeric value 5 digits to 25 in length!\n";
					}
				}
				
				break

			case 'phone':
			  
			  break
		}
	}
	else
	{
		//error = 1;
		//msg += ' - ' + "Please choose payment method!\n";
	}
	
	
	if (!cc_card_holder.value)
	{
		error = 1;
		msg += ' - ' + "Please enter card holder!\n";
	}
	
	if (!cc_address1.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your address!\n";
	}
	
	if (!cc_city.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your city!\n";
	}
	
	if (!cc_zip.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your zip!\n";
	}
	
	if (!cc_state_id.value || cc_state_id.value == '0')
	{
		error = 1;
		msg += ' - ' + "Please select your billing state!\n";
	}
	
	if (isNaN(cc_phone.value))
	{
		error = 1;
		msg += ' - ' + "Please enter your phone!\n";
	}
	
	if (!email.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your email!\n";
	}
	
	
	if (error)
	{
		alert (msg);
		return false;
	}
	else
	{
		//testing validation
		//return false;
		//var form = document.getElementById ('theform');
		//form.submit ();
		return true;
	}
}

function validateStep11 ()
{
	var error = 0;
	var msg = "Error(s) found:\n";
	//var first_name = document.getElementById ('first_name');
	//var last_name = document.getElementById ('last_name');
	var ship_name = document.getElementById ('ship_name');
	var ship_address1 = document.getElementById ('ship_address1');
	var ship_city = document.getElementById ('ship_city');
	var ship_zip = document.getElementById ('ship_zip');
	var ship_phone = document.getElementById ('ship_phone');
	var ship_state_id = document.getElementById ('ship_state_id');
	
	
	
//	if (!first_name.value)
//	{
//		error = 1;
//		msg += ' - ' + "Please enter your first name!\n";
//	}
//	
//	if (!last_name.value)
//	{
//		error = 1;
//		msg += ' - ' + "Please enter your last name!\n";
//	}
	
	if (!ship_name.value)
	{
		error = 1;
		msg += ' - ' + "Please enter name!\n";
	}
	
	if (!ship_address1.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your shipping address!\n";
	}
	
	if (!ship_city.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your shipping city!\n";
	}
	
	if (!ship_zip.value)
	{
		error = 1;
		msg += ' - ' + "Please enter your shipping zip!\n";
	}
	
	if (isNaN(ship_phone.value))
	{
		error = 1;
		msg += ' - ' + "Please enter valid phone number!\n";
	}

	if (ship_state_id.value == 0)
	{
		error = 1;
		msg += ' - ' + "Please select your shipping state!\n";
	}

	
	
	if (error)
	{
		alert (msg);
		return false;
	}
	else
	{
		//var form = document.getElementById ('theform');
		//form.submit ();
		return true;
	}
}
//Shopping Cart Verification END


//Validation funcs

function IsNumeric(strString)
//  check for valid numeric strings	
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
	return blnResult;
}


function fitLengthInterval(strString,f,t)
//  check for valid numeric strings	
{
	if (strString.length < f) return "short";
	if (strString.length > t) return "long";
}

//empty basket alert
function alertEmptyBasket()
{
	alert ('Your cart is empty. Please return and add products to cart and continue.');
}

//custom alert window for left menu, "Return to Step..." BEGIN
var answerFunction;
var answerFunctionLink = '';
var answerFunctionButtonObj = '';

function myConfirm(text1, button1, text2, button2, text3, button3, answerFunc) {
	var box = document.getElementById("confirmBox");
	box.getElementsByTagName("span")[0].firstChild.nodeValue = text1;
	var boxBack = document.getElementById("confirmBoxBack");
	var button = box.getElementsByTagName("input");
	button[0].value = button1;
	
	//check if the button "save and continue" must exists BEGIN
	var submitflag = false;
	var show_save = document.getElementById("show_save");
	
	if ((show_save) && (show_save.value == 1)) {submitflag = true};
	/*
	var submits = document.getElementsByName("save");
	
	for(var i = 0; i < submits.length; i++)
	{
		if (submits[i].id == "save") {submitflag = true};
	}
	*/
	//check if the button "save and continue" must exists END
	
	if (!submitflag)
	{
		button[1].style.display = "none";
		box.getElementsByTagName("span")[1].firstChild.nodeValue = '';
	}
	else
	{
		button[1].style.display = "";
		button[1].value = button2;
		box.getElementsByTagName("span")[1].firstChild.nodeValue = text2;
	}
	
	button[2].value = button3;
	box.getElementsByTagName("span")[2].firstChild.nodeValue = text3;
	answerFunction = answerFunc;
	box.style.display = "block";
	boxBack.style.display = "block";
	
	//hide all select elements for IE6
	if (isIE6Browser())
	{
		var selects = document.getElementsByTagName("select");
		
		for(var i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility = "hidden";
		}
	}
}

function answer(response) {
	document.getElementById("confirmBox").style.display = "none";
	document.getElementById("confirmBoxBack").style.display = "none";
	
	//show all select elements for IE6
	if (isIE6Browser())
	{
		var selects = document.getElementsByTagName("select");
		
		for(var i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility = "visible";
		}
	}
	
	answerFunction(response);
}

//link (string) - URL direction;
//button (string) - if the function is called from button ("return to step" button) - the button name
function tester(link, buttonObj) {
	var confirmBoxText1 = 'Continue to the next page';
	var confirmBoxText2 = 'Save current page changes, then continue to the next page.'
		 + '\nYou may be prompted to complete required changes to the current page before continuing';
	var confirmBoxText3 = 'Stay on current page';
	answerFunctionLink = link;
	answerFunctionButtonObj = buttonObj;
	
	myConfirm(confirmBoxText1, "Continue", confirmBoxText2, "Save and Continue", confirmBoxText3, "Cancel",
			function (answer) {
				switch(answer)
				{
					case 1: //continue w/o saving
						
						if (answerFunctionLink != '')//if no direction - do nothing
						{
							if (answerFunctionButtonObj == '')//comes from link
							{
								window.location.replace(answerFunctionLink);
							}
							else//submit the form
							{
								if (submitFunc(answerFunctionButtonObj.name))
								{
									//submit the form with previus button
									var hiddenField = document.getElementById('h_' + answerFunctionButtonObj.name);
									hiddenField.value = 1;
									hiddenField.form.action = hiddenField.form.action + answerFunctionLink;
									hiddenField.form.submit();
								}
							}
						}
						
						break
					
					case 2: //save and continue
						
						if (answerFunctionLink != '')//if no direction - do nothing
						{
							if (submitFunc('save'))
							{
								//form submit will be with save button
								var hiddenField = document.getElementById('h_save');
								hiddenField.value = 1;
								
								//load link field with after save URL
								var hiddenURLField = document.getElementById('after_save_h');
								
								if (answerFunctionButtonObj == '')//comes from link
								{
									hiddenURLField.value = answerFunctionLink;
								}
								else//submit the form
								{
									hiddenURLField.value = (hiddenField.form.action + answerFunctionLink);
								}
								
								//form submit
								hiddenField.form.submit();
							}
						}
						
						break
				}
			}
	
	 );
	
	return false;
}
//custom alert window for left menu, "Return to Step..." END

//detect if the browser is IE6 BEGIN
function isIE6Browser()
{
	var isIE6 = false;
	
	if (navigator.appVersion.indexOf("MSIE") != -1)
	{
		temp = navigator.appVersion.split("MSIE");
		version = parseFloat(temp[1]);
		
		if (version == 6) {isIE6 = true;}
	}
	
	return isIE6;
}
//detect if the browser is IE6 END


function SA ()
{
	 
}

SA.prototype.make_request = function  (sUrl,type,Data,argument,params)
{
	
	var div = document.getElementById("testmsg");
	var handleSuccess = function(o){

		if(o.responseText !== undefined)
		{
			div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
			div.innerHTML += "<li>HTTP status: " + o.responseText + "</li>";
			//dereference the XHR instance.
			o.conn = null;
			//dereference the connection object.
			o = null;
		}
	};

	var handleFailure = function(o){
		if(o.responseText !== undefined){
			//div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
			//div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
			//div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
			//dereference the XHR instance.
			o.conn = null;
			//dereference the connection object.
			o = null;
		}
	};

	var callback =
	{
	  success:handleSuccess,
	  failure:handleFailure,
	  argument:argument
	};

	var request = YAHOO.util.Connect.asyncRequest(type, sUrl, callback, Data);
	
}


SA.prototype.make_post_request = function  (sUrl,Data,argument,params)
{
	SA.make_request (sUrl,'POST',Data,argument,params);
}

SA.prototype.make_get_request = function  (sUrl,Data,argument,params)
{
	SA.make_request (sUrl,'GET',Data,argument,params);
}

SA = new SA();

function sa_panel (panel_id,status_panel_id,sUrl,postData,argument,Timeout,params)
{
	var div = document.getElementById(panel_id);
	var divstatus = false;

	if (status_panel_id)
	{
		divstatus = document.getElementById(status_panel_id);
	}

	var handleSuccess = function(o)
	{
		if(o.responseText !== undefined)
		{
			div.innerHTML = o.responseText;
			
			//alert (o.responseText);
			
			if (divstatus)
			{
				divstatus.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
			}
			
			o.conn = null;
			//dereference the connection object.
			o = null;
		}
	};

	var handleFailure = function(o)
	{
		if(o.responseText !== undefined)
		{

			alert (o.statusText);
			div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
			div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
			div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";

			o.conn = null;
			//dereference the connection object.
			o = null;
		}
	};

	var callback =
	{
	  success:handleSuccess,
	  failure:handleFailure,
	  argument:argument
	};

	 //alert (sUrl);

	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, "");

	if (Timeout)
	{
		setTimeout("sa_panel ('"+panel_id+"','"+status_panel_id+"','"+sUrl+"','"+postData+"','"+argument+"',"+Timeout+",'"+params+"')",Timeout);
	}
	
}






function popup_spec_graphic(url,pos)
{
	var postData = "";

	SA.panel ("spec_graphic_popup_container","spec_graphic_popup_status",url,postData,"","","");
}



function alax_popup (url,param_str,container,status)
{
	var postData = "";
	//alert (url);alert (selected_spec_graphic_cat);
	sa_panel (container,status,url,postData,"","","");
}

function hide_all_dropdowns ()
{
	if (isIE6Browser())
	{
		var selects = document.getElementsByTagName("select");
	
		for(var i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility="hidden";
		}
	}
}

function show_all_dropdowns ()
{
	if (isIE6Browser())
	{
		var selects = document.getElementsByTagName("select");
	
		for(var i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility="visible";
		}
	}
}

//Discovering If Browser Accepts Cookies BEGIN
// Copyright 2002 Bontrager Connection, LLC
function DoTheCookieTest(div_cookie_yes, div_cookie_no)
{
	document.cookie = 'TemporaryTestCookie=yes; path=/';
	var divCookieYes = document.getElementById(div_cookie_yes);
	var divCookieNo = document.getElementById(div_cookie_no);
	
	setTimeout("TestIfCookieWasSet('" + divCookieYes.id + "', '" + divCookieNo.id + "')", 3000);
}

function TestIfCookieWasSet(div_cookie_yes, div_cookie_no)
{
	var testcookie = '';
	var divCookieYes = document.getElementById(div_cookie_yes);
	var divCookieNo = document.getElementById(div_cookie_no);
	
	if(document.cookie.length > 0)
	{
		var cookiename = 'TemporaryTestCookie=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		
		if(cookiebegin > -1)
		{
			cookiebegin += cookiename.length;
			cookieend = document.cookie.indexOf(";",cookiebegin);
			if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
			testcookie = document.cookie.substring(cookiebegin,cookieend);
		}
	}
	
	if(testcookie == 'yes')
	{
		/*alert('Yes, your browser accepted the test cookie.');*/
		divCookieYes.style.display="block";
	}
	else
	{
		/*alert('Your browser did not accept the test cookie.');*/
		divCookieNo.style.display="block";
	}
}
//Discovering If Browser Accepts Cookies END

//Diploma Frames
function showHideDFDetails (dropdownId, sectionId)
{
	var el = document.getElementById (dropdownId);
    var section_data = document.getElementById (sectionId + '_data');
    //var section_empty = document.getElementById (sectionId + '_empty');
    
    if (el.options[el.selectedIndex].value != 0)
    {
        section_data.style.display = '';
        //section_empty.style.display = 'none';
    }
    else
    {
        section_data.style.display = 'none';
        //section_empty.style.display = '';
    }
}

//JFC, Additional Memorabilia
function showHideDetailsArray(qty_id_array, sectionId)
{
	var flag = false;
    var section_data = document.getElementById (sectionId + '_data');
    
    for (var i = 0; i < qty_id_array.length; i++)
    {
    	var el = document.getElementById (qty_id_array[i]);
    	
    	if (el.options[el.selectedIndex].value != 0)
    	{
    		flag = true;
    	}
    }
    
    if (flag)
    {
        section_data.style.display = '';
    }
    else
    {
        section_data.style.display = 'none';
    }
}

function getEvalVar(varStr) {return eval(varStr);}

function setEvalVar(varStr, varValue) {eval(varStr + ' = ' + varValue);}

function utf8_url_encode(string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
	
    for (var n = 0; n < string.length; n++) {
		
        var c = string.charCodeAt(n);
		
        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }
    }
	
    return escape(utftext);
}