//<!-- Formating string to correct price -->
 
//#########################   Format Price #####################################
function FormatPrice (PriceTextBox) 
{
var formPrice = PriceTextBox.value;

if(formPrice)
		{		
		var strValidNumbers = "0123456789";
		var CorrectPrice = "";
		var FirstDigit = 0;
		var strDot = ".";
		
		//Getting the "Dot" position.
		var DotIndex = formPrice.indexOf(strDot);
		
		//Add leading Zero			
		if (DotIndex==0)
			{
			formPrice= "0." + formPrice;
			DotIndex = formPrice.indexOf(strDot);
			}
	         
		//Remove all the dots except the first one.
		if (DotIndex > 0)
		{
			var strCutUntilDot="0";
			var strCutFromDot;			
			strCutUntilDot = formPrice.substr(0 ,DotIndex);			
			strCutFromDot = formPrice.substr(DotIndex+1 ,formPrice.length);
			var ArrFromDot = strCutFromDot.split("");
			if (ArrFromDot.length)
			{
				strCutFromDot="";
				for (var i=0;i < ArrFromDot.length ;i++ )
				{
					//Append all execpt dots
					if (ArrFromDot[i] != strDot)
					{
						strCutFromDot = strCutFromDot + ArrFromDot[i];
					}
				}					
			}
			//Correct price with only 1 dot
			 formPrice = strCutUntilDot + strDot + strCutFromDot;		
		}
         //Allow only numbers .
		var ArrPrice=formPrice.split("");
		        
			for(i=0;i < ArrPrice.length ;i++)				
				{
					switch (strValidNumbers.indexOf(ArrPrice[i]))
					{
					case -1:												
							//Delete all non-digit unless the char is "."
							if ((ArrPrice[i]!=strDot))
								{
									ArrPrice[i] = "";
								}	
							//If there is "." char.
							//no need to go over all the array.
					                if (DotIndex>0)
							{
							var NewLength = (ArrPrice.length-1)- i;
							
								//If only one char after ".".
								if ( NewLength == 1 )
									{
									  //Add 0 to the end.
									  ArrPrice[i+2] = "0";									  
									}
								  //Define new length to array.
								  ArrPrice.length = DotIndex+3; 								 												
							}						
							break;
				   default:
							if (i==0)
							{
							 //Save first digit	
							 FirstDigit = ArrPrice[i];
							}
					}
				CorrectPrice = CorrectPrice + ArrPrice[i];			
			 }			
			if (strDot == CorrectPrice.charAt((CorrectPrice.length)-1) )
			{
             //Add Zeroes after "."
			CorrectPrice = CorrectPrice + "00";
			}
		}
//PriceTextBox.value = parseFloat(CorrectPrice);
PriceTextBox.value = CorrectPrice;
}

//######################### Check Price #####################################
function CheckPrice (MinPriceTextBox,MaxPriceTextBox)
 {
  // This function is chacking:
  //That the difference  between min parice & max price are positive
  
  var strMinPrice=MinPriceTextBox.value;
  var strMaxPrice=MaxPriceTextBox.value;
  //Set default min price.   
  if (!strMinPrice || strMinPrice=='undefined')
   {
      MinPriceTextBox.value="0.00";
   }
   
   //Set default max price.
  if (!strMaxPrice || strMaxPrice=='undefined')
   {
      MaxPriceTextBox.value="999999999";
   }
   
	MinPriceTextBox.value = parseFloat(MinPriceTextBox.value);
	MaxPriceTextBox.value = parseFloat(MaxPriceTextBox.value);

   // Set the max price in max text box.
     MaxPriceTextBox.value=Math.max(MinPriceTextBox.value,MaxPriceTextBox.value);
  
  // Add 1 dollarto max price to create a difference.
   if (MaxPriceTextBox.value==MinPriceTextBox.value && MinPriceTextBox.value < 999999999 )
     {      
      MaxPriceTextBox.value= eval(MaxPriceTextBox.value)+1;
     }
 }

//#########################   Check Keyword #####################################
 function CheckKeyword (KeywordTextBox)
 {
  // This function is chacking correct key
   var strKeyword = KeywordTextBox.value; 
	for (var index=0 ;index < strKeyword.length;index++ )
	{
		strKeyword = strKeyword.replace("->","");
		strKeyword = strKeyword.replace("&","");
	}
   KeywordTextBox.value=strKeyword.toLowerCase();
 }

 //######################
 function LeftTrim (keywordTxtBox)
 {
	var kwStr  = keywordTxtBox.value;
	var reg   = /^\W+/;
	keywordTxtBox.value = kwStr.replace(reg ,'');
 }

