// new founction to message pop up
function MessagePopup(val)
{

	if(val=="ja-JP")
	{
	var vals = "送信に失敗しました。 しばらくしてから、もう一度やり直してください。 \n もしくは、一旦ブラウザを閉じ、初めからやり直してください。" ;
	alert(vals) ;
	}
	else if(val=="kr-KR")
	{
	var vals = "등록이 성공적으로 처리되지 않았습니다. 새로운 브라우저를 열어 다시 등록신청하여 주시기 바랍니다." ;
	alert(vals) ;
	}
	else if(val=="zh-HK")
	{
	var vals = "閣下所遞交之申請未能成功，請於稍後重試 / 關閉及重新開啟本瀏覽器。" ;
	alert(vals) ;
	}
	else if(val=="zh-TW")
	{
	var vals = "您的資料遞送失敗，請另外開啟新視窗重新填寫或請稍後再試." ;
	alert(vals) ;
	}
	else
	{
	var vals = "Your submission was not submitted successfully, please try again in a moment or close it and open new browser." ;
	alert(vals) ;
	}
					
}


// New Functions for Formlab 2.1
function checkLinkedFields(objCurrent, objLinked, objRow, valTrue)
{
	var disp = false;
	
	//alert(objCurrent.type);
	//alert(objLinked);
	
	// Because Javascript is case sensitive, we need to convert the values to lower / upper case first
	var valCurrent = objCurrent.value.toLowerCase();
	var valTrue = valTrue.toLowerCase();
		
	switch (objCurrent.type)
	{
	case "checkbox":
		// Will need to loop because checkbox can have multiple values, not like radio button
		var objChk;
		eval("objChk = document.formlabs." + objCurrent.name + ";");		
		for (i=0; i<objChk.length; i++)
		{
			if (objChk[i].checked && objChk[i].value.toLowerCase() == valTrue)
			{
				disp = true;
			}
		}
		break;
	case "select-one":
		if (valCurrent == valTrue)
			disp = true;
		break;
	case "radio":
		if (objCurrent.checked && valCurrent == valTrue)
			disp = true;
			
				
		break;
	default:
		alert('Not Implemented'); //objCurrent.type			
	}

	if (disp)
	{
		//alert('Visible');
		objRow.style.display = 'block';
		objRow.style.visibility = 'visible';
	}
	else
	{
		// No need to process if already hidden
		if (objRow.style.display != 'none') 
		{
			// Bembeng Arifin - Fix the logic, should be checking the type first
			// Reset / Clear the object values
			switch (objLinked.type)
			{
			case "select-one":
				objLinked.selectedIndex = -1;
				// Bembeng Arifin - 20070205 - fireEvent only for IE
				//objLinked.fireEvent("onchange");
				objLinked.onchange();
				break;
			case "text":
				objLinked.value = '';
				break;
			case "checkbox":
				var objMulti;
				eval("objMulti = document.formlabs." + objLinked.name + ";");	
				// Should only for Checkbox collection and Radio Button collection
				for (i=0; i<objMulti.length; i++)
				{
					objMulti[i].checked = false;
				}

				// Click on the first control to hide the child
				// Set true first as a decoy
				objMulti[0].checked = true;
				// And then the next click will remove the check value
				objMulti[0].click();
				break;
			case "radio":
				var objMulti;
				eval("objMulti = document.formlabs." + objLinked.name + ";");	
				// For radio, do a click to all of the option to reset the values, i know that this is an ugly thing to do, but it works :P
				for (i=0; i<objMulti.length; i++)
				{
					objMulti[i].click();
				}
				for (i=0; i<objMulti.length; i++)
				{
					objMulti[i].checked = false;
				}
				break;
			default:
				//alert('Should be only for Drop Down List and Text');			
				break;
			}					
			
			objRow.style.display = 'none';
			objRow.style.visibility = 'hidden';
		}				
	}
}
	
function addItemToArray(ar, v1, v2, v3)
{
	ar[ar.length] = new Array(v1, v2, v3);
}

function updateChildInformationArray(objHeader, objChild, objAr)
{
	
	//alert('test');
	// Reset Options
	objChild.options.length = 0;
	//alert('test1');
//	alert(objAr);
//	alert(objAr.length);
	
	// Get Header value
	var valParent = objHeader.value;

	if (valParent == "")
	{
		try
		{
			objChild.add(new Option("", ""), null);
		}
		catch (e)
		{
			objChild.add(new Option("", ""));
		}
	}
	for (i = 0; i < objAr.length; i++)
	{
		// Convention of the Array Objects
		// obj[x][0] -> Display Text
		// obj[x][1] -> Value
		// obj[x][2] -> Parent Value
		//alert(objAr[i][2]);
		//alert(valParent);
		if (objAr[i][2] == valParent || objAr[i][2] == "" || valParent == "" ) 
		{
		
				try
			{
				objChild.add(new Option(objAr[i][0], objAr[i][1]), null);	
			}
			catch (e)
			{
				objChild.add(new Option(objAr[i][0], objAr[i][1]));
			}
		}		
	}
}

function SearchPostalCode(PostalCodePage, objPostalCode, objAddress1, objAddress2, cc, locale)
{
	var width = 600;
	var height = 460;
	var top = (screen.availHeight - height) / 2;
	var left = (screen.availWidth - width) / 2;    
    
	var strUrl = PostalCodePage + '?locale='+locale+'&cc='+cc+'&pos='+objPostalCode.id+'&add1='+objAddress1.id+'&add2='+objAddress2.id;
	var strWinName = 'Postal';
	var strFeatures = 'width='+width+',height='+height+',top='+top+',left='+left+',location=0,menubar=0,resizeable=0,scrollbars=0,status=0,titlebar=1';
	
	var mypopup = window.open(strUrl, strWinName, strFeatures);	
	
	//alert('test');
	/*
	if (window.showModalDialog)
	{
		var rtn = window.showModalDialog('PostalCode.htm', cc, "dialogHeight:470px;dialogWidth:600px");
		if (rtn)
		{
			try
			{
				objPostalCode.value = rtn[0];
				objAddress1.value = rtn[1];
				objAddress2.value = rtn[2];
			}
			catch(ex)
			{
				alert(ex);
			}
		}
	}
	else
	{
		alert('Not Supported');
	}
	*/	
	
}



//Added on 2-5-2007 - abdul
// This is being used for the printerfriendly() function, we put this here so this function can be shared for all the locales
function preparePrintableVersionUrl()
{	
	try
	{
		// ReConstruct the URL
		var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
		// Get the query string
		var qry = window.location.search;		
		// Remove Preview flag and encode the URL
		return url + escape(qry.replace('preview=1', ''));	
	}
	catch(e)
	{
		// Return the original url if encounter any error
		return window.location.href;
	}	
}

