function LTrim( value ) 
{ 
 var re = /\s*((\S+\s*)*)/;
 return value.replace(re, "$1"); 
}
// Removes ending whitespaces
function RTrim( value ) 
{
 
 var re = /((\s*\S+)*)\s*/;
 return value.replace(re, "$1");
 
}

// Removes leading and ending whitespaces
function trim( value ) 
{ 
	 return LTrim(RTrim(value)); 
}
function checkchar(mystr,invalidChars1)
{
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?

		{

			badChar1 = invalidChars1.charAt(i)

			if (mystr.indexOf(badChar1,0) > -1) 

				{

					return false;

				}

		}

return true;

}

function popUp(url)

{
	
	window.open (url,"mywindow","resizable=yes, scrollbars=yes");

}
function IsNumeric(str)

   {

	   var strValidChars = "0123456789";

	   var strChar;

	   var strString = str ;

	   var blnResult = true;

	   var field;



	   if (strString.length == 0) return false;

	

	   //  test strString consists of valid characters listed above

	   for (i = 0; i < strString.length && blnResult == true; i++)

		  {

		  strChar = strString.charAt(i);

		  if (strValidChars.indexOf(strChar) == -1)

			 {

			 	//alert('This value should be Numeric!');

				//field.value = "";

				blnResult = false;

			 }

		  }

	   return blnResult;

   }	//	End	of function IsNumeric

function IsPriceNumeric(str)

   {

	   var strValidChars = "0123456789.";

	   var strChar;

	   var strString = str ;

	   var blnResult = true;

	   var field;



	   if (strString.length == 0) return false;

	

	   //  test strString consists of valid characters listed above

	   for (i = 0; i < strString.length && blnResult == true; i++)

		  {

		  strChar = strString.charAt(i);

		  if (strValidChars.indexOf(strChar) == -1)

			 {

			 	//alert('This value should be Numeric!');

				//field.value = "";

				blnResult = false;

			 }

		  }

	   return blnResult;

   }	//	End	of function IsNumeric




function isPriceNumber (id,val)
{
	if(document.getElementById(id).value != "")
	{
		if( IsPriceNumeric (document.getElementById(id).value) == false )
		{
			alert("Only numeric values are allowed.");
			document.getElementById(id).value = val;
			
		}
	}
}
function IsPhoneNumeric(str)

   {

	   var strValidChars = "0123456789-+";

	   var strChar;

	   var strString = str ;

	   var blnResult = true;

	   var field;



	   if (strString.length == 0) return false;

	

	   //  test strString consists of valid characters listed above

	   for (i = 0; i < strString.length && blnResult == true; i++)

		  {

		  strChar = strString.charAt(i);

		  if (strValidChars.indexOf(strChar) == -1)

			 {

			 	//alert('This value should be Numeric!');

				//field.value = "";

				blnResult = false;

			 }

		  }

	   return blnResult;

   }	//	End	of function IsNumeric



function isNumber (id,val)

{

	if(document.getElementById(id).value != "")

	{

		if( IsNumeric (document.getElementById(id).value) == false )

		{

			alert("Only numeric values are allowed");

			document.getElementById(id).value = val;

			

		}

	}

}
function isPhoneValid (id,val)
{
	if(document.getElementById(id).value != "")
	{
		if( IsPhoneNumeric (document.getElementById(id).value) == false )
		{
			alert("Please write valid phone number.");
			document.getElementById(id).value = val;
			
		}
	}
}
function checkchar(mystr,invalidChars1)
{
			
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?
		{
			badChar1 = invalidChars1.charAt(i)
			if (mystr.indexOf(badChar1,0) > -1) 
				{
					return false;
				}
		}
return true;
}
function isChar(id,val)
{
	if(document.getElementById(id).value != "")
	{	
		 if(!checkchar(document.getElementById(id).value,"?/:,;=+'\"<>|\\`~{}#$%@!^&*[]()_.-0123456789"))
		{
			alert("Only alphabets are allowed");
			document.getElementById(id).value = val;
		
		}		
	}// if(document.getElementById(id).value != "")ss	
}

function getSelected(fldName)
{
	alert("hre");		
	flag = 0;
	alert(add_product.available_for.length);
	for (i=0;i<document.add_product.available_for.length;i++)
	{
		  if (document.add_product.available_for[i].checked)
		  {
				 sel_value = document.add_product.available_for[i].value;
				 flag=1;
				 break;
		  }
	}
	/*for (i=0;i<document.add_product[fldName].length;i++)
	{
		  if (document.add_product[fldName][i].checked)
		  {
				 sel_value = document.add_product[fldName][i].value;
				 flag=1;
				 break;
		  }
	}*/
	return flag;
}// getSelected



function confirmNewsStatus(pid,status, pageNum)
{
	if(status == 0)
	{
		flag = confirm("Are you sure you want to de-activate this News/Analysis.");
	}
	else if(status == 1)
	{
		flag = confirm("Are you sure you want to activate this News/Analysis.");
	}
	if(flag)
	{
		window.location = "forex-outlook.php?st=change&pid="+pid+"&newst="+status+"&page="+pageNum;
	}
}
function confirmDelNews(pid, pageNum)
{
	
	flag = confirm("Are you sure you want to delete this record.");
	
	if(flag)
	{
		window.location = "forex-outlook.php?st=del&pid="+pid+"&page="+pageNum;
	}
}
function confirmSignalStatus(pid,status, pageNum)
{
	if(status == 0)
	{
		flag = confirm("Are you sure you want to de-activate this idea.");
	}
	else if(status == 1)
	{
		flag = confirm("Are you sure you want to activate this idea.");
	}
	if(flag)
	{
		window.location = "ideas.php?st=change&pid="+pid+"&newst="+status+"&page="+pageNum;
	}
}
function confirmDelSignal(pid, pageNum)
{
	
	flag = confirm("Are you sure you want to delete this idea.");
	
	if(flag)
	{
		window.location = "ideas.php?st=del&pid="+pid+"&page="+pageNum;
	}
}

