var formSubmission=false;
function removeUserProduct(e, args){
	var requestUrl = args[0];
	if(!formSubmission){
    	YAHOO.util.Connect.asyncRequest("GET",requestUrl, null, null);
	}
}

function writeRatingStars(rating,maxRating)
{ 
	document.writeln(showRatingStars(rating,maxRating));
}

function showRatingStars(rating,maxRating)
{
	var str = "";
	rating = Math.ceil(rating);
	for(i = 0;i < rating ;i++)
	{	
		str += "<img src=\"images/star_red.gif\" />";
	}
	for(i = rating;i < maxRating;i++)
	{	
		str += "<img src=\"images/star_grey.gif\" />";
	}
	return str;
}

function getTellFriendURL(url)
{
	location.href = escape(url);
}


function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";

	if(v_length < 0){
	return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE)
{
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length)
{
	if(VALUE.charAt(iTemp) == w_space)
	{
	}
	else{
	strTemp = VALUE.substring(iTemp,v_length);
	break;
	}
	iTemp = iTemp + 1;
} //End While

return strTemp;
} //End Function

function openURL(url)
{
	window.open(url);	
}

function isNumeric(sText)
{
   var validChars = "0123456789";
   var isNumber=true;
   var j_char;

   for (i = 0; i < sText.length && isNumber == true; i++)
      {
      j_char = sText.charAt(i);
      if (validChars.indexOf(j_char) == -1)
         {
         isNumber = false;
         }
      }
   return isNumber;
}

var element;
var category;
function startCount(elem, id, categoryString)
{   
	string="display(" + id + ");";	
	element = elem;
	category = categoryString;
	myTimer = setTimeout(string, 500);
}

function display(id) {
	var start = 0;
	var last = 3;
	selectedCategoryId = id;
    makeCategoryRequest("displaySeeds.html?", id, element, category);
}

function clearCount(elem)
{
	clearTimeout(myTimer);
}

function dowloadToolbarIfRequired(){
	if(navigator.appVersion.indexOf("MSIE")!=-1){
	  location.href="toolbarbutton.exe";
	}
	else{
	 alert('Current version of toolbar button will work only with Internet Explorer. Please download using Internet Explorer.');
	}
	//alert('Click USuggestNow button while SHOPPING in USuggest to make suggestions.');
}

function closeWindowWithoutConfirmation(){
if(window.opener == null){
	    window.opener = '';
//the following line is to get rid of the closing confirmation alert for IE7.
		window.open('','_self');
		window.close();
	}
	else{
		top.window.close();
	}
}

function showLoggedInUserSectionIfRequired(enteredUserId, userrole){
 var loggedInUserSection =  document.getElementById("loggedInUserSect");
 if(loggedInUserSection != null){
	if(enteredUserId != undefined){
	   loggedInUserSection.style.visibility = "visible";	
	 }
	 if(enteredUserId != undefined && userrole == 'admin'){
	  document.getElementById("sendNewsletter-link").style.display = "block";
	  document.getElementById("sendPrivateInvitation-link").style.display = "block";
	 }
 }
}

function closeWindow()
{
	if(window.opener != null){
		top.window.close();
	}
	else{
		window.location.href = "index.jsp"
	}
}

  function appendRefreshParamIfRequired(url){
  
      // if the url does not have the query string
      if(url.indexOf("&refresh=true") == -1 && url.indexOf("?") == -1 && url.indexOf("directURL") == -1){
			url = url + "?refresh=true";
			
	  }
	  
	  //if the uril does not have the refresh parameter
	  else if(url.indexOf("&refresh=true") == -1 && url.indexOf("directURL") == -1){
           if(url.indexOf("#") != -1){
                 var urlParts = url.split('#');
                 url = urlParts[0] + "&refresh=true";
           }
           else{
	           url = url + "&refresh=true";
	           }
       }
       
       //this is to remove the jump link from the url
       else if(url.indexOf("&refresh=true") != -1 && url.indexOf("#") != -1){
             var urlParts = url.split('#');
             url = urlParts[0];
       }
       
      
      return url;
  }
  
function addItemsToSelectList(value,text,obj){
	pos = obj.options.length;
	for(i = 0; i < pos;i++){
		if(obj.options[i].value == value){
			return;
		}
	}
	obj.options[pos] = new Option();
	obj.options[pos].value = value;
	obj.options[pos].text = decodeURIComponent(text);
}

function addToList(value, text, pos, obj){
  		obj.options[pos] = new Option();
		obj.options[pos].value = value;
		obj.options[pos].text = decodeURIComponent(text);
}

function removeDuplicatesFromList(obj) {
    var index, tempValue0, tempValue1, tempText0, tempText1;
    for (index=1; index<obj.options.length; index++) {
      tempValue0=obj.options[index-1].value;
      tempText0 =obj.options[index-1].text;
      tempValue1=obj.options[index].value;
      tempText1 =obj.options[index].text;
      if ((tempValue1 == tempValue0) && (tempText1 == tempText0)) {
        obj.options[index]=null;
        index-=1;
      }
    }
}

