/*
$Id: cp.js,v 1.00 2007/06/26 
(c) 2007 The China Post
*/

function test()

{
   if (! document.forms[1].dateRange[3].checked)
     {
      alert ("Specific - From sould be checked")
      document.forms[1].dateRange[3].focus();
      return false;
     } 
   else
      return true;
  }


function EWindow(sTarget)
{
//window.open(sTarget,"Photo","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=600,height=500,resizable=no");
	var emailWindow = window.open(sTarget,'Email','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,width=700,height=550,resizable=no');
	emailWindow.focus();
	return true;
}

function MWindow(sTarget)
{
//window.open(sTarget,"Photo","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=600,height=500,resizable=no");
	var movieWindow = window.open(sTarget,'movie','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=640,height=480,resizable=no');
	movieWindow.focus();
	return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MaxWindow() { //v2.0
  self.moveTo(0,0)
	self.resizeTo(screen.availWidth,screen.availHeight)
}

function diggit() {
 url1="http://digg.com/submit?phase=2&url=";
 url2=window.location.href;
 //location=url1+url2;
 ttt=url1+url2
 window.open(ttt);
 }	

function WPhotos(sTarget)
{
//window.open(sTarget,"Photo","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=674,height=768,resizable=no");
	var photoWindow = window.open(sTarget,'Photo','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=502,height=650,resizable=no');
	photoWindow.focus();
	return true;
}

function NewWindow(sTarget)
{
//window.close();
window.opener.open(sTarget,'Article','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,,,resizable=no');
}

function PrintWindow(sTarget)
{
//window.close();
window.open(sTarget,'Print','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,,,resizable=no');
}

function Clear_email() {
  var str=document.forms[1].email.value ;
  if (str == "Enter email here")
  {  
	document.forms[1].email.value="";
	document.getElementById('email').style.color='#000000'
	}
}

function Clear_commentstxt() {
  var str=document.forms[1].commentstxt.value ;
  if (str == "Enter comments here")
  {
	document.forms[1].commentstxt.value="";
	document.getElementById('commentstxt').style.color='#000000'
	}
}

function Check_Comments()
  {

	if ( (is_email()) && (is_commentstxt()) )
      return true;
   else
      return false;
  }

function is_email()
{
	var str=document.forms[1].email.value;
	if ((str!== null) && (str.indexOf('@',0) == -1 || str.indexOf('.',0) == -1 ))
	{
	 alert ("Please input your right delivery Email address");
   document.forms[1].email.focus();
	 return false;
	}
	else
	return true;
}     

function is_commentstxt()
{
  var str=document.forms[1].commentstxt.value;
  if ((str == "") || (str == "Enter comments here"))
  {
   alert ("Please input your comments")
   document.forms[1].commentstxt.focus();
   return false;
  }
  else
     return true;
}
   
/* most popular module tab functions */
function cnnMpStories( intWhich ) {
	for(i=1;i<4;i++) {
		if(i==intWhich) {
			document.getElementById('cnnMpStories' + i).style.display = 'block'
			//$('cnnMpStories' + i).style.display = 'block';
			document.getElementById('nation_h' + i).className = 'active';
			//$('nation_h' + i).className = 'active';
		}
		else {
			document.getElementById('cnnMpStories' + i).style.display = 'none'
			//$('cnnMpStories' + i).style.display = 'none';
			document.getElementById('nation_h' + i).className = 'inactive';
			//$('nation_h' + i).className = 'inactive';
		}
	}
	document.getElementById('nation_h' + intWhich).blur();
	//$('nation_h'+ intWhich).blur();
}

function WThread(sTarget)
{
	var photoWindow = window.open(sTarget,'Thread','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=600,height=630,resizable=yes');
	photoWindow.focus();
	return true;
}

function Check_Thread()
  {

	if ( (is_thread_email()) && (is_thread_title()) && (is_thread_content()) )
      return true;
   else
      return false;
  }

function is_thread_email()
{
	var str=document.forms[0].News_author.value;
	if ((str!== null) && (str.indexOf('@',0) == -1 || str.indexOf('.',0) == -1 ))
	{
	 alert ("Please enter a valid email address.");
   document.forms[0].News_author.focus();
	 return false;
	}
	else
	return true;
}     

function is_thread_title()
{
  var str=document.forms[0].News_title.value;
  if ((str == "") || (str == "Enter the thread headline - 200 characters max"))
  {
   alert ("Please input thread headline")
   document.forms[0].News_title.focus();
   return false;
  }
  else
     return true;
}

function is_thread_content()
{
  var str=document.forms[0].News_eng_content.value;
  if ((str == "") || (str == "Enter the thread content - 5000 characters max"))
  {
   alert ("Please input thread content")
   document.forms[0].News_eng_content.focus();
   return false;
  }
  else
     document.forms[0].News_eng_content.focus();
     return true;
}

function Clear_author() {
  var str=document.forms[0].News_author.value ;
  if (str == "Enter email (only the first half of email will be shown)")
  {  
	document.forms[0].News_author.value="";
	document.getElementById('News_author').style.color='#000000';
	document.forms[0].News_author.focus();
	}
}

function Clear_title() {
  var str=document.forms[0].News_title.value ;
  if (str == "Enter the thread headline - 200 characters max")
  {
	document.forms[0].News_title.value="";
	document.getElementById('News_title').style.color='#000000';
	document.forms[0].News_title.focus();
	}
}

function Clear_content() {
  var str=document.forms[0].News_eng_content.value ;
  if (str == "Enter the thread content - 5000 characters max")
  {
	document.forms[0].News_eng_content.value="";
	document.getElementById('News_eng_content').style.color='#000000';
	document.forms[0].News_eng_content.focus();
	}
}


function CheckLen_title() {
	if (document.forms[0].News_title.value.length > 200){
		L1=document.forms[0].News_title.value.length;
		str1=document.forms[0].News_titlet.value;
		str2=str1.substr(0,200);
		alert("Your thread headline : "+L1+"\r\rexceed 200 characters");
	  document.forms[0].News_title.value=str2;
	  document.forms[0].News_title.focus();	
	  return false
	}
	else {
	  return true;
	}	
}

function CheckLen_content() {
	if (document.forms[0].News_eng_content.value.length > 5000){
		L1=document.forms[0].News_eng_content.value.length;
		str1=document.forms[0].News_eng_content.value;
		str2=str1.substr(0,5000);
		alert("Your thread content : "+L1+"\r\rexceed 5000 characters");
	  document.forms[0].News_eng_content.value=str2;
	  document.forms[0].News_eng_content.focus();	
	  return false
	}
	else {
	  return true;
	}	
}