function confirmMemberStatus(pid,status, pageNum, ch, search_member)
{
	if(status == 0)
	{
		flag = confirm("Are you sure you want to de-activate this member login.");
	}
	else if(status == 1)
	{
		flag = confirm("Are you sure you want to activate this member login.");
	}
	if(flag)
	{
		window.location = "members.php?st=change&pid="+pid+"&newst="+status+"&page="+pageNum+"&ch="+ch+"&search_member="+search_member;
	}
}

function confirmDelMember(pid,pname, pageNum, ch, search_member)
{
	
	flag = confirm("Are you sure you want to delete member login '"+pname+"'.");
	
	if(flag)
	{
		window.location = "members.php?st=del&pid="+pid+"&pname="+pname+"&page="+pageNum+"&ch="+ch+"&search_member="+search_member;
	}
}
function confirmDelGlossary(pid,pname, pageNum, ch, search_q)
{
	
	flag = confirm("Are you sure you want to delete this glossary item.");
	
	if(flag)
	{
		window.location = "glossary.php?st=del&pid="+pid+"&pname="+pname+"&page="+pageNum+"&ch="+ch+"&search_q="+search_q;
	}
}

function validateUserName(id,val)
{
	if(document.getElementById(id).value != "")
	{
		
		if(!checkchar(document.getElementById(id).value," ?./:,;=+'\"<>|\\`~{}#$%@!^&*()[]"))
		{
			alert("Special characters and spaces are not allowed");
			document.getElementById(id).value = val;			
		}	
		
	}// if(document.getElementById(id).value != "")ss	
}
function validateCharacter(id, val)
{
	
		if(!checkchar(document.getElementById(id).value,"?/:,;=+'\"<>|\\`~{}#$%@!^&*[]()_.-0123456789"))
		{
			alert("Only alphabets are allowed");
			document.getElementById(id).value = val;
		
		}
}

function confirmManStatus(pid,status, pageNum)
{
	if(status == 0)
	{
		flag = confirm("Are you sure you want to de-activate this manual.");
	}
	else if(status == 1)
	{
		flag = confirm("Are you sure you want to activate this manual.");
	}
	if(flag)
	{
		window.location = "fleet-manuals.php?st=change&pid="+pid+"&newst="+status+"&page="+pageNum;
	}
}
function downloadMagzine(user, id, mod)
{
	if(user == "")
	{
		alert("Only members can download magazine, please login to download.");
	}
	else
	{	
		
		window.location = "download.php?st="+id+"&mod="+mod;
	}
}
function addBookMark()
{



 if (window.external) 



 {



	 document.write('<a href = "javascript:CreateBookmarkLink()");">Add to Favourties</a>'); 



 } 



 else  if (window.sidebar) 



 {



	  document.write('<a href = "javascript:CreateBookmarkLink()");">Bookmark Page</a>'); 



 } 



 else if (window.opera && window.print) 



 {	



	  document.write('<a href = "javascript:CreateBookmarkLink()");">Add Bookmark</a>');



 } 



}// Closing of function addBookMark()
 function CreateBookmarkLink() 



	 {



		 title = document.title; 



		  // Blogger - Replace with <$BlogItemTitle$> 



		  // MovableType - Replace with <$MTEntryTitle$>



		



		 url = window.location.href;



		  // Blogger - Replace with <$BlogItemPermalinkURL$> 



		  // MovableType - Replace with <$MTEntryPermalink$>



		  // WordPress - <?php bloginfo('url'); ?>



		



			if (window.sidebar) { // Mozilla Firefox Bookmark



				window.sidebar.addPanel(title, url,"");



			} else if( window.external ) { // IE Favorite



				window.external.AddFavorite( url, title); }



			else if(window.opera && window.print) { // Opera Hotlist



				return true; }



	 }//Closing of function CreateBookmarkLink() 

function checkReg(){
	var message="Please enter required fields\n";
	var flag=false;
	
	if(document.quick_registration.name.value=='' || document.quick_registration.name.value=='enter your full name'){
		message+="* Your Full Name\n";
		flag=true;
	}
	
	var checkm=checkEmail(document.quick_registration.email.value);

	 if((checkm==false) || (document.quick_registration.email.value==""))
  	 {
		message+="* Valid email address\n";
		flag=true;
	 }
	
	
	 if(flag==true){
	 	alert(message);
		return false;
	 }
	 else
		document.quick_registration.submit();
	
}

function checkEmail(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email))
		return true;
	else
		return false;
}

function clrFld(id){
	
	if(id == "name"){
	
		if(document.getElementById(id).value=='enter your full name')
			document.getElementById(id).value = "";
	}
	
	else if(id == "email"){
		
		if(document.getElementById(id).value=='enter your email')
			document.getElementById(id).value = "";
	}
	
}