function removeAllFromList(obj){
    pos = obj.options.length - 1;
	for(i = pos; i >= 0;i--){
			obj.options[i] = null;
	}
}

function selectAllOptions(obj, form){
  for(i = 0;i < obj.options.length; i++){
   obj.options[i].selected = true;
 }
}	

function removeSelected(obj){
	removed = false;
	pos = obj.options.length - 1;
	for(i = pos; i >= 0;i--){
		if(obj.options[i].selected){
			removed = true;
			obj.options[i] = null;
		}
	}
	if(!removed){
		alert("Select item to remove");
	}
}

function removeFromSelectList(obj, value){
	pos = obj.options.length - 1;
	for(i = pos; i >= 0;i--){
		if(obj.options[i].value == value){
			obj.options[i] = null;
		}
	}
}

function isValidSecurityCode(form){
	var isValid = true;
	var securityKey = form.j_captcha_response.value;
	if(securityKey == null){
		isValid = false;
	}
	else { 
	  securityKey = securityKey.replace( /^\s+/g, "" ); //strip leading
	  securityKey = securityKey.replace( /\s+$/g, "" ); //strip trailing
	 	if(securityKey.length < 1){
	  		 form.j_captcha_response.value = securityKey;
	   		 isValid = false;
	   		 
	 	} 
	}
	form.j_captcha_response.focus();  
	return isValid;  
}

function trim(str) {  
	return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
  
function goTop(){
	var url = window.location.href;		
	if(url.indexOf("#") != -1){
		url = url.split('#')[0]
	}
	url = url+"#";
	window.location.href = url;
}  

 function isValidVideoPath(videoPath){
  var validImage = true;
  var regex = /^[a-zA-Z]$/;
  var fileType = /^\.[a-zA-Z0-9]{2,4}$/;
  var imagePathArray = videoPath.split(":");
  // to check whether the image path has drive name as well as the filename
  if(imagePathArray.length == 1){
    validImage = false;
  }
  //to check whether the image path has the valid drive name
  else if(imagePathArray.length > 1 && (imagePathArray[0].length > 1 || !regex.test(imagePathArray[0]))){
       validImage = false;
  }
  //to check whether the file name has the valid file extension.
  else if(imagePathArray.length > 1){
     var imagePathAfterColon = imagePathArray[imagePathArray.length-1];
     var fileExtension = imagePathAfterColon.substring(imagePathAfterColon.lastIndexOf("."),imagePathAfterColon.length);
     if(!fileType.test(fileExtension)){
      validImage = false;
     }
  }
 return validImage;
}

function checkEmailId(emailStr) {
   if (emailStr.length == 0) {
       return true;
   }
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);
   if (matchArray == null) {
       return false;
   }
   var user=matchArray[1];
   var domain=matchArray[2];
   if (user.match(userPat) == null) {
       return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
       for (var i = 1; i <= 4; i++) {
          if (IPArray[i] > 255) {
             return false;
          }
       }
       return true;
   }
   var domainArray=domain.match(domainPat);
   if (domainArray == null) {
       return false;
   }
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if ((domArr[domArr.length-1].length < 2) ||
       (domArr[domArr.length-1].length > 3)) {
       return false;
   }
   if (len < 2) {
       return false;
   }
   return true;
}


//functions for showing loading icon
function loadingPanel_init() {					
	var x = YAHOO.util.Dom.getX("pagination") + 200;
	var y = YAHOO.util.Dom.getY("pagination") + 100;
	wait = new YAHOO.widget.Panel("wait",  
						{ width:"240px", 
						  close:false, 
						  draggable:false, 
						  modal:false,
						  visible:false,
						  x:x,
						  y:y,
						  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5}
						} 
	);
	// Initialize the temporary Panel to display while waiting for external content to load
	wait.setHeader("Loading, please wait...");
	wait.setBody('<img src="images/loading.gif"/>');
	wait.render(document.body);		
}
function showLoadingPanel(){
	wait.show();
}
function hideLoadingPanel(){
	wait.hide();
}

function removeDuplicatesFromThisArray(inArray){
  var arr=new Array();
  for(i=0;i<inArray.length;i++)
  {
  	if(inArray[i]==inArray[i+1]) {
  		continue;
  	}
 	arr[arr.length]=inArray[i];
  }
  return arr;
  } 
 
 // This will pause the execution for the given duration (milliseconds. 
  function pauseExecution(millis)
{   
	var date = new Date();
	var curDate = null;
	do { 
		curDate = new Date();
	}
	while(curDate-date < millis);
} 

function submitFacebookForm(){
   document.forms["facebookForm"].submit();
}

function select_all()
{
var text_val=eval(document.getElementById("moneyMakingURLField"));
text_val.focus();
text_val.select();
}

function select_allImageText()
{
var text_val=eval(document.getElementById("moneyMakingImageField"));
text_val.focus();
text_val.select();
}

function selectAll(txtAreaId)
{
var text_val=eval(document.getElementById(txtAreaId));
text_val.focus();
text_val.select();
}

function ClipBoard(txtAreaId) 
{
Copied = document.getElementById(txtAreaId).createTextRange();
Copied.execCommand("Copy");
}