function EnterOther(objField)
{
	var nIndex = objField.selectedIndex; 
	if (objField.options(nIndex).text == "other")
	{
		var stValue = window.prompt("Please enter value for the 'other'", "");
		if (stValue == null)
		{
			objField.selectedIndex = 0;
			return;
		}
		var oOption = document.createElement("OPTION");
		objField.options.add(oOption);
		oOption.innerText = stValue;
		oOption.value = stValue;
		objField.value = stValue;
		objField.selectedIndex = objField.options.length-1;
	}
}

function ChangeCaption(stCaption)
{
    document.getElementById("ctl00_body_btnNext").value = stCaption;
}

function RedirectLink()
{
    //debugger;

    var frmContribute = document.forms[2];

	var chkItems = document.getElementsByName("fldType");

	if (chkItems[0].checked)
	{
	    if (document.getElementById("ctl00_body_txtTipLink").value == "")
		{
			alert("Enter valid link to news page.");
			return false;
		}
	}

	// submit-vai-email
	else if (chkItems[1].checked)
	{
		window.navigate("/site/email.aspx?subject=Submit%20News");
		return false;
	}
	
	// submit-details
	else if (chkItems[2].checked)
	{
		window.navigate("/news/submit.aspx?show=news");
		return false;
	}
				
	// article-review
	else if (chkItems[3].checked)
	{
		window.navigate("/news/submitarticle.aspx");
		return false;
	}
	
	// download
	else if (chkItems[4].checked)
	{
		window.navigate("/membership/sign-in.aspx?ReturnUrl=/site/links.aspx%3Fop%3Dadd%26sel%3D3");
		return false;
	}								
	
	// advertisement
	else if (chkItems[5].checked)
	{
		window.navigate("/page.aspx?/site/info-advertise");
		return false;
	}
				
	return true;
}

function CancelAndReturn()
{
	var stOFGT = document.referrer+"";
	if (stOFGT != "")
		window.location.href = stOFGT;
	else
		window.location.href = "/default.aspx";
}

function AutoPaste()
{
	if (document.all.chkAutoPaste != null && !document.all.chkAutoPaste.checked)
		return;
		
	var el = window.event.srcElement;
	if (el == null)
		return;
	
	if (el.value != "")
		return;	

	var stText = window.clipboardData.getData("Text");
	if ((stText != "") && (stText != "undefined") && (stText != null))
	{
		el.value = stText;
		el.focus();
		el.select();
		window.clipboardData.clearData("Text");
	}
	//window.clipboardData.getData("Text", "");
}

function GetNiceDateFormat()
{
	//9 Dec. 1999 16:00:00
	var dt = new Date();
	var sDate = new String();
	var arMonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

	sDate  = dt.getDate() + " ";
	sDate += (arMonth[dt.getMonth()] +". ");
	sDate += (dt.getFullYear() +" ");
	sDate += (dt.getHours() +":");
	sDate += (dt.getMinutes() +":");
	sDate += (dt.getSeconds() +" ");
	
	return sDate;
}

function PreviewSubmision()
{
	if (!WebForm_OnSubmit())
		return;
	
	var btnSubmit = document.getElementById("ctl00_body_btnSubmit");
	btnSubmit.disabled = true;

	if (!ValidateForm())
		return false;
	
	var stStory = document.getElementById("ctl00_body_txtBody").value;
	if (stStory.indexOf("<P>") == 0)
		stStory = stStory.substr(3);
	var nIndex = stStory.lastIndexOf("</P>");
	if (nIndex == stStory.length-4)
		stStory = stStory.substring(0, nIndex);

	document.all.prvStory.innerHTML = "<P>"+ stStory +"</P>";

	var stTitle = document.getElementById("ctl00_body_txtTitle").value;

	document.all.prvTitle.innerHTML = "<a href='" + document.getElementById("ctl00_body_txtLink").value + "'>" + stTitle + "</a>";
	document.all.prvSource.innerHTML = "<a href='" + document.getElementById("ctl00_body_txtLink").value + "'>" + document.getElementById("ctl00_body_fldSourceName").value + "</a>";
	//document.all.prvName.innerText = document.frmAddNews.fldName.value;
	document.all.prvTime.innerText = GetNiceDateFormat();
	
	return true;
}

function ValidateForm()
{
	var stSourceName = document.getElementById("ctl00_body_fldSourceName").value;
	
	if (stSourceName != "email" && stSourceName != "inhouse")
	{
	    if (document.getElementById("ctl00_body_txtLink").value == "")
		{
			alert("Did not fill Source URL")
			return false;
		}
	}
	
	document.all.oPreview.style.display = "";
	document.getElementById("ctl00_body_btnSubmit").disabled = false;
	window.scroll(0, 100);
	return true;
}

function ShowGuideLines()
{
	window.open("/site/noUIpage.aspx?name=postguidelines&scroll=yes", "_New", "toolbar=no,width=450,height=280,status=no,resizable=yes,scrollbar=yes");
}

window.onload = function()
{
	var btnSubmit = document.getElementById("ctl00_body_btnSubmit");
	if (btnSubmit != null)
		btnSubmit.disabled = true;
}