
function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function MaskedTextBox_CreateItem(id, mask, validationExpression, autoFillMask) {
    this.Id = id;
    this.Mask = mask;
    this.ValidationExpression = validationExpression;
    this.AutoFillMask = autoFillMask;
    this.CurrentValue = document.getElementById(id).value;
}

function MaskedTextBox_FindItem(id) {
   if (eWorld_MaskedTextBox_Items == null) {
      return null;
   }
   
   for (var i=0; i<eWorld_MaskedTextBox_Items.length; i++) {
      if (eWorld_MaskedTextBox_Items[i].Id == id) {
         return eWorld_MaskedTextBox_Items[i];
      }
   }
}

function MaskedTextBox_AutoFillBox(keyCode, box, item, fromInput) {
    var addedCharacter = fromInput;
    var returnValue = true;
    
    if (item.AutoFillMask) {
    
        var nextMaskChar = MaskedTextBox_GetNextMaskCharacter(box, item, addedCharacter);
        
        while (nextMaskChar != '') {                       
            // check to see if the next mask character is an alpha/numeric character
            if (nextMaskChar.toLowerCase() == '9' || nextMaskChar.toLowerCase() == 'c' || nextMaskChar.toLowerCase() == 'x' || (box.value.length == item.Mask.length)) {
                break;
            }
            
            // if the next character is not alpha or numeric, add it to the value
            var nextCharCode = nextMaskChar.toLowerCase().charCodeAt(0);            
            if ((nextCharCode != 57) && ((nextCharCode < 48) || (nextCharCode > 57)) && (nextCharCode != 99)) {
                if (!addedCharacter && keyCode != -999) {
                    box.value = box.value + String.fromCharCode(keyCode) + nextMaskChar;
                    returnValue = false;
                    addedCharacter = true;
                } else {
                    box.value = box.value + nextMaskChar;
                }
            }
            
            nextMaskChar = MaskedTextBox_GetNextMaskCharacter(box, item, addedCharacter);
        }
    }
    
    return returnValue;
}

function MaskedTextBox_GetNextMaskCharacter(box, item, addedCharacter) {
    var nextMaskChar = '';
    
    if ((box.value.length + 1) <= item.Mask.length) {
        if (box.value.length == 0) {
            nextMaskChar = item.Mask.charAt(0);
        } else {
            if (addedCharacter) {
               nextMaskChar = item.Mask.charAt(box.value.length);
            } else {
               nextMaskChar = item.Mask.charAt(box.value.length + 1);
            }
        }
    }
    
    return nextMaskChar;
}

function MaskedTextBox_InitializeCompatibility() {
   if (typeof(eWorld_UI_MaskedTextBoxes) != 'undefined') {
      for (var i=0; i<eWorld_UI_MaskedTextBoxes.length; i++) {
         var element = document.getElementById(eWorld_UI_MaskedTextBoxes[i]);
         eWorld_MaskedTextBox_Items[i] = eval(element.maskedTextBox);
      }
   }
}

function MaskedTextBox_FocusMask(box, id) {
    var item = MaskedTextBox_FindItem(id);
    
    if (box.value != '') {        
        // attempt to move the cursor at the end of the input characters
        var length = box.value.length;
        box.focus();
        box.setSelectionRange(length, length)
    }
}

function MaskedTextBox_VerifyMask(e, box, id) {
    var item = MaskedTextBox_FindItem(id);
    var keyCode = e.which;
    
    if (box.value == '' && item.AutoFillMask && item.Mask.length != 0 && keyCode != 13 && keyCode != 8 && keyCode != 0) {
      MaskedTextBox_AutoFillBox(-999, box, item, false);
    } else if (box.value != '' && item.AutoFillMask && item.Mask.length != 0 && keyCode != 13 && keyCode != 8 && keyCode != 0) {
      MaskedTextBox_AutoFillBox(-999, box, item, true);
    }
    
    var currentValue = box.value;
    var returnValue = false;
    
    if (item.Mask.length == 0 || keyCode == 13 || keyCode == 8 || keyCode == 0) {
        returnValue = true;
    } else {
        var maskChar = item.Mask.substr(currentValue.length, 1);
         
        // determine if what was typeed is the valid next mask character       
        if ((maskChar.charCodeAt(0) == 57  || maskChar.toLowerCase().charCodeAt(0) == 120) && (keyCode >= 48) && (keyCode <= 57)) { // digit
            returnValue = true;
        } else if (e.ctrlKey && keyCode == 118) {
            returnValue = true;
        } else if ((maskChar.toLowerCase().charCodeAt(0) == 99  || maskChar.toLowerCase().charCodeAt(0) == 120) && (((keyCode >= 65) && (keyCode <=90)) || ((keyCode >= 97) && (keyCode <= 122)))) { // character
            returnValue = true;
        } else if (maskChar == String.fromCharCode(keyCode)) { // special
            returnValue = true;
        } else { // no match
            returnValue = false;
        }
        
        if (returnValue) {
            if (box.value.length == 0) {
               box.value += String.fromCharCode(keyCode);
               returnValue = MaskedTextBox_AutoFillBox(keyCode, box, item, true);
               returnValue = false;
            } else {
               returnValue = MaskedTextBox_AutoFillBox(keyCode, box, item, false);
            }
        }
    }
    
    if (!returnValue) {
        e.preventDefault();
    }
    
    return returnValue;
}