//######################
 function RightTrim (keywordTxtBox)
 {
	var kwStr  = keywordTxtBox.value;
	var reg   = /\W+$/;
	keywordTxtBox.value = kwStr.replace(reg ,'');
 }

//######################
 function Trim (keywordTxtBox)
 {
	LeftTrim(keywordTxtBox);
	RightTrim(keywordTxtBox);

 }


 //######################   open pop up link in HomePage ##########################

loadpage = false;

//###################### 
function setValueTrue()
{ 
 loadpage=true;
}

//######################
function tellPopup(pageName) {
	if (!loadpage) { 
		var win =  window.open(pageName,'tellafriend','width=356,height=440,toolbar=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,screenX=0,screenY=0,top=0,left=0');
	}
}


//######################
function openIt(path) 
{
newWindow = window.open(path,'newWin', 'width=350,height=450')
}


function clicko(land) {
	var newStr = land;
	document.location.href = newStr;
	}

function SetDynamicHomePageValue (obj) {
	var newLocation = "http://" + location.host + '?HP=' +  obj.value;
	document.location.href = newLocation;
}

//######################
function SetFormActionDropDown(mediaFlag) {
		// function that remove special characters
	if (	(document.frmGSRequest.nodropdown) && (document.frmGSRequest.nodropdown.value !=1) ) {
				var selectedIndex	= document.frmGSRequest.FD.selectedIndex;
		document.frmGSRequest.KW.value = ReplaceDem(document.frmGSRequest.KW.value); 
		// remove blanks characters from start and end keyword only 
		Trim(document.frmGSRequest.KW);
		if (document.frmGSRequest.KW.value=='') {
			alert('Please type what you are looking for into the Search box'); 
			return;
		} else if (document.frmGSRequest.FD.options[document.frmGSRequest.FD.selectedIndex].value=='') { 			
			alert('Please select an option.');
			document.frmGSRequest.FD.options[0].selected='true';
			return;		 
		} else if (document.frmGSRequest.KW.value.length < 2) { 
			alert('Search terms must be at least two characters'); 
			return;
		} 
		if (mediaFlag == 0)
		{
				if (document.frmGSRequest.FD.options[selectedIndex].value==63715 || document.frmGSRequest.FD.options[selectedIndex].value==63716 || document.frmGSRequest.FD.options[selectedIndex].value==63717) {
					document.frmGSRequest.action ='http://' + location.host + '/dealtime2000/Media/Media_GS2_referral';
					document.frmGSRequest.submit(); 
					return;
			}
		}
			var kw = escape(ReplaceStringToSEO(document.frmGSRequest.KW.value));
			var formId = document.frmGSRequest.FD.options[selectedIndex].value;
			var formName = document.frmGSRequest.FD.options[selectedIndex].text;
			var regRemoveSpace			= / /g;
			var andRex						= /&/g;
			formName = formName.replace(regRemoveSpace,'_');
			formName = formName.replace(andRex, '_and_');

			var nParentFormID = document.frmGSRequest.FD.value;
			var newLocation;
			var formString = '/xGS-' + kw + '~NS-1';	
			
			if (formName == 'Current_Results' ) {
					var ArrTemp = formId.split('-');
					formName		= escape(ReplaceStringToSEO(ArrTemp[0]));
					formString = GetCurrentResultsFormString(formName,kw);
					if (formString.length > 255)
					{
						alert('To many search terms');
						return;
					}
					formId = 0;
			}

			if ( formId != '0' )
			{
				if (formName != '' ) {
					formString = formString + '~FN-' + formName;
				}
				formString = formString + '~FD-' + formId;
				formString = formString  + '~DL-0~NS-1';
			}		
			newLocation = 'http://' + location.host + formString ;

/*			
		if (mediaFlag == 1)
		{
			if (document.frmGSRequest.FD.options[selectedIndex].value==63715 || document.frmGSRequest.FD.options[selectedIndex].value==63716 || document.frmGSRequest.FD.options[selectedIndex].value==63717) {
				newLocation = 'http://' + location.host + "/xMDS-" + formName + "~KW-" + kw + "~VT-" + formId ;
			}
		}
*/
			document.location.href = newLocation;
			return;
		} else {		document.frmGSRequest.KW.value = ReplaceDem(document.frmGSRequest.KW.value); 
		// remove blanks characters from start and end keyword only 
		Trim(document.frmGSRequest.KW);
		if (document.frmGSRequest.KW.value=='') {
			alert('Please type what you are looking for into the Search box'); 
			return;
		} else if (document.frmGSRequest.KW.value.length < 2) { 
			alert('Search terms must be at least two characters'); 
			return;
		} 
			var kw = escape(ReplaceStringToSEO(document.frmGSRequest.KW.value));
			var regRemoveSpace			= / /g;
			var andRex						= /&/g;
			var newLocation;
			var formString = '/xGS-' + kw + '~NS-1';	
			
			newLocation = 'http://' + location.host + formString ;
			document.location.href = newLocation;
			return;
	}
}

