//GENERAL FUNCTIONS FOR TRIM
function LTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) 
	{
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
	{
		var i = s.length - 1;    
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;

		s = s.substring(0, i+1);
	}
	return s;
}
function Trim(str)
{
	return RTrim(LTrim(str));
}


//THIS IS FOR OPT-OUT PAGE
function FixButtonStyle(id)
{
 var role = self.location.href.substr(self.location.href.lastIndexOf('='));// .charAt(self.location.href.length - 1); 
 
 if(role.indexOf('C') > -1 )
  {
   if(document.getElementById(id) != null) 
	document.getElementById(id).className = 'optout';
  }
 else 
 { 
 if(document.getElementById(id) != null) 
   document.getElementById(id).className = 'de-register';
  } 
}


//HIDE THE NAVIGATIONS BUTTONS IN HOMEPAGE IS COUPON COUNT IS 0
function HideButtons(id1, id2 , objCouponCount)
{
  
	var CouponCount = document.getElementById(objCouponCount);
	if(CouponCount.value == "0")
	{
		document.getElementById(id1).className = 'hide';
		document.getElementById(id2).className = 'hide';
	}
}

//FOR CLEARING THE CONTENTS IN TXTFIELDS WHEN ITS FOCUSED
function ClearContent(objField,sText)
{
	var Field = document.getElementById(objField);
	if(Trim(Field.value) == sText)
	{
		Field.value = "";
	}
}

//FOR CLEARING THE CONTENTS IN TXTFIELDS WHEN IT LOSING THE FOCUS AND ITS EMPTY
function FillContent(objField,sText)
{
	var Field = document.getElementById(objField);
	if(Field.value == "")
	{
		Field.value = sText;
	}
}

//FOR FOCUSING THE SUBMIT WHEN KEYDOWN 
function FixSubmitFocus(objField,event)
{
	if (event.keyCode==13)
	{
		Field = document.getElementById(objField);
		Field.focus();
	}
}

//FUNCTION TO REPLACE TEXTS- ADDED BY SAILESH
function ReplaceText(TextToReplace,BodyText)
{
	var strSplit;
	var spliResult;
	var cont=0;  
	var First;
	var sec;
			strSplit=TextToReplace.split(";");
			
			while(cont<strSplit.length)
			{
			spliResult=strSplit[cont].split("=");
			First=spliResult[0];
			sec=spliResult[1];
					while(BodyText.indexOf(First)!=-1)
					{
						BodyText=BodyText.replace(First,sec);
					}
			cont++;
			}
			return BodyText;
			
}