﻿/*
    Reflect the values from 'source' to 'toElement'
*/
function reflectValue(source, toElement)
{
	//var source = document.getElementById(fromElement);
	var destination = document.getElementById(toElement);
	
	if (source != null && destination != null)
	{
		destination.innerHTML = source.value;
	}
}

/*
	Custom validator for checkbox
*/
function validateCheckBox(chk, error)
{
	var checkbox = document.getElementById(chk);
	
	if (checkbox != null && Page_IsValid)
	{
		if (!checkbox.checked)
		{
			alert(error);
		}
		
		return checkbox.checked;
	}
	
	return false;
}

function showDialog(page)
{
	window.open(page, "NewWindow", "height=450,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no", true);
}


function showCurrentlyEmployedSection(radioList, row1, row2, textbox1, textbox2)
{
	var radios = document.getElementsByName(radioList);
	var firstRow = document.getElementById(row1);
	var secondRow = document.getElementById(row2);
	var tb1 = document.getElementById(textbox1);
	var tb2 = document.getElementById(textbox2);
	var index = 0;
	
	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		index = 1;
	}
	
	if (radios[index].checked)
	{
		firstRow.className = "visible";
		secondRow.className = "visible";
		tb1.className = "visible";
		tb2.className = "visible";
		tb1.focus();
	}
	else
	{
		firstRow.className = "hidden";
		secondRow.className = "hidden";
		tb1.className = "hidden";
		tb2.className = "hidden";
	}
}

//
// Show/Hide additional information row
//
function toggleAdditionalInfoRow(ddl, row, ddlAddiInfo, ddlAddiInfo2, ddlAddiInfo3, ddlAddiInfo4, textbox)
{
	var ddlHowYouFindOut = ddl;
	var additionalRow = document.getElementById(row);
	var ddlAdditionalInfo = document.getElementById(ddlAddiInfo);
	var ddlAdditionalInfo2 = document.getElementById(ddlAddiInfo2);
	var ddlAdditionalInfo3 = document.getElementById(ddlAddiInfo3);
	var ddlAdditionalInfo4 = document.getElementById(ddlAddiInfo4);
	var txtAdditionalInfo = document.getElementById(textbox);
	var label = document.getElementById("lblAdditionalInfo");
	
	if (ddlHowYouFindOut != null)
	{
		var selectedIndex = ddlHowYouFindOut.selectedIndex;
		
		if (selectedIndex == 2 || selectedIndex == 4 || selectedIndex == 5 ||
		   selectedIndex == 8 || selectedIndex == 9 || selectedIndex == 10 ||
		   selectedIndex == 11 || selectedIndex == 12 || selectedIndex == 13 || selectedIndex == 14 )
		{
			
			if (selectedIndex == 2)
			{
				if (label != null)
				{
					label.innerText = "新聞・雑誌の名前を記入してください";
				}
			}
			else if (selectedIndex == 4)
			{
				if (label != null)
				{
					label.innerText = "サイト名を記入してください";
				}
			}
			else if (selectedIndex == 5)
			{
				if (label != null)
				{
					label.innerText = "大学・学校名を記入してください";
				}
			}
			else if (selectedIndex == 8)
			{
				if (label != null)
				{
					label.innerText = "掲示板・BBSの名前を選んでください";
				}
			}
			else if (selectedIndex == 9)
			{
				if (label != null)
				{
					label.innerText = "サイト名を記入してください";
				}
			}else if (selectedIndex == 10)
			{
				if (label != null)
				{
					label.innerText = "紹介者の評価員コード（半角数字１０ケタ）をご記入ください";
				}
			}
			else if (selectedIndex == 11)
			{
				if (label != null)
				{
					label.innerText = "バナーを見たページを記入してください";
				}
			}
			else if (selectedIndex == 12)
			{
				if (label != null)
				{
					label.innerText = "ダイレクトメールの送り主・題名を記入してください";
				}
			}
			else if (selectedIndex == 13)
			{
				if (label != null)
				{
					label.innerText = "ちらし・郵便物の種別、受け取った日を記入してください";
				}
			}
			else if (selectedIndex == 14)
			{
				if (label != null)
				{
					label.innerText = "どちらでお知りになったか具体的にご記入ください";
				}
			}
			
			// Display TextBox
			additionalRow.className = "visible";
			txtAdditionalInfo.className = "visible";
			ddlAdditionalInfo.className = "hidden";
			ddlAdditionalInfo2.className = "hidden";
			ddlAdditionalInfo3.className = "hidden";
			ddlAdditionalInfo4.className = "hidden";
			txtAdditionalInfo.focus();
		}
		else if (selectedIndex == 1  )
		{
			label.innerText = "求人サイトを選んでください";
			
			// Display DropDownList
			additionalRow.className = "visible";
			txtAdditionalInfo.className = "hidden";
			ddlAdditionalInfo.className = "visible";
			ddlAdditionalInfo2.className = "hidden";
			ddlAdditionalInfo3.className = "hidden";
			ddlAdditionalInfo4.className = "hidden";
			ddlAdditionalInfo.focus();
		}
		else if (selectedIndex == 6)
		{
			label.innerText = "サイト名を選んでください";
			// Display DropDownList
			additionalRow.className = "visible";
			txtAdditionalInfo.className = "hidden";
			ddlAdditionalInfo.className = "hidden";
			ddlAdditionalInfo2.className = "hidden";
			ddlAdditionalInfo3.className = "hidden";
			ddlAdditionalInfo4.className = "visible";
			ddlAdditionalInfo4.focus();
		}		
		else if (selectedIndex == 3)
		{
			label.innerText = "どこでお知りになりましたか";
			// Display DropDownList
			additionalRow.className = "visible";
			txtAdditionalInfo.className = "hidden";
			ddlAdditionalInfo.className = "hidden";
			ddlAdditionalInfo2.className = "visible";
			ddlAdditionalInfo3.className = "hidden";
			ddlAdditionalInfo4.className = "hidden";
			ddlAdditionalInfo2.focus();
		}
		else if (selectedIndex == 7 )
		{
			label.innerText = "サーチエンジン名を選んでください";
			// Display DropDownList
			additionalRow.className = "visible";
			txtAdditionalInfo.className = "hidden";
			ddlAdditionalInfo.className = "hidden";
			ddlAdditionalInfo2.className = "hidden";
			ddlAdditionalInfo3.className = "visible";
			ddlAdditionalInfo4.className = "hidden";
			ddlAdditionalInfo3.focus();
		}
		else
		{
			additionalRow.className = "hidden";
			txtAdditionalInfo.className = "hidden";
			ddlAdditionalInfo.className = "hidden";
			ddlAdditionalInfo2.className = "hidden";
			ddlAdditionalInfo3.className = "hidden";
			ddlAdditionalInfo4.className = "hidden";

		}
	}
}