function MaskedTextBox_Change(box, id) {
    var item = MaskedTextBox_FindItem(id);
    var returnValue = false;
    
    if (item.ValidationExpression.length > 0) {
        eval("var re = /" + item.ValidationExpression + "/;");
        if (re.test(box.value)) {
            returnValue = true;
        }
    } else {
        returnValue = true;
    }
    
    if (!returnValue) {
        box.value = item.CurrentValue;   
    } else {
        item.CurrentValue = box.Value;
    }
    
    return returnValue;
}



//var eWorld_MaskedTextBox_Items =  new Array(new MaskedTextBox_CreateItem('dayphone', "(999) 999-9999", "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}", true), new //MaskedTextBox_CreateItem('evephone', "(999) 999-9999", "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}", true));

//----------- This function returns all the countries listed in index, registration and learn more page --------#
function GetCountries(formName, fieldName, urlGetCountry)
{
	xmlHttp = getHttpRequestObject();
	if (xmlHttp) 
	{
		xmlHttp.open('POST', urlGetCountry, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4)  
			{				
				if (xmlHttp.status == 200)
				{					
					var result = xmlHttp.responseText;
					if (result==0)
					{
						alert('No Countries available to display');
						document.formName.fieldName.options.length=0;
					}
					else
					{
						arr = result.split(":");
						fieldName.options.length=0;
						fieldName.options[0] = new Option('Select one..','');
						for(i=0,j=1;i<arr.length-1;i++,j++)
						{
							brr = arr[i].split("=");
							fieldName.options[j] = new Option(brr[1], brr[0]);
						}
					}
					xmlHttp.abort();
					return false;
				}
			}
		}
		xmlHttp.send(null);
	}
}

//----------- This function returns all the state list required on index page --------#
function GetStates(formName, fieldName, urlGetState)
{
	xmlHttp = getHttpRequestObject();
	if (xmlHttp) 
	{			
		xmlHttp.open('POST', urlGetState, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4)  
			{
				if (xmlHttp.status == 200)
				{
					var result = xmlHttp.responseText;
					if (result==0)
					{
						alert('No Countries available to display');
						document.formName.fieldName.options.length=0;
					}
					else
					{
						arr = result.split(":");
						fieldName.options.length=0;
						fieldName.options[0] = new Option('-- Any --','');
						for(i=0,j=1;i<arr.length-1;i++,j++)
						{
							brr = arr[i].split("=");
							fieldName.options[j] = new Option(brr[1], brr[0]);
						}
					}
					xmlHttp.abort();
					return false;
				}
			}
		}
		xmlHttp.send(null);
	}
}

//--------- This function returns all the state fro a country. Required on fill_application_form.tpl --------#
function populateState(id, urlGetState, frmName)
{	

	if(id == '')
	{
		//alert('Please choose country');
		document.getElementById(frmName).country.focus();		
	}
	document.getElementById(frmName).state.options.length=0;
	document.getElementById(frmName).state.options[0] = new Option('Loading ...', '');
	
	urlGetState += "country_id="+id;
	if (xmlHttp) 
	{
		xmlHttp.open('POST', urlGetState, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4)  
			{				
				if (xmlHttp.status == 200)
				{
					var result = xmlHttp.responseText;
					if (result==0)
					{
						alert('This country doesnt have any state');
						document.getElementById(frmName).state.options.length=0;
					}
					else
					{
						arr = result.split(":");
						document.getElementById(frmName).state.options.length=0;
						for(i=0;i<arr.length-1;i++)
						{
							brr = arr[i].split("=");
							document.getElementById(frmName).state.options[i] = new Option(brr[1], brr[0]);
						}
					}
					xmlHttp.abort();
					return false;
				}
			}
		}
		xmlHttp.send(null);
	}
}







function validateField(user) {
  	xmlHttp = getHttpRequestObject();
	//alert('xmlHttp');
	if (xmlHttp) 
	{
		xmlHttp.abort();
  		xmlHttp.open("GET", "../include/validateField.php?gradYearValue=" + user, true);
  		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState == 4) {
				document.getElementById('hsgradYear').innerHTML = xmlHttp.responseText;
			}
  		}
 		xmlHttp.send(null);
	}
}






function showResetForm2(value)
{
	//alert('here');
	if(value == 1)
	{
		document.getElementById('resetForm').style.display='block';
	}
	else
	{
		document.getElementById('resetForm').style.display='none';
	}
}

function showResetForm()
{
	var response = confirm('Are you sure you want to reset your search criteria?');
	
	if(response == true)
	{
		window.location = "http://dotschools.com/index.php?reset=1";
	}
}

function submitResetForm(value)
{
	if(value == 'no')
	{
		document.getElementById('resetForm').style.display = 'none';
	}
	else
	{
		window.location = "index.php?reset=1";
	}
}

function submitFormTop2()
{
	document.formTop.submit();
	/*alert('here');
	if(type == 'state')
	{
		redirecturl = url + document.formTop.stateTop.value + '-.html';
	}
	else
	{
		redirecturl = url + document.formTop.zipTop.value + '.html';
	}
	window.location = redirecturl;*/
}

function submitFormTop(type,url)
{
	//document.formTop.submit();
	//alert('here');
	if(type == 'state')
	{
		redirecturl = url + document.formTop.stateTop.value + '-degree.html';
	}
	else
	{
		redirecturl = url + document.formTop.zipTop.value + '-degree.html';
		
	}
	
	
	window.location = redirecturl;
}

/*
function extrafieldMask(collegeID2)
{
	if(collegeID2 >= 85059 && collegeID2 <= 85073)
	{	
		oStringMask = new Mask("###-###-####")
		oStringMask.attach(document.frmMore['custom[extrafield1]']);
		//oStringMask.attach(document.frmMore.evephone);
	}
}
*/