//######################
function GetCurrentResultsFormString (formName,kw) {
	var formString;
	var regRemoveTilda			= /\~.+/g;
	var urlPathname = location.pathname;
	urlPathname	= urlPathname.replace(regRemoveTilda, '');
	var regRemoveSpace			= / /g;
	if (urlPathname.indexOf(formName,0) == -1 || ((urlPathname.indexOf('xPP',0) == -1) && (urlPathname.indexOf('xDN',0) == -1)))
	{		
		formString = document.frmGSRequest.resultType.value;		
		formString = formString.replace(regRemoveSpace,'_');
		formString = formString + '-^' + kw;		
	} 	else 	{
		var urlPathnameArr = urlPathname.split('-'); 
		formString	 = urlPathnameArr.join('-');
		var removedSearchTerm = document.frmGSRequest.removedSearchTerm.value;		
		formString = formString	 + '-^' + kw;				
		if (removedSearchTerm != '')
		{
		if (urlPathnameArr.length > 2)
		{
			var last = urlPathnameArr.pop();						
		}
		if (urlPathnameArr.length == 2)
		{
			urlPathnameArr[1] = urlPathnameArr[1] + '-';
		}
		formString = urlPathnameArr.join('-');
		formString = formString	 + '-^' + kw;				
		} 
	}	
return formString;
			
}

//######################
function selectDynHomePage (obj) {
	var indx = obj.selectedIndex;
	var optnVal = obj.options[indx].value;
	var newLocation = "http://" + location.host + '/?HP=' +  optnVal;
	document.location.href = newLocation;
}

//######################
function ReplaceDem(str) {
	var newStr = str;
	var strValidChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&_-.';	
	// remove all the characters that their ascii code is bigger than 255
	var stringLen = newStr.length;
	var i;
	var tempStr = "";
	for ( i=0 ; i<stringLen ; i++ )
	{
		if (strValidChars.indexOf(newStr.charAt(i)) != -1)
		{
			tempStr = tempStr + newStr.charAt(i);
		} else {
			tempStr = tempStr + " ";
		}
	}
	//return (tempStr.toLowerCase());
	return (tempStr);
}

//######################
// Replace the string to SEO
function ReplaceStringToSEO(str) {
	var newStr = str;
	var spaceRex = / /g;
	var andRex = /&/g;
	var dblUnder = /__/g;
	var minusRex = /-/g;
	var newStr = str.replace(spaceRex, '_');
	newStr = newStr.replace(andRex, '_and_');
	newStr = newStr.replace(dblUnder, '_');
	newStr = newStr.replace(minusRex, '_');
	return newStr; 
}
//######################
function CheckGsSeparatorLine() {
	if (document.frmGSRequest.FD.options[document.frmGSRequest.FD.selectedIndex].value=='')
	{
		document.frmGSRequest.FD.options[0].selected='true';
	}
}

//######################
function GetKeyCode(keyCode,formObj,mediaFlag) {
  if (keyCode == 13 )
	{
		var formName = formObj.name;
		window.document.forms[formName].submit();
	}
}
//######################