//
// Checks if the post code textbox is empty when 
// user clicks the Get Address button
//
function validateGetAddressButton(postCode1, postCode2, errorMsg)
{
	var txtPostCode1 = document.getElementById(postCode1);
	var txtPostCode2 = document.getElementById(postCode2);
	
	if (txtPostCode1 != null && txtPostCode1.value.length > 0 &&
		txtPostCode2 != null && txtPostCode2.value.length > 0)
	{
		// if postcode is entered, check the format
		// the format has to be XXX-XXXX
		var value = txtPostCode1.value + "-" + txtPostCode2.value;
		var regex = /\d{3}-\d{4}/;
		if (value.match(regex))
		{
			return true;
		}
		else
		{
			alert(errorMsg);
		}
	}
	else
	{
		alert(errorMsg);
	}
	
	return false;
}


/*
	Custom validator for validating checkbox list
*/
function validateCheckBoxList(source, args)
{
	var checkBoxListTable = document.getElementById("trainCompaniesCheckBoxList");
	
	if (checkBoxListTable != null)
	{
		var checkboxes = checkBoxListTable.getElementsByTagName("input");
		
		if (checkboxes != null && checkboxes.length > 0)
		{
			for (var i = 0; i < checkboxes.length; i++)
			{
				if (checkboxes[i].type == "checkbox" && checkboxes[i].checked)
				{
					args.IsValid = true;
					return true;
				}
				else
				{
					args.IsValid = false;
				}
			}
			
			return false;
		}
		else
		{
			args.IsValid = false;
			return false;
		}
	}
	else
	{
		args.IsValid = false;
		return false;
	}
	
	
}

/*
	Custom client side validator for checkbox
*/
function validateTermsCheckbox(sender, args)
{
	var checkbox = document.getElementById("acceptTermsAndConditionsCheckbox");
	
	if (checkbox != null)
	{
		if (checkbox.checked)
		{
			args.IsValid = true;
			return true;
		}
		else
		{
			args.IsValid = false;
			return false;
		}
	}
}

/*
	Custom client-side validator for the postcode field.
	Validate the postcode field.
*/
function validatePostCode(source, args)
{
	var postCode1 = document.getElementById("txtWorkPostCode1");
	var postCode2 = document.getElementById("txtWorkPostCode2");
	var value="";
	
	if (postCode1 != null && postCode2 != null)
	{
		if (postCode1.value == "" && postCode2.value == "")
		{
			return true;
		}
		
		value = postCode1.value + "-" + postCode2.value;
	}
	
	
	
	if (ValidatorTrim(value).Length != 0)
	{
		var regex = /\d{3}-\d{4}/;
		if (value.match(regex))
		{
			args.IsValid = true;
			return true;
		}
		else
		{
			args.IsValid = false;
			return false;
		}
	}
	else
	{
		args.IsValid = false;
		return false;
	}
}

