function checkURL()
{
	var curHost = window.location.hostname.toLowerCase(); // Current Host Name	
	var curProtocol = window.location.protocol.toLowerCase(); // Current Host Name	
	//var waitSeconds = 10000; // 10 seconds before redirected
		
	if (curProtocol == 'http:') //h50043.www5.hp.com
	{
		//tblNote.style.display = 'block';
		//self.setTimeout("redirectNew()", waitSeconds)
		redirectNew();
	}
}

function redirectNew()
{
	var newHost = 'https://h50043.www5.hp.com';	// New Admin site
	var curPath = window.location.pathname;
	var newUrl = newHost + curPath;
	
	window.location.href = newUrl;
}
checkURL();

// 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;
	var valTrue_array ;
	
	//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();
	
	var exists=valTrue.indexOf('|');
	
	valTrue_array=valTrue.split('|');
		
	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 + ";");	
		if(exists < 0)
		{	
		for (i=0; i<objChk.length; i++)
		{
			if (objChk[i].checked && objChk[i].value.toLowerCase() == valTrue)
			{
				disp = true;
			}
		}
		}
		else
		{
			for (i=0; i<objChk.length; i++)
			{	
				for (j=0; j<valTrue_array.length; j++)
				{
					if (objChk[i].checked && objChk[i].value.toLowerCase() == valTrue_array[j])
					{
						disp = true;
						break;
					}
				}
			}
		}
		//alert(disp);
		break;
	case "select-one":
		if(exists < 0)
		{
		if (valCurrent == valTrue)
			disp = true;
		}
		else
		{
		
			for (j=0; j<valTrue_array.length; j++)
			{
				if (valCurrent == valTrue_array[j])
				{
					disp = true;
					break;
				}
				
			}
		}
		break;
	case "radio":
	if(exists < 0)
		{
		if (objCurrent.checked && valCurrent == valTrue)
			disp = true;
		}
		else
		{
			for (j=0; j<valTrue_array.length; j++)
			{
				if (objCurrent.checked && valCurrent == valTrue_array[j])
				{
					disp = true;
					break;
				}
				
			}
		
		}	
				
		break;
	case "select-multiple":
		if(exists < 0)
			{
			if (valCurrent == valTrue)
				disp = true;
			}
			else
			{
				for (j=0; j<valTrue_array.length; j++)
				{
					if (valCurrent == valTrue_array[j])
					{
						disp = true;
						break;
					}
					
				}
			}
		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 + ";");	
				if (isArray(objMulti))
				{
				// 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();
				}
				else
				{
				// Click on the first control to hide the child
				// Set true first as a decoy
				objMulti.checked = true;
				// And then the next click will remove the check value
				objMulti.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;
			case "textarea":
				objLinked.value = '';
				break;
			case "select-multiple":
				for (i=0; i<objLinked.length; i++)
				{
				objLinked[i].selected = false;
				}
				break;
			default:
				alert('Should be only for Drop Down List and Text');			
			}						
			
			objRow.style.display = 'none';
			objRow.style.visibility = 'hidden';
	//	}				
	}
}

function isArray(obj) 
{
	//alert(obj.length);
   //if (obj.constructor.toString().indexOf("Array") == -1)
   if (obj.length)
      return true;
   else
      return false;
}
	
function addItemToArray(ar, v1, v2, v3)
{
	var exists=v3.indexOf('|');
	//alert(v3);
	
	var valTrue_array=v3.split('|');
	
	if(exists < 0)
	{
	ar[ar.length] = new Array(v1, v2, v3);
	}
	else
	{
		for (j=0; j<valTrue_array.length; j++)
			{
			ar[ar.length] = new Array(v1, v2,valTrue_array[j]);
			}
	}
}

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 == "" ) 
		{
			// Check Whether the value already exists in the child
			if (!CheckValueExists(objChild, objAr[i][1]))
			{
				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 CheckValueExists(objSelect, val)
{
	for (iS=0;iS<objSelect.length;iS++)
	{
		if (objSelect.options[iS].value == val)
			return true;
	}
	return false;
}

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');
	}
	*/	
}


// 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;
	}	
}

// 
function assignValuestoControl(Id, Value)
{
	//alert(Id);
	try
	{
	//	alert(Id);
	//	alert(Id.type);
		var disp = false;
	
		var objValue = Value ; 
		var objId =   Id;
		
	
	
		switch (objId.type)
		{
		case "radio":
				var objdradio;
			eval("objdradio = document.formlabs." + objId.name + ";");		
			for (i=0; i<objdradio.length; i++)
			{
				if (objdradio[i].value.toLowerCase() == Value)
				{
					objdradio[i].checked = false;
					objdradio[i].click();
				}
			}
			
			break;
		case "text":
			objId.value = Value ;
			break;
		case "textarea":
			objId.value = Value ;
			break;
		case "checkbox":
			var objChk;
			var chkvalue_array=Value.split("|");
			eval("objChk = document.formlabs." + objId.name + ";");		
			for (i=0; i<objChk.length; i++)
			{
				for (j=0; j<chkvalue_array.length; j++)
				if (objChk[i].value.toLowerCase() == chkvalue_array[j])
				{
					objChk[i].checked = true;
					// Just to make sure that the checkbox will not be selected
					// The click event in the below will select the checkbox
					//if (objChk[i].checked) objChk[i].checked = false;
					
					// Select the checkbox and trigger the event
					//objChk[i].click();
				}
			}
			
			
			// Click on the first control to hide the child
			// Set the opposite first as a decoy
			if (objChk[0].checked) 
				objChk[0].checked = false;
			else
				objChk[0].checked = true;		
			// And then the next click will re-select the check value
			objChk[0].click();
			break;
		case "select-one":
			var objdrop;
			eval("objdrop = document.formlabs." + objId.name + ";");		
			for (i=0; i<objdrop.length; i++)
			{
				if (objdrop[i].value.toLowerCase() == Value)
				{
					objdrop[i].selected = true ;
				}
			}
			
			objId.onchange();
			break;
		case "select-multiple":
			//alert(Value);
			var objListBox;
			var ListBoxvalue_array=Value.split("|");
			eval("objListBox = document.formlabs." + objId.name + ";");		
			for (i=0; i<objListBox.length; i++)
			{
				for (j=0; j<ListBoxvalue_array.length; j++)
				if (objListBox[i].value.toLowerCase() == ListBoxvalue_array[j])
				{
					objListBox[i].selected = true;
					
				}
			}
			
			
			break;
			
		}		
	}
	
	catch(E)
	{
	
	//alert(E) ;
	}
		
	

	
}