function	submitHref(statSrc,unesclink){
      var link = escape( unesclink );

  var parr = window.document.frmGSRequest2.compare;

  var CheckedList = new Array();
  var UnCheckedList = new Array();
  var chInd = 0;
  var unchInd = 0;

  if( parr.length ){
	for(var i = 0; i < parr.length; i++) {
	  if( parr[i].checked ){
	    CheckedList[chInd] = parr[i].value;
	    chInd++;
          }
          else{
            UnCheckedList[unchInd] = parr[i].value;
            unchInd++;
          }
	}
  }
  else{
	  if( parr.checked ){
	    CheckedList[chInd] = parr.value;
          }
          else{
            UnCheckedList[unchInd] = parr.value;
          }
  }

  var finProdList = new Array();
  var finInd=0;
  for( var j=0; j  < prevProdList.length; j++ ){
      var uncheckFlag = 'N';
      for( var k=0; k < UnCheckedList.length; k++ ){
          if( prevProdList[j] == UnCheckedList[k] ){
              uncheckFlag = 'Y';
          }
      }
      if( uncheckFlag == 'N' ){
          finProdList[ finInd ] = prevProdList[j];
          finInd++;
      }
  }

  for( var m=0; m  < CheckedList.length; m++ ){
      var checkFlag = 'N';
      for( var n=0; n < finProdList.length; n++ ){
          if( CheckedList[m] == finProdList[n] ){
              checkFlag = 'Y';
          }
      }
      if( checkFlag == 'N' ){
          finProdList[ finInd ] = CheckedList[m];
          finInd++;
      }
  }

  finProdList.sort();

  var numSelectProd = finProdList.length;

  var shList = finProdList.join('~');
  window.document.prodStore.compProdList.value=shList;

   var matchRes = link.match(/xSBS-/);
   if( matchRes ){
    if( finProdList.length < 1 ){
      window.open(statSrc +"/sc/SBS/OOPS.html", "sbs_npr" , "scrollbars=yes,width=520,height=450");
      return;
    }
   
    if( finProdList.length < 2 ){
      
      var prIdStr = 'PD-'+finProdList[0];
      var redirLink;
      var lnh = '/xPF-~' + prIdStr;
      link =  escape( lnh );
    }
    else {
      var cutProdList = new Array();
      if( finProdList.length > 20 ){
        cutProdList = finProdList.slice( 0, 20 );
        finProdList = cutProdList;
      }

      var sbsLnkList = finProdList.join('-');
      var numPrdPrm = 'NCP-'+numSelectProd;
      var rpltmpLink = link +  '%7E' + numPrdPrm + '~PRDLT-' + sbsLnkList;
      link = rpltmpLink;
    }

    var locUrl = document.URL;
    var locUrlnh = locUrl.replace( /^(http:\/\/[^\/]+)/, "");
    window.document.prodStore.histStamp.value= locUrlnh;
  }


var tldlink = link.replace( /\%7E/g, '~' );
   //  Unescape for special char
    tldlink = unescape(tldlink);
  window.document.prodStore.action=tldlink;
  window.document.prodStore.submit();
  }




function signPrevCheck(){
 // var prevProdList = new Array();

   var compArr = window.document.frmGSRequest2.compare;
   if (compArr) {
      if( compArr.length ){
	   for(var i=0; i<compArr.length; i++){
		  for( var j=0; j<prevProdList.length; j++ ){
			 if( compArr[i].value == prevProdList[j] ){
				compArr[i].checked = true;
			 }
		  }
	   }
      }
      else{
	  for( var j=0; j<prevProdList.length; j++ ){
		 if( compArr.value == prevProdList[j] ){
			compArr.checked = true;
		 }
	  }
      }
   }
}




function rmProd( rmPrdId ){

  var finProdList = new Array();
  var finInd=0;
  for( var j=0; j<prevProdList.length; j++ ){
    if( prevProdList[j] != rmPrdId ){
      finProdList[finInd]=prevProdList[j];
      finInd++;
    }
  }

  var locUrlTld = document.URL;
  var locUrl = locUrlTld.replace( /\%7E/g, '~' );
  var tmpLock = locUrl.replace( /^(http:\/\/[^\/]+)/, "");
  var tldLink =  escape( tmpLock );
  var sndLink = tldLink.replace( /\%7E/g, '~' );

  if( finProdList.length < 2 ){

      var redirLink;
      for( var n=0; n < document.links.length; n++ ){
          if(document.links[n].href.match('/xPC-') ){
              redirLink = document.links[n].href;
          }
      }
      var lnh = "xPF-~PD-" + finProdList[0];
      var oneTldLink =  escape( lnh );
      sndLink = oneTldLink.replace( /\%7E/g, '~' );
  }

  finProdList.sort();
  var shList=finProdList.join('~');
  var sbsLnkList = finProdList.join('-');

  sendCommit(sndLink, shList, sbsLnkList);
}