/*
	Show/Hide employed with row
*/
function toggleEmployedWith(radioList, rowID, textbox)
{
	var row = document.getElementById(rowID);
	var tb = document.getElementById(textbox);
	var radios = document.getElementsByName(radioList);
	var index = 0; // index for the Yes item
	
	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		index = 1; // For IE, index for YES item is 1.
	}
	
	if (radios[index].checked)  // Yes
	{
		if (row != null)
		{
			row.className = "visible";
			if (tb != null) 
			{
				tb.className = "visible";
				tb.focus();
			}
		}
	}
	else // No
	{
		if (row != null)
		{
			row.className = "hidden";
			if (tb != null) 
			{
				tb.className = "hidden";
			}
		}
	}
}

function hideEmployedWith(rowID)
{
	var row = document.getElementById(rowID);
	
	if (row != null)
	{
		row.className = "hidden";
	}
}

function limitTextArea(textbox, size)
{
	if (textbox != null)
	{
		if (event.keyCode == 8 || event.keyCode == 46 || (event.keyCode >= 35 && event.keyCode <= 40))
		{
			event.returnValue = true;
		}
		else if (textbox.value.length >= size && (event.keyCode != 8 || event.keyCode != 46))
		{
			event.returnValue = false;
		}
	}
}

function acceptTermsAndCondition(checkbox, message)
{
	var termsAndConditionCheckbox = document.getElementById(checkbox);
	
	if (!termsAndConditionCheckbox.checked)
	{
		alert(message);
		return false;
	}
}

function emptyTextBoxesOnPostCodeChange()
{
	var stateRow = document.getElementById("stateRow");
	var cityRow = document.getElementById("cityRow");
	var street1Row = document.getElementById("street1Row");
	var street2Row = document.getElementById("street2Row");
	var street3Row = document.getElementById("street3Row");
	var homePhoneRow = document.getElementById("homePhoneRow");
	var workPhoneRow = document.getElementById("workPhoneRow");
	var mobileRow = document.getElementById("mobileRow");
	var faxRow = document.getElementById("faxRow");
	var emailRow = document.getElementById("emailRow");
	var emailConfirmRow = document.getElementById("emailConfirmRow");
	var mobileEmailRow = document.getElementById("mobileEmailRow");
	var mobileEmailConfirmRow = document.getElementById("mobileEmailConfirmRow");
	var lblContactInfo = document.getElementById("lblContactInfo");
	
	var txtState = document.getElementById("txtState");
	var txtCity = document.getElementById("txtCity");
	var ddlStreet1 = document.getElementById("ddlStreet1");
	
	txtState.value = "";
	txtCity = "";
	for (var i = 0; i < ddlStreet1.options.length; i++)
	{
		ddlStreet1.options[i] = null;
	}
	
	stateRow.style.display = "none";
	cityRow.style.display = "none";
	street1Row.style.display = "none";
	street2Row.style.display = "none";
	street3Row.style.display = "none";
	homePhoneRow.style.display = "none";
	workPhoneRow.style.display = "none";
	mobileRow.style.display = "none";
	faxRow.style.display = "none";
	emailRow.style.display = "none";
	emailConfirmRow.style.display = "none";
	mobileEmailRow.style.display = "none";
	mobileEmailConfirmRow.style.display = "none";
	lblContactInfo.style.display = "none";
}

function emptyTrainCheckBoxListOnPostCodeChange()
{
	var checkboxListTable = document.getElementById("trainCompaniesCheckBoxList");
	
	//alert(checkboxListTable);
	
	if (checkboxListTable != null)
	{
		var count = checkboxListTable.rows.length;
		for (var i = 0; i < count; i++)
		{
			checkboxListTable.deleteRow(0);
		}
	}
}

function checkConfirmationEmail(email1, email2, message)
{
	var email = document.getElementById(email2);
	var confirm = document.getElementById(email1);
	
	if (Page_IsValid && email.value != confirm.value)
	{
		alert(message);
		confirm.focus();
	}
}

function focusConfirmTextbox(email)
{
	var emailTextBox = document.getElementById(email);
	emailTextBox.focus();
}

/*
 Smart Navigation
*/
function smartNavigationHandler()
{
 var position;
 var scrollPosition = document.getElementById("scrollPosition");
 
 if (document.body != null && document.body.scrollTop)
 {
  position = document.body.scrollTop;
 }
 else
 {
  position = window.pageYOffset;
 }
 
 if (position != null && scrollPosition != null)
 {
  scrollPosition.value = position;
 }
}
 
/*
 
 Restore the last scroll position.
*/
function restoreScrollPosition()
{
 var scrollPosition = document.getElementById("scrollPosition");
 
 if (scrollPosition != null && scrollPosition.value != null && scrollPosition.value.length > 0)
 {
  window.scrollTo(0, scrollPosition.value);
 }
 else
 {
  window.setTimeout("restoreScrollPosition()", 150);
 }
}