function nextPage(nextPageUrl){
  var shList=prevProdList.join('~');
  var sbsLnkList = prevProdList.join('-');
  sendCommit(nextPageUrl, shList, sbsLnkList);
}

function sortPage(sortPageUrl, attrributeId){
  
  
  sortPageUrl = sortPageUrl.replace('SortByID' , attrributeId)
  var shList=prevProdList.join('~');
  var sbsLnkList = prevProdList.join('-');
  sendCommit(sortPageUrl, shList, sbsLnkList);
}

function sendCommit( unesclink, postInp, sbsLnkList ){
  var tldLink = escape( unesclink );
  var link =  tldLink.replace( /\%7E/g, '~' );


  var matchResSbs = link.match(/xSBS-/); 
  if( matchResSbs ){

    var tmpListPrdArr = new Array();
    tmpListPrdArr = postInp.split('~');

   var numSelectProd = tmpListPrdArr.length;
   var matchResNmPr = link.match(/NCP/);
   var rpltmpLink;
   if( matchResNmPr ) {
     rpltmpLink = link.replace( /\~NCP-\d*\~/, '~NCP-'+numSelectProd+'~' );
   }
   else{
      var numPrdPrm = 'NCP-'+numSelectProd;
      rpltmpLink = link +  '%7E' + numPrdPrm ;
   }
   var linkNoPrdlt = rpltmpLink.replace( /\~PRDLT[-\d]+/, '' );
   link = linkNoPrdlt + '~PRDLT-' + sbsLnkList;
  }

  window.document.prodStore.compProdList.value=postInp;
  window.document.prodStore.action=link;    
  window.document.prodStore.submit();

  
}

//### Set cursor in gs keyword text box
function SetCursor()
	{
	   if (document.frmGSRequest) 
		{
			if ((document.dummyFrm) && (document.dummyFrm.dummyFocus.value==1) )
			{
				// dont set the focus because of the popup
			}
			else
			{				
				document.frmGSRequest.KW.focus();
			}
		}
	}

function shoppyPopUpWin() {

var textlink='http://a1964.g.akamaitech.net/f/1964/452/24h/sc.dealtime.com/cctool/files/intro_win.html';
var ht=540;
var wd=720;
var wPos=0;
var hPos=0;

	if (screen) {
		wPos = (screen.availWidth-wd)/2;
		hPos = (screen.availHeight-wd)/2;
	}


var agt=navigator.userAgent.toLowerCase(); 

if ((agt.indexOf("msie") != -1) && (agt.indexOf("mac") == -1)) {
	var newwindow;
}


	if ((agt.indexOf("msie") != -1) && (agt.indexOf("mac") == -1)) {
		if (newwindow != null) { newwindow.close(); }
	}
	newwindow = window.open(textlink,'popup',config='height=' + ht + ',width=' + wd + ',left=' + wPos + ',top=' + hPos + ', scrollbars=no,toolbar=no,copyhistory=no,resizable=no,directories=no,menubar=no,status=no,location=no');
	newwindow.focus();
}

function rebatePop(link) {
var win = window.open(link, "whatIS","scrollbars=yes,width=680,height=420");
}


	function CheckProductPageLeftForm() { 	 
		 FormatPrice(window.document.frmGSRequest2.PriceRange_lo);    
		 FormatPrice(window.document.frmGSRequest2.PriceRange_hi);    
		 Trim(window.document.frmGSRequest2.KW);
		 CheckKeyword(window.document.frmGSRequest2.KW);
	 }
	function CheckProductPageBottomForm() { 	 
		 FormatPrice(window.document.frmGSRequest3.PriceRange_lo);
		 FormatPrice(window.document.frmGSRequest3.PriceRange_hi);    
	 }



function writeBanner(banner){
	document.writeln("<SCRIPT LANGUAGE='JavaScript1.1' SRC='http://ad.doubleclick.net/adj/" + banner + ";dcopt=ist;tile=1;sz=468x60;ord=" + random + "?'></SCRIPT>");

	if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) { 
		document.write('<A HREF="http://ad.doubleclick.net/jump/' + banner +';tile=1;sz=468x60;ord=' + random + '?" TARGET="_blank">');
		document.write('<IMG SRC="http://ad.doubleclick.net/ad/' + banner +';tile=1;sz=468x60;ord=' + random + '?" WIDTH="468" HEIGHT="60" BORDER="0" ALT=""></A>'); 
	} 

}