//Event.observe(window, 'load', page_loaded, false); 
//moved definition to script.jsp within javascript to avoid errors pop up

function page_loaded(evt) {
  	
}

function expand_staffPicksExpandBtn(){
  document.getElementById('staffPicksExpandBtn').style.display='none';
 document.getElementById('staffPicksExpand').style.display='block';
}

function expand_virginSelectExpandBtn(){
  									
  document.getElementById('virginSelectExpandBtn').style.display='none';
  document.getElementById('virginSelectExpand').style.display='block';

}
  	
function ajaxLoader(url,id) {
  if (document.getElementById) {
  	document.getElementById(id).innerHTML= "<div class='load'><img src='images/loading.gif'/></div>";
  	//document.getElementById(id).innerHTML= "<div class='load'></div>";
	//alert('ok');
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
        el = document.getElementById(id);
        el.innerHTML = x.responseText;
        //alert(x.responseText);
      }
    }
    x.open("GET", url, true);
    x.send(null);
  }
}

function createParams(Params) {
	var querystr = "?";
	for(i=0;i<Params["keys"].length;i++) {
		querystr += Params["keys"][i]+"="+encodeURIComponent(Params["values"][i])+"&"; //or encodeURI
	}
	return querystr;
}

function URLEncode(decodedstr)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	//var plaintext = document.URLForm.F1.value;
	var plaintext = decodedstr;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
	//document.URLForm.F2.value = encoded;
	//return false;
}

function URLDecode(encodedstr)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   //var encoded = document.URLForm.F2.value;
   var encoded = encodedstr;
   
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
	return plaintext;
   //document.URLForm.F1.value = plaintext;
   //return false;
}

/*******************************************************************************
	Function fired when tabs are clicked on details page
**********************************************************************************/

function tab_clicked(evt){
	//alert('in tab clicked event');
	var child = Event.element(evt);
	//alert(child.id);
	if (Element.hasClassName(child,"hl")) {
		return;
	}
	else {
		hlMe(child);
		
		if (child.id == 'tellFriendTab') {
			var device_display_name = document.getElementById(child.id).getAttribute("device_display_name");
			var itemId = document.getElementById(child.id).getAttribute("itemid");
			var itemType = document.getElementById(child.id).getAttribute("itemType");
			
			ajaxLoader('tell_friend.do?device_display_name='+device_display_name+'&itemId='+itemId+'&itemType='+itemType,'tabsContent');
		}
		if (child.id == 'wishListTab') {
			var device_display_name = document.getElementById(child.id).getAttribute("device_display_name");
			var itemId = document.getElementById(child.id).getAttribute("itemid");
			var itemType = document.getElementById(child.id).getAttribute("itemType");
			//alert(device_display_name);
			ajaxLoader('wish_list.do?device_display_name='+device_display_name+'&itemId='+itemId+'&itemType='+itemType,'tabsContent');
		}
		else if (child.id == 'rateTab') {
			//var rating = $(child.id).getAttribute("itemrating");
			//alert(rating);
			ajaxLoader('rate_it.do?rating'+rating,'tabsContent');	
		}
	}
	Event.stop(evt);
}

/***************************************
	Fired when phone is changed
***************************************/
function checkPhone(pageURL) {
	
		var redirectURL = URLEncode(pageURL);
		//alert(redirectURL);
		document.location.href="device_changedevice.do?pagetoredirect="+redirectURL;
}

/******************************************************

	Called on click of Go Botton in Login home page
	Phone number etc is formatted
************************************************************/
function performLogin(submitURL) {
	
		//alert(submitURL);
	    var ptnValue = document.getElementById('virginptn').value;
	    
	    var charsToStrip = "()-. +";
	    
		var formattedPTN = stripCharsInBag (ptnValue, charsToStrip);
		document.getElementById('virginptn').value = formattedPTN;
		
		//alert(document.getElementById('virginptn').value);
		document.getElementById('commonForm').action = submitURL;
		submitPage(document.getElementById('commonForm'),'');
	    
		
	
}

/***************************************
	Fired when login is done
***************************************/
	
function login(pageURL) {

	var redirectURL = URLEncode(pageURL);
	//alert(redirectURL);
	document.location.href="login_loginhome.do?pagetoredirect="+redirectURL;
}

function submitPage(formObj) {
	 try {
	 
	    //alert(formObj.name);
	    var pageoffset = document.getElementById("pageroffset");
	    
	    if (pageoffset) {
	    	//document.all("pager.offset").value = 0;
	    	pageoffset.value = 0;
	    }
	    
	    if (formObj.pagenumberclicked)
			formObj.pagenumberclicked.value = "0";
	   
	  
		
		
		formObj.submit();
		
	
	  }
	  catch(Exception) {
	  	alert("in Exception of SubmitPage");
	  }
	 
}

/*******************************************************

This function clears Omniture variables

***********************************/
function clear_omniture_variables() {

	s.PageName="";
	s.hier1="";
	s.channel="";
	s.prop1="";
	s.prop2="";
	s.prop19="";
	s.prop21="";
	
	s.prop25="";
	s.prop11="";
	s.eVar11="";
	s.events="";
	s.products="";
	s.purchaseID="";
}

/*******************************************************

Debugging of Omniture variables

***********************************/

function debug_omniture_variables() {

	var o_variable = "pageName="+s.PageName+"|hier1="+s.hier1+"|channel="+s.channel+"|prop1="+s.prop1+"|prop2="+s.prop2+"|prop19="+s.prop19+"|prop21="+s.prop21+"|prop25="+s.prop25
						+ "|eVar11="+s.eVar11+"|events="+s.events+"|products="+s.products+"|purchaseID="+s.purchaseID;
	alert(o_variable);
}

/*******************************************************
This function set Omniture variables for the main home page
****************************************************************/

function set_omniture_variables_home(isLoggedIn) {

	s.pageName="Downloads: Downloads-NAC: What's Hot";
	s.hier1="Downloads: Downloads-NAC: What's Hot";
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: What's Hot";
	s.prop19="";
	
	if ('Y' == isLoggedIn)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
	s.prop25="";
	s.prop11="";
	s.eVar11="";
	s.events="";
	s.products="";
	s.purchaseID="";
	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/*******************************************************
This function set Omniture variables for each content type  home page
****************************************************************/

function set_omniture_variables_item_home(isLoggedIn,itemtype) {

	var content_name = "";
	switch(itemtype) {
	
		case "rt":
			content_name = "Ringtones";
			break;
			
		case "wp":
			content_name = "Graphics";
			break;
			
		case "rbt":
			content_name = "RingBack Tones";
			break;
			
		case "games":
			content_name = "Games";
			break;
			
		case "apps":
			content_name = "Applications";
			break;
	
	}

	s.pageName="Downloads: Downloads-NAC: "+ content_name+": Homepage";
	s.hier1="Downloads: Downloads-NAC: "+content_name+": Homepage";
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: "+content_name;
	s.prop19="";
	if ('Y' == isLoggedIn)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
	s.prop25="";
	s.prop11="";
	s.eVar11="";
	s.events="";
	s.products="";
	s.purchaseID="";

	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/*******************************************************
This function set Omniture variables for the category search
****************************************************************/

function set_omniture_variables_categories(itemtype,categoryname) {

	clear_omniture_variables();

	var content_name = "";
	switch(itemtype) {
	
		case "rt":
			content_name = "Ringtones";
			break;
			
		case "wp":
			content_name = "Graphics";
			break;
			
		case "rbt":
			content_name = "RingBack Tones";
			break;
			
		case "games":
			content_name = "Games";
			break;
			
		case "apps":
			content_name = "Applications";
			break;
	
	}
	
	s.pageName=" Downloads: Downloads-NAC: "+content_name+" : "+categoryname;
	s.hier1=" Downloads: Downloads-NAC: "+content_name+" : "+categoryname;
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: "+content_name;
	s.prop19="";
	
	//this id will be there only if you are logged in , else not
	var menuObj = document.getElementById("logged_in_menus");
	if (menuObj)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
	s.prop25="";
	s.prop11="";
	s.eVar11="Downloads-NAC";
	s.events="";
	s.products="";
	s.purchaseID="";

	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/*******************************************************
This function set Omniture variables for the Ringtones Artist search
****************************************************************/

function set_omniture_variables_artist_search(artistName) {

	clear_omniture_variables();

	
	s.pageName="Downloads: Downloads-NAC: Ringtones: "+ artistName;
	s.hier1="Downloads: Downloads-NAC: Ringtones: "+ artistName;
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: "+ artistName;
	s.prop19="";
	//this id will be there only if you are logged in , else not
	var menuObj = document.getElementById("logged_in_menus");
	if (menuObj)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
		
	s.prop11="";
	s.eVar11="Downloads-NAC";
	s.events="";
	s.products="";
	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/****************************************************************
This function set Omniture variables for the Item Details search
****************************************************************/

function set_omniture_variables_item_details(isLoggedIn,itemtype,itemName) {

	clear_omniture_variables();
	
	var content_name = "";
	switch(itemtype) {
	
		case "rt":
			content_name = "Ringtones";
			break;
			
		case "wp":
			content_name = "Graphics";
			break;
			
		case "rbt":
			content_name = "RingBack Tones";
			break;
			
		case "games":
			content_name = "Games";
			break;
			
		case "apps":
			content_name = "Applications";
			break;
	
	}
	
	s.pageName=" Downloads: Downloads-NAC: "+content_name+" : "+itemName;
	s.hier1=" Downloads: Downloads-NAC: "+content_name+" : "+itemName;
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: "+content_name;
	s.prop19="";
	if ('Y' == isLoggedIn)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
	s.prop11=""
	s.eVar11="Downloads-NAC";
	s.events="prodView";
	s.products=";Downloads-NAC: "+content_name+":"+itemName;

	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/****************************************************************
This function set Omniture variables for Global Search
****************************************************************/

function set_omniture_variables_global_search(isLoggedIn,itemtype,keyword,totalcount) {

	clear_omniture_variables();
	
	var content_name = "";
	switch(itemtype) {
	
		case "rt":
			content_name = "Ringtones";
			break;
			
		case "wp":
			content_name = "Graphics";
			break;
			
		case "rbt":
			content_name = "RingBack Tones";
			break;
			
		case "games":
			content_name = "Games";
			break;
			
		case "apps":
			content_name = "Applications";
			break;
	
	}
	
	s.pageName="Downloads: Downloads-NAC: Downloads-NAC Internal Search";
	s.hier1="Downloads: Downloads-NAC: Downloads-NAC Internal Search";
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: Downloads-NAC Internal Search";
	s.prop19="";
	if ('Y' == isLoggedIn)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
	
	//s.prop25="none" if no results found or s.prop25=<number of records found> if results are found
	//s.events="event5" (NOTE: If a null search, then you set to event 5. If successful search, don't set anything.)
	var recordcount = parseInt(totalcount,10);
	//alert(recordcount);
	if (recordcount >0) {
		s.prop11 = recordcount;
		s.events="";
	}
	else {
		s.prop11 = "none";
		s.events="event5";
	}
	s.eVar11="Downloads-NAC";
	s.products=""
	s.purchaseID=""


	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/****************************************************************
This function set Omniture variables for AOC page
****************************************************************/

function set_omniture_variables_aoc(isLoggedIn,itemtype,itemdisplayName) {

	clear_omniture_variables();
	
	var content_name = "";
	switch(itemtype) {
	
		case "rt":
			content_name = "Ringtones";
			break;
			
		case "wp":
			content_name = "Graphics";
			break;
			
		case "rbt":
			content_name = "RingBack Tones";
			break;
			
		case "games":
			content_name = "Games";
			break;
			
		case "apps":
			content_name = "Applications";
			break;
	
	}
	
	s.pageName="Downloads: Downloads-NAC: "+content_name+" : Purchase Confirmation Page";
	s.hier1="Downloads: Downloads-NAC: "+content_name+": Purchase Confirmation Page";
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: Purchase Confirmation Page";
	s.prop19="";
	if ('Y' == isLoggedIn)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
		
	s.prop25="";
	s.eVar11="Downloads-NAC";
	s.events="scCheckout";
	//s.products="Downloads-NAC: Ringtones: Muddy Waters: Hard Day Blues"
	s.products=";Downloads-NAC: "+content_name+":"+itemdisplayName;
	s.purchaseID="";
	
	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}

/****************************************************************
This function set Omniture variables for Purchase page
****************************************************************/

function set_omniture_variables_purchase(isLoggedIn,itemtype,itemdisplayName,orderId,itemPrice) {

	clear_omniture_variables();
	
	var content_name = "";
	switch(itemtype) {
	
		case "rt":
			content_name = "Ringtones";
			break;
			
		case "wp":
			content_name = "Graphics";
			break;
			
		case "rbt":
			content_name = "RingBack Tones";
			break;
			
		case "games":
			content_name = "Games";
			break;
			
		case "apps":
			content_name = "Applications";
			break;
	
	}
	
	
	s.pageName="Downloads: Downloads-NAC: "+content_name+" : Final Purchase Page";
	s.hier1="Downloads: Downloads-NAC: "+content_name+": Final Purchase Page";
	s.channel="Downloads";
	s.prop1="Downloads: Downloads-NAC";
	s.prop2="Downloads: Downloads-NAC: Final Purchase Page";
	s.prop19="";
	if ('Y' == isLoggedIn)
		s.prop21="Logged In";
	else
		s.prop21="Logged Out";
	s.prop25="";
	s.prop11="";
	s.eVar11="Downloads-NAC";
	s.events="purchase";
	//s.products=";Downloads-NAC: Ringtones: Muddy Waters: Hard Day Blues; 1; 2.50"
	s.products=";Downloads-NAC: "+content_name+":"+itemdisplayName+";1;"+itemPrice;
	s.purchaseID=orderId;
	
	
	//debug_omniture_variables();
	
	/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
	var s_code=s.t();
	if(s_code) document.write(s_code);
}
/*******************************************************

	For Getting item details
	BundleId is not used for the time being, so pass that as an empty parameter
	The toConformPage parameter indicates to go staring to confirmation page without showing the
	details page. Happens in case of ringtones when Buy Now is clicked.

***********************************/
function getItemDetails(itemType,itemId,maturity_flag,bundleId,toConfirmPage,fileExtensionRank) {

	//alert(itemType);
	document.getElementById('itemId').value=itemId;
	
	if(bundleId == 3 )
		document.getElementById('itemtype').value = "apps";
	else
		document.getElementById('itemtype').value=itemType;
		
	var mat_flag = "";
	if (isEmptyStr(maturity_flag) || maturity_flag == 'undefined')
		maturityFlag = "";
	else
		mat_flag = maturity_flag;
	
	var confirmpage = "";
	if (!isEmptyStr(toConfirmPage))
		confirmpage = 'Y';
	
	var fileExtRank = fileExtensionRank;
	if (isEmptyStr(fileExtensionRank))
		fileExtRank = '';
		
	//alert(confirmpage);
	//alert(fileExtRank);
	document.getElementById('commonForm').action='content_details.do?toConfirmPage='+confirmpage+'&maturity_flag='+mat_flag+'&fileExtRank='+fileExtRank;
	//alert(document.getElementById('commonForm').action);
	submitPage(document.forms['commonForm'],'');
	
}



/****************************************************

Fired when the category dropdown is changed

*********************************************************/
function OnChangeOfSelectedCategory(categoryId,cattext,itemtype) {
					
					if (document.getElementById('pageroffset')) document.getElementById('pageroffset').value=0;
					//var querystring = formaction.substr(pos);
					
					//Call for getting subcategories if any
					
					var SubCatParams = new Array("keys","values");		
					SubCatParams["keys"] = Array	("itemtype","categoryId","cattext","itemSubTypeId");
					SubCatParams["values"] = Array	(itemtype,categoryId,URLEncode(cattext),"");
					var url_subcat = "content_paintCategory.do"+createParams(SubCatParams);
					
					//var urlandparams = url_base + "?" + query;
					//alert("SUbcat URL:"+url_subcat);
					
					var catdivTag = itemtype+"_category_div";
					
					var subParams = createParams(SubCatParams);
					var opt = {
					    // Use GET
					    method: 'post',asynchronous:true,
					    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
					    postBody: subParams.substr(1), //to get rid of ?, 
					    onCreate: function(t) {
					       		document.getElementById(catdivTag).innerHTML = '<div style="padding:0; text-align:left !important; width:400px; height:250px;background:url(images/loading.gif) left left no-repeat;"></div>';
					    },
					     // Handle successful response
					    onSuccess: function(t) {
					    	var resp = t.responseText;
					    	//alert(resp);
					        //document.getElementById('page_results').innerHTML = resp;
					        //resp ="jjhhgg";
					        document.getElementById(catdivTag).innerHTML = resp;
					        
					    },
					   
					     // On Complete acts as a postfunction
					    onComplete: function(t) {
					    }
					}
			
					new Ajax.Request('content_paintCategory.do', opt);
					
					//document.location.href='content_paintCategory.do?itemtype='+itemtype+'&categoryId='+categoryId;
					//return;
					
					
					
					//Get the items for the category through Ajax call
					var ContentParams = new Array("keys","values");		
					ContentParams["keys"] = Array	("itemtype","categoryId","cattext","itemSubTypeId");
					ContentParams["values"] = Array	(itemtype,categoryId,URLEncode(cattext),"");
					var url_1 = "content_searchbycategory.do"+createParams(ContentParams);
					
					//var urlandparams = url_base + "?" + query;
					//alert("Final URL:"+url_1);
					
					var contentparams = createParams(ContentParams);
					var opt = {
					    // Use GET
					    method: 'post',asynchronous:true,
					    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
					    postBody: contentparams.substr(1), //to get rid of ?, 
					    onCreate: function(t) {
					       		document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loading.gif) center center no-repeat;"></div>';
					    },
					     // Handle successful response
					    onSuccess: function(t) {
					    	var resp = t.responseText;
					    	//alert(resp);
					        //document.getElementById('page_results').innerHTML = resp;
					        document.getElementById('page_results').innerHTML = resp;
					        
					    },
					   
					     // On Complete acts as a postfunction
					    onComplete: function(t) {
					    
					    	set_omniture_variables_categories(itemtype,cattext);
					    }
					}
			
					new Ajax.Request('content_searchbycategory.do', opt);
					return;
					//alert(selectedtext);
					/*var previousval = "";
					var previoustext = "";
					if (selectedindx > 0) {
						var previousindx = selectedindx - 1;
						var previousval = selCatObj[previousindx].value;
						var previoustext = stripInitialWhitespace(selCatObj[previousindx].text);
						previoustext = previoustext.replace("&#xA0;&#xA0;", "");
					}
					
					var nextval = "";
					var nexttext = "";
					if (selectedindx < len  - 1) {
						var nextindx = selectedindx + 1;
						var nextval = selCatObj[nextindx].value;
						var nexttext = stripInitialWhitespace(selCatObj[nextindx].text);
						nexttext = nexttext.replace("&#xA0;&#xA0;", "");
						
					}
					
					
					var indx = selectedindx;
					var formaction = "";
					
					
					if (selectedval == "hotapps")
					 	formaction = itemtype+"_home.do?itemtype="+itemtype+"&cattext=What%27s+Hot";
					 	
					else 
						formaction = "content_searchbycategory.do?itemtype="+itemtype+"&categoryId="+selectedval+"&cattext="+URLEncode(selectedtext);
					
					document.getElementById('commonForm').action = formaction;
					submitPage(document.getElementById('commonForm'),'');*/
					
}

/****************************************************

Fired when the href for category is clicked from the display above the content section

*********************************************************/
function OnClickOfCategoryHref(itemtype,categoryNodeId) {
					//var formaction = document.getElementById('contentform').action;
					//var pos = formaction.indexOf("?");
					//var urltouse;
					//if (pos != -1)
						//urltouse = formaction.substring(0,pos);
					//else
						//urltouse = formaction;
					//alert(urltouse);
					if (document.getElementById('pageroffset')) document.getElementById('pageroffset').value=0;
					//var querystring = formaction.substr(pos);
					var selCatObj = document.getElementById('categories');
					var len = document.getElementById('categories').options.length;
					//alert(len);
					//alert(categoryNodeId);
					var selectedindx = 0;
					//for hotapps value , it is the first node , so no need to check
					if (categoryNodeId != 'hotapps') {
						for(var j=0;j<len;j++) {
							var cat_dropdown_id = selCatObj[j].value;
							if (categoryNodeId == cat_dropdown_id) {
								selectedindx = j;
								break;
							}
						}
					}
					var selectedval = selCatObj[selectedindx].value;
					var selectedtext = selCatObj[selectedindx].text;
					
					if (selectedval == "hotapps") {
					 	formaction = itemtype+"_home.do?itemtype="+itemtype+"&cattext=What%27s+Hot";
						document.getElementById('commonForm').action = formaction;
						submitPage(document.getElementById('commonForm'),'');
						return;
					}
					
					//Get the items for the category through Ajax call
					var ContentParams = new Array("keys","values");		
					ContentParams["keys"] = Array	("itemtype","categoryId","cattext","itemSubTypeId");
					ContentParams["values"] = Array	(itemtype,selectedval,URLEncode(selectedtext),"");
					var url_1 = "content_searchbycategory.do"+createParams(ContentParams);
					
					//var urlandparams = url_base + "?" + query;
					//alert("Final URL:"+url_1);
					
					var contentparams = createParams(ContentParams);
					var opt = {
					    // Use GET
					    method: 'post',asynchronous:true,
					    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
					    postBody: contentparams.substr(1), //to get rid of ?, 
					    onCreate: function(t) {
					       		document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
					    },
					     // Handle successful response
					    onSuccess: function(t) {
					    	var resp = t.responseText;
					    	//resp = "sjgfkgfkasgf";
					    	//alert(resp);
					        document.getElementById('page_results').innerHTML = resp;
					        
					    },
					   
					     // On Complete acts as a postfunction
					    onComplete: function(t) {
					    }
					}
			
					new Ajax.Request('content_searchbycategory.do', opt);
					
					
					//alert(selectedindx);
					/*var previousval = "";
					var previoustext = "";
					if (selectedindx > 0) {
						var previousindx = selectedindx - 1;
						var previousval = selCatObj[previousindx].value;
						var previoustext = selCatObj[previousindx].text;
					}
					
					var nextval = "";
					var nexttext = "";
					if (selectedindx < len  - 1) {
						var nextindx = selectedindx + 1;
						var nextval = selCatObj[nextindx].value;
						var nexttext = selCatObj[nextindx].text;
					}
					
					
					var indx = selectedindx;
					var formaction = "";

					if (selectedval == "hotapps")
					 	formaction = itemtype+"_home.do?itemtype="+itemtype+"&cattext=What%27s+Hot";
					 	
					else 
						formaction = "content_searchbycategory.do?itemtype="+itemtype+"&categoryId="+selectedval+"&cattext="+URLEncode(selectedtext);
					document.getElementById('commonForm').action = formaction;
					submitPage(document.getElementById('commonForm'),'');*/
					
}


/****************************************************

Fired when ItemType is changed in Ringtone default page

*********************************************************/
function OnChangeOfRTTypes(spanObj) {
		
		//var selRtTypes = document.getElementById('ringtone_subtypes');
		//alert(spanObj.id);
		var selRtTypes = document.getElementById(spanObj.id+'_rtsubtypes');
		
		//Remove the first option Ringtone Type .. that is just a display for default page for RT
		//if (selRtTypes)
			//removeOption(spanObj.id+'_rtsubtypes', "0");
		
		document.getElementById('rt_searchString').value = '';
		var selectedOptionObj = selRtTypes[selRtTypes.selectedIndex];
		
		
		
		var selectedval = selectedOptionObj.value;
		var selectedtext = selectedOptionObj.text;
		//alert(selectedval);
		
		var array_val = selectedval.split(","); 
		var itemTypeId = array_val[0];
		var itemSubTypeId = array_val[1];
		var categoryId = array_val[2];
		//alert(itemSubTypeId);
		
		//for Changing to "Ringtone Type" selection option , no call takes place
		if (categoryId == 0 || categoryId == undefined) {
			document.getElementById('rtMainContent').innerHTML = '';
			document.getElementById('rtSubTypeForm_rtsubtypes').selectedIndex = 0;
			document.getElementById('categoryForm_rtsubtypes').selectedIndex = 0;
			
			document.getElementById('d_rtSubTypeForm_category').innerHTML = '<select name="rtSubTypeForm_category" id="rtSubTypeForm_category" style="width: 180px; margin: 4px 0px 0px 4px;" onchange="onchangeOfRtSubCategory($(\'rtSubTypeForm\'));"><option value="">Style</option></select>';
		    document.getElementById('d_categoryForm_category').innerHTML='<select name="categoryForm_category" id="categoryForm_category" style="width: 180px; margin: 4px 0px 0px 4px;" onchange="onchangeOfRtSubCategory($(\'categoryForm\'));"><option value="">Style</option></select>';
			
			
			//alert('here');
			return;
		}
		

		//Get the items for the category through Ajax call
		var CategoryParams = new Array("keys","values");		
		CategoryParams["keys"] = Array	("itemtype","categoryId","itemSubTypeId");
		CategoryParams["values"] = Array	("rt",categoryId,itemSubTypeId);
		var url_1 = "content_rt_getCategories.do"+createParams(CategoryParams);
		
		//var urlandparams = url_base + "?" + query;
		//alert("Final URL:"+url_1);
		
		var catparams = createParams(CategoryParams);
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: catparams.substr(1), //to get rid of ?, 
		    onCreate: function(t) {
		       		//document.getElementById('d_rtSubTypeForm_category').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		       		//document.getElementById('d_categoryForm_category').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText;
		    	//alert(resp);
		        //document.getElementById('rtSubTypeForm_category').innerHTML = resp;
		        document.getElementById('d_rtSubTypeForm_category').innerHTML = '<select name="rtSubTypeForm_category" id="rtSubTypeForm_category" style="width: 180px; margin: 4px 0px 0px 4px;" onchange="onchangeOfRtSubCategory($(\'rtSubTypeForm\'));"><option value="">Style</option>'+resp+'</select>';
		        document.getElementById('d_categoryForm_category').innerHTML='<select name="categoryForm_category" id="categoryForm_category" style="width: 180px; margin: 4px 0px 0px 4px;" onchange="onchangeOfRtSubCategory($(\'categoryForm\'));"><option value="">Style</option>'+resp+'</select>';
		        
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    
		    	if (spanObj.id == 'rtSubTypeForm') {
		    		
		    		//alert(document.getElementById('rtSubTypeForm_rtsubtypes').innerHTML);
		    		document.getElementById('d_categoryForm_types').innerHTML = '<select name="categoryForm_rtsubtypes" id="categoryForm_rtsubtypes" onchange="OnChangeOfRTTypes($(\'categoryForm\'));" style="width: 180px; margin-left: 4px;">'+ document.getElementById('rtSubTypeForm_rtsubtypes').innerHTML+'</select>';
		    		document.getElementById('categoryForm_rtsubtypes').selectedIndex = document.getElementById('rtSubTypeForm_rtsubtypes').selectedIndex;
		    	}
		    		
		    	if (spanObj.id == 'categoryForm') {
		    		
		    		document.getElementById('d_rtSubTypeForm_types').innerHTML = '<select name="rtSubTypeForm_rtsubtypes" id="rtSubTypeForm_rtsubtypes" onchange="OnChangeOfRTTypes($(\'rtSubTypeForm\'));" style="width: 180px; margin-left: 4px;">'+ document.getElementById('categoryForm_rtsubtypes').innerHTML+'</select>';
		    		document.getElementById('rtSubTypeForm_rtsubtypes').selectedIndex = document.getElementById('categoryForm_rtsubtypes').selectedIndex;
		    	}
		    }
		}
			
		new Ajax.Request('content_rt_getCategories.do', opt);
		
		//Get the items for the category through Ajax call
		var ContentParams = new Array("keys","values");		
		ContentParams["keys"] = Array	("itemtype","categoryId","cattext","itemSubTypeId");
		ContentParams["values"] = Array	("rt",categoryId,URLEncode(selectedtext),itemSubTypeId);
		var url_1 = "content_searchbycategory.do"+createParams(ContentParams);
		
		//var urlandparams = url_base + "?" + query;
		//alert("Final URL:"+url_1);
		
		var contentparams = createParams(ContentParams);
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: contentparams.substr(1), //to get rid of ?, 
		    onCreate: function(t) {
		       		document.getElementById('rtMainContent').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText;
		    	//resp = "sjgfkgfkasgf";
		    	//alert(resp);
		        document.getElementById('rtMainContent').innerHTML = resp;
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    }
		}
			
		new Ajax.Request('content_searchbycategory.do', opt);
		return;
		//var formaction = "";
		//formaction = "content_searchbycategory.do?itemtype=rt&categoryId="+categoryId+"&cattext="+URLEncode(selectedtext)+"&itemSubTypeId="+itemSubTypeId;
		//formObj.action = formaction;
		//formObj.submit();
	
}

/********************************************************
	Fired when the RT Sub category dropdown is changed
**********************************************************/
function onchangeOfRtSubCategory() {

		var categoryObj = document.getElementById('rtSubTypeForm_category');
		var selcategoryObj = categoryObj[categoryObj.selectedIndex];
		var selected_category_val = selcategoryObj.value;
		var selected_category_text = selcategoryObj.text;
		
		if (isEmptyStr(selected_category_val)) {
			alert('Please select a category for Search');
			return;
		}

		var KeyWordParams = new Array("keys","values");		
			KeyWordParams["keys"] = Array	("itemtype","categoryId","cattext");
			KeyWordParams["values"] = Array	("rt",selected_category_val,URLEncode(selected_category_text));
			var url_1 = "content_searchbycategory.do"+createParams(KeyWordParams);
			
			//var urlandparams = url_base + "?" + query;
			//alert("Final URL:"+url_1);
			
			var contentparams = createParams(KeyWordParams);
			var opt = {
			    // Use GET
			    method: 'post',asynchronous:true,
			    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
			    postBody: contentparams.substr(1), //to get rid of ?, 
			    onCreate: function(t) {
			       		document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
			    },
			     // Handle successful response
			    onSuccess: function(t) {
			    	var resp = t.responseText;
			    	//resp = "sjgfkgfkasgf";
			    	//alert(resp);
			        document.getElementById('page_results').innerHTML = resp;
			        
			    },
			   
			     // On Complete acts as a postfunction
			    onComplete: function(t) {
			    }
			}
				
			new Ajax.Request('content_searchbycategory.do', opt);
   	

}

/********************************************************8
	Using the Enter button for Search
***************************************************************/
function doRtSearch(buttonName,e) {
//the purpose of this function is to allow the enter key to 
//point to the correct button to click.
        var key;

         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
    
        if (key == 13) //Enter key
        {
        	//alert('here1');
            //Get the button the user wants to have clicked
            var btn = document.getElementById(buttonName);
            if (btn != null)
            { //If we find the button click it
            
            	OnClickOfRTGoBtn();
                //btn.click();
                event.keyCode = 0
            }
        }
}

/*****************************************
	Fired from the main Home Page or Stuff page for RT search
************************************************/
function doRTStuffSearch(buttonName,e) {

	var key;

		 var searchstring = $F('rt_searchString');
         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
    
        if (key == 13) //Enter key
        {
        	//alert('here1');
            //Get the button the user wants to have clicked
            var btn = document.getElementById(buttonName);
            if (btn != null)
            { //If we find the button click it
            
            	//alert(searchstring);
            	window.location.href='globalsearch.do?itemtype=rt&searchfield='+searchstring;
                //btn.click();
                event.keyCode = 0
            }
        }

	
}



/********************************************************
	Fired when the GO Button in RT default page is clicked
**********************************************************/
function OnClickOfRTGoBtn() {

		
		var keyword_search = document.getElementById('rt_searchString').value;
		
		
		//Do all this for keyword search
		if (!isEmptyStr(keyword_search) && keyword_search != 'TITLE OR ARTIST') {
		
		
			if (keyword_search.length < 3) {
				alert("SearchField must be 3 characters");
				return;
			}
			
			
			var KeyWordParams = new Array("keys","values");		
			KeyWordParams["keys"] = Array	("itemtype","keyword");
			KeyWordParams["values"] = Array	("rt",URLEncode(keyword_search));
			var url_1 = "content_searchrt.do"+createParams(KeyWordParams);
			
			//var urlandparams = url_base + "?" + query;
			//alert("Final URL:"+url_1);
			
			var contentparams = createParams(KeyWordParams);
			var opt = {
			    // Use GET
			    method: 'post',asynchronous:true,
			    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
			    postBody: contentparams.substr(1), //to get rid of ?, 
			    onCreate: function(t) {
			       		document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
			    },
			     // Handle successful response
			    onSuccess: function(t) {
			    	var resp = t.responseText;
			    	//resp = "sjgfkgfkasgf";
			    	//alert(resp);
			        document.getElementById('page_results').innerHTML = resp;
			        
			    },
			   
			     // On Complete acts as a postfunction
			    onComplete: function(t) {
			    }
			}
				
			new Ajax.Request('content_searchrt.do', opt);
			
			return;
		
		}
		//End of Keyword search
		
		//If keyword is not specified , do the below
		if (isEmptyStr(selectedval)) {
		
			//alert("Sub Category is empty");
			OnChangeOfRTTypes(spanObj);
			return;
		
		}
		else {
			selected_category_val = categoryObj[categoryObj.selectedIndex].value;
			selected_category_text = categoryObj[categoryObj.selectedIndex].text;
		}
		
		//Get the items for the category through Ajax call
		var ContentParams = new Array("keys","values");		
		ContentParams["keys"] = Array	("itemtype","categoryId","cattext","itemSubTypeId");
		ContentParams["values"] = Array	("rt",selected_category_val,URLEncode(selected_category_text),itemSubTypeId);
		var url_1 = "content_searchbycategory.do"+createParams(ContentParams);
		
		//var urlandparams = url_base + "?" + query;
		//alert("Final URL:"+url_1);
		
		var contentparams = createParams(ContentParams);
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: contentparams.substr(1), //to get rid of ?, 
		    onCreate: function(t) {
		       		document.getElementById('rtMainContent').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText;
		    	//resp = "sjgfkgfkasgf";
		    	//alert(resp);
		        document.getElementById('rtMainContent').innerHTML = resp;
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    }
		}
			
		new Ajax.Request('content_searchbycategory.do', opt);

}

/*******************************************************
	This function fired when phone is changed
	Puts the device parameters in session through Ajax
*******************************************************************/

function onChangeOfPhone(deviceId,deviceName,deviceImage,redirectURL,deviceSKU) {

	//alert('here');
	//alert(top.document.forms['commonForm'].action);
	
	var destination_url = redirectURL;
	if (isEmptyStr(destination_url)) {
		//alert('here');
		destination_url = "home.do?menu=whatshot&itemtype=";
	}
	
	//alert(destination_url);
	var ContentParams = new Array("keys","values");		
	ContentParams["keys"] = Array	("deviceid","deviceName","deviceImage","deviceSKU","redirectURL");
	ContentParams["values"] = Array	(deviceId,deviceName,deviceImage,deviceSKU,destination_url);
	var url_1 = "device_setDeviceinSession.do"+createParams(ContentParams);
	
	//var urlandparams = url_base + "?" + query;
	//alert("Final URL:"+url_1);
	
		var contentparams = createParams(ContentParams);
		var opt = {
				    // Use GET
				    method: 'post',asynchronous:true,
				    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
				    postBody: contentparams.substr(1), //to get rid of ?, 
				    onCreate: function(t) {
				    	//if (sync_var_bucketII == 0)
				       		//document.getElementById('buckets_containerII').innerHTML = '<div style="padding:0 0 0 8px; text-align:center !important; width:222px; height:174px;background:url(images/loading2.gif) center center no-repeat;"></div>';
				    },
				     // Handle successful response
				    onSuccess: function(t) {
				    	//var resp = t.responseText; //getting the disbaled array from here
				        //document.getElementById('ul_alldevices').innerHTML = resp;
				        
				    },
				   
				     // On Complete acts as a postfunction
				    onComplete: function(t) {
				    	var resp = t.responseText;
				    	//alert(resp);
				    	
				    	/*if (resp == 'not_a_java_device') {
				    		document.location.href='gameslite.do';
				    		return;
				    	}
				    	else*/
				    		document.location.href=URLDecode(destination_url);
				    }
				}
			
		new Ajax.Request('device_setDeviceinSession.do', opt);

}

/***********************************************
	Sets Logged in device in Session before purchasing from details page directlyu
***************************************************/
function setlogindeviceinSession(redirectURL,loggedindeviceId) {

	document.location.href='device_setLoggedInDeviceinSession.do?logged_in_deviceid='+loggedindeviceId+'&toURL='+redirectURL;
}

function checkBrowser() {

	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}

/**************************************
	Searches on Press of Enter Key
*******************************/
function OnKeyPressOfGlobalSearch(buttonName,e) {

		var whichBrowser = checkBrowser();
		
		 var key;

         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
    
        if (key == 13) //Enter key
        {
        	//alert('here1');
            //Get the button the user wants to have clicked
            var btn = document.getElementById(buttonName);
            if (btn != null)
            { //If we find the button click it
            
            	//alert(btn.id);
            	//alert(whichBrowser);
            	transitSearch('',$F('keyword'));
                //btn.click();
                
                if ('Internet Explorer' == whichBrowser)
                	window.event.keyCode = 0;
                	
                if ('Firefox' == whichBrowser)
                	return false;
            }
        }

		//if ((window.event.keyCode == 13) && ((window.event.srcElement.name == "keysearchfield"))) {
			//alert('here in globalsearch');
			//transitSearch('',document.getElementById('keyword').value);
		//}
}


/*********************************************************
	For Global Search

***************************************************************/
function transitSearch(itemType,searchfield,paginate){

		//alert(searchfield);
		if (isEmptyStr(searchfield) || searchfield.length < 3) {
			searchfield = '';
			alert('SearchField should have at least 3 characters');
			document.getElementById('commonForm').action = '';
			return false;
		}
		

		//Searchfield must contain at least one alphanumeric character even if there is a special character
		var alpha_chars = 0;
		var special_chars = 0;
		for(var j=0; j<searchfield.length; j++)
		{
		  var alphaa = searchfield.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  		alpha_chars = 1;
		  }
		  else	{
		  	 special_chars = 1;
			
		  }
		}
		
		if (alpha_chars == 0 && special_chars == 1) {
			 alert('SearchField must have alphanumeric characters');
			 return false;
		}

		
		//var url = 'globalsearch.do?searchfield='+searchfield+'&itemtype='+itemType;
		//alert(url);
		//window.location.href = url;
		
		var actionURL = 'globalsearch.do?searchfield='+searchfield;
		if (!isEmptyStr(itemType))
			actionURL = 'globalsearch.do?searchfield='+searchfield+'&itemtype='+itemType;
			
		if ('Y' == paginate)
			actionURL = actionURL + "&paginate=Y";
			
		document.location.href = actionURL;
		
		//document.getElementById('commonForm').action= actionURL;
		
		/*document.getElementById('commonForm').action='globalsearch.do?paginate=Y&searchfield='+searchfield;
		if (!isEmptyStr(itemType))
			document.getElementById('commonForm').action= 'globalsearch.do?paginate=Y&searchfield='+searchfield+'&itemtype='+itemType;*/
		//submitPage(document.forms['commonForm'],'');
}

/********************************************************

	Adding or Removing an item from Wish List
****************************************************************/
function addorRemovefromWishList(itemId,itemName,scope,dovalidation ) {
	
		//alert('here1');
		/*if (dovalidation == '1') {
			var valid = new Validation('commonForm', {onSubmit:false,stopOnFirst:true,useTitles : true});
			
		    var result = valid.validate();
		    //alert(result);
		    if (!result)
		    	return;
		}*/

	    
	    if ('add' == scope) {
	    	var ajaxurl = 'content_addtowishlist.do?itemId='+itemId+'&itemName='+ itemName;
	    	ajaxLoader(ajaxurl,'tabsContent');
	    }
	    
	     if ('remove' == scope) {
	    	var ajaxurl = 'content_removefromwishlist.do?itemId='+itemId+'&itemName='+ itemName;
	    	ajaxLoader(ajaxurl,'tabsContent');
	    }
	    
	    //Fired when WishList is displayed and Delete is clickewd from there
	    if ('removefromview' == scope) {
	    	window.location.href='content_removefromwishlist.do?itemId='+itemId+'&itemName='+ itemName+'&refreshlist=Y';
	    	
	    }
	
}

/********************************************************

	Gets the checked price Model
****************************************************************/
function getCheckedPriceModel()
{
	//var inputs = document.getElementsByTagName('input');
	var prices = document.getElementsByName('priceModel');
	var len = prices.length;
	//alert(len);
	
	if (isNaN(len)) {
		//alert('dfhgkjdfhgkjdfgkjdfshgkjsg');
		return prices;
	}
		
	var ids = new Array();
	for(var i = 0; i < prices.length; i++)
	{
		//if(inputs[i].getAttribute('id').toLowerCase().substr(0,4) == 'myid')
		if(prices[i].checked)
		{
			//inputarray.push(inputs[i].getAttribute('id'));
			return prices[i];
			break;
		}
	}
}
	
/***********************************************************
Places the Order from the web
order_details_id is set as an attribute when proce is clikced from price_clicked
Basically the id of <li id="price0" i,e price0 or price 1  in the details page is set in the 
attribute order_details_id and them the itemId etc are fetched 
*****************************************************************/
function placeorder(el,formObj,isLoggedIn,orderType) {

	//alert(isLoggedIn);
	if ('Y' != isLoggedIn) {
		document.getElementById('login_msg').innerHTML = "Please Login to Buy the Item";
		if (document.getElementById('virginptn'))
			document.getElementById('virginptn').focus();
		return;
	}
	var params = "";


	if(document.getElementById(el).type && document.getElementById(el).type.toLowerCase() == 'radio') {
        var radioGroup = document.getElementById(el).name;
        var el = document.getElementById(el).form;
    } else if (document.getElementById(el).tagName.toLowerCase() != 'form') {
        return false;
    }
 	
 	//Get the checked radio button
    /*var checked_pricemodel = document.getElementById(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );*/
    
    var checked_pricemodel = getCheckedPriceModel();
    //alert(checked_pricemodel.type);
    
    //alert(checked_pricemodel.id);
    //return (checked) ? $F(checked) : null;
    
    var itemId = checked_pricemodel.getAttribute("itemid");
    var settlementId = checked_pricemodel.getAttribute("settlementId");
    var settlementName = checked_pricemodel.getAttribute("settlementName");
	var itemTypeId = checked_pricemodel.getAttribute("itemTypeId");
	var pricemodelId = checked_pricemodel.getAttribute("priceModelId");
	//alert(pricemodelId);
	var device_display_name = checked_pricemodel.getAttribute("device_display_name");
	var maturityFlag = checked_pricemodel.getAttribute("maturityFlag");
	var developername = checked_pricemodel.getAttribute("developername");
	var companyId = checked_pricemodel.getAttribute("companyid");
	var itemtype = checked_pricemodel.getAttribute("itemtype");
	var itemSubTypeId = checked_pricemodel.getAttribute("itemSubTypeId");
	var promotionId = checked_pricemodel.getAttribute("promotionId");
	var bundletypeid = checked_pricemodel.getAttribute("bundletypeid");
	var bundlesize = checked_pricemodel.getAttribute("bundlesize");
	var externalItemId = checked_pricemodel.getAttribute("externalItemId");
	
	
	var promo_code_entered = '';
	if (document.getElementById('item_promocode')) {
		promo_code_entered = $F('item_promocode');
		if (isEmptyStr(promo_code_entered))
			promo_code_entered = "";
	}
	
	var artist = "";
	if (itemtype == 'rt') {
		rtpreveiwurl = checked_pricemodel.getAttribute("rtpreveiwurl");
		artist = checked_pricemodel.getAttribute("artist");
	}
	else {
		rtpreveiwurl = "";
		artist = "";
	}
	
	if (isEmptyStr(artist))
		artist = "";
		
	if (isEmptyStr(externalItemId))
		externalItemId = "";
	
	
	//Purchase by Credits
	if (orderType == 'getbycredits') {
		var credit_orderId = checked_pricemodel.getAttribute("credit_orderId");
		params = "&itemSubTypeId="+itemSubTypeId+"&externalItemId="+externalItemId+"&artist="+artist+"&ordertype=getbycredits&credit_orderId="+credit_orderId+"&itemTypeId="+itemTypeId+"&itemId="+itemId+"&itemtype="+itemtype+"&device_display_name="+device_display_name;
	
		//alert('getbycreditsparams: '+params);
		window.location.href = 'content_buywithcredits.do?'+params;
		return;
	}
	
	
	if (isEmptyStr(promotionId))
		promotionId = "0";
		
	if (isEmptyStr(bundletypeid))
		bundletypeid = "";
		
	if (isEmptyStr(bundlesize))
		bundlesize = "";
	
	var rtpreveiwurl = "";
	

	
	params = params + "itemId="+itemId+"&";
	//if (order_details_obj_id.indexOf("price") != -1) {
		var dollar_price = checked_pricemodel.getAttribute("price"); //this is the best price attribute in ItemPriceDTO
		params = params + "dollar_price="+dollar_price+"&";
		var listPrice = checked_pricemodel.getAttribute("listPrice");
	//}

	params = params + "&promo_code_entered="+promo_code_entered+"&listPrice="+listPrice+"&externalItemId="+externalItemId+"&bundlesize="+bundlesize+"&bundletypeid="+bundletypeid+"&itemtype="+itemtype+"&artist="+artist+"&promotionId="+promotionId+"&itemSubTypeId="+itemSubTypeId+"&pricemodelId="+pricemodelId+"&settlementId="+settlementId+"&settlementName="+settlementName+"&itemTypeId="+itemTypeId+"&device_display_name="+device_display_name+"&developerName="+developername+"&maturityFlag="+maturityFlag+"&companyId="+companyId+"&rtpreveiwurl="+rtpreveiwurl;
	
	
	//alert(params);
	
	//return;

	window.location.href = 'content_placeorder.do?'+params;
	//formObj.submit();
}

/****************************************************
	Validating promotion code entered in the box
********************************************************/
function validatePromoCode(itemId,fileExtRank,promo_code) {

	if (isEmptyStr(promo_code)) {
		alert('Please entere a valid Promotion Code');
		return;
	}
	var url = 'content_validatePromoCode.do?itemId='+itemId+'&fileExtRank='+fileExtRank+'&promotionCode='+promo_code;
	//window.location.href = url;
	//alert(url);
	
	
	var contentparams = 'itemId='+itemId+'&fileExtRank='+fileExtRank+'&promotionCode='+promo_code;
	//var contentparams = 'itemId=80328&fileExtRank=1&promotionCode='+promo_code;
		var opt = {
				    // Use GET
				    method: 'post',asynchronous:true,
				    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
				    postBody: contentparams, //to get rid of ?, 
				    onCreate: function(t) {
				    	document.getElementById('promoerror').innerHTML = "Validating Promotion Code.....";
				    },
				     // Handle successful response
				    onSuccess: function(t) {
				    	var resp = t.responseText; //getting the disbaled array from here
				        //document.getElementById('ul_alldevices').innerHTML = resp;
				        
				        if (resp == -1) {
				        	//alert('Error');
				        	document.getElementById('promoerror').innerHTML = "Invalid Promotion Code";
				        }
				        else {
				        	document.getElementById('promoerror').innerHTML = '';
				        	document.getElementById('sp_item_prices').innerHTML = resp;
				        }
				        
				    },
				   
				     // On Complete acts as a postfunction
				    onComplete: function(t) {
				    	
				    }
				}
			
		new Ajax.Request('content_validatePromoCode.do', opt);

}


/***********************************************************************
		Assigns a RBT to the account
************************************************************************/
function assignRBT(externalItemId,itemId,orderId,loggedInPTN) {

	var contentparams = 'itemId='+itemId+'&externalItemId='+externalItemId+'&orderId='+orderId+'&loggedInPTN='+loggedInPTN;
	//var contentparams = 'itemId=80328&fileExtRank=1&promotionCode='+promo_code;
	//alert(contentparams);
		var opt = {
				    // Use GET
				    method: 'post',asynchronous:true,
				    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
				    postBody: contentparams, //to get rid of ?, 
				    onCreate: function(t) {
				    	document.getElementById('rbt_status').innerHTML = "Assigning RingBackTone to Account.Please wait.....";
				    	if (document.getElementById('rtalbum'))
				        		document.getElementById('rtalbum').style.display = 'none';
				    },
				     // Handle successful response
				    onSuccess: function(t) {
				    	var resp = t.responseText; //getting the disbaled array from here
				        document.getElementById('rbt_status').innerHTML = resp;
				        document.getElementById('rtalbum').style.display = '';
				        
				        //if (resp.indexOf("Error") == -1) {
				       		//if (document.getElementById('rtalbum'))
				        		//document.getElementById('rtalbum').style.display = '';
				        //}
				       

				    },
				   
				     // On Complete acts as a postfunction
				    onComplete: function(t) {
				    	
				    }
				}
			
		new Ajax.Request('content_assignRBT.do', opt);



}


/***************************************
	Fired when final confirmation for buy is clicked
***************************************/
	
function finalorder(pageURL) {

	var redirectURL = URLDecode(pageURL);
	//redirectURL = "/virgin"+redirectURL+"&placefinalorder=Y";
	redirectURL = redirectURL+"&placefinalorder=Y";
	document.getElementById('okBtn').innerHTML= '<img src=images/virgin/but_ok_fade.gif border=0/>';
	document.getElementById('cancelBtn').innerHTML= '<img src=images/virgin/but_cancel_fade.gif border=0/>';
	//Element.update('okBtn','<img src=images/virgin/but_ok_fade.gif border=0/>');
	//Element.update('cancelBtn','<img src=images/virgin/but_cancel_fade.gif border=0/>');
	//document.getElementById('okBtn').innerHTML='<img src=images/virgin/but_ok_fade.gif border=0/>
	//alert(redirectURL);
	document.location.href=redirectURL;
}

/***************************************
	Fired when cancel button is clicked on the Buy Confirm page
***************************************/
function gobacktoDetail(pageURL) {

	var redirectURL = URLDecode(pageURL);
	//redirectURL = "/virgin"+redirectURL+"&placefinalorder=Y";
	
	var query = fleegix.uri.getQuery(redirectURL);
	var url_base = fleegix.uri.getBase(redirectURL); //portion before the question mark
	var itemType = fleegix.uri.getParam('itemtype', query);
	var itemId = fleegix.uri.getParam('itemId', query);
	var bundleItemId = fleegix.uri.getParam('bundleItemId',query);
	
	if(!isNaN(bundleItemId)) {
		itemId = bundleItemId;
	}
	
	document.location.href='content_details.do?itemId='+itemId+'&itemtype='+itemType;

}


/***************************************
	Fired when final confirmation for buy is clicked
***************************************/
	
function sortOrders(pageURL,sortFlag,sortOrder) {

	var redirectURL = URLDecode(pageURL);
	//alert(redirectURL);
	var query = fleegix.uri.getQuery(redirectURL);
	var url_base = fleegix.uri.getBase(redirectURL); //portion before the question mark
	query = fleegix.uri.setParam('sortFlag', sortFlag, query);
	query = fleegix.uri.setParam('sortOrder', sortOrder, query);
	//var finalURL = "/virgin"+url_base+"?"+query;
	var finalURL = url_base+"?"+query;
	//alert(finalURL);
	document.location.href=finalURL;
}

/***************************************
	Fired when listing results needs to be sorted 
	for sorting global search results
***************************************/
	
function sortResults(pageURL,sortFlag,sortOrder) {

	var redirectURL = URLDecode(pageURL);
	//alert(redirectURL);
	var query = fleegix.uri.getQuery(redirectURL);
	var url_base = fleegix.uri.getBase(redirectURL); //portion before the question mark
	query = fleegix.uri.setParam('sortFlag', sortFlag, query);
	query = fleegix.uri.setParam('sortOrder', sortOrder, query);
	query = fleegix.uri.setParam('pageroffset', '0', query);
	//var finalURL = "/virgin"+url_base+"?"+query;
	var finalURL = url_base+"?"+query;
	//alert(finalURL);
	document.location.href=finalURL;
}

/****************************************************

This function fired when the redownload link is clicked

*********************************************************/
function redownload(orderId,devicedisplayName,itemTypeId,divId) {

		//alert('here');
		var contentparams = "orderId="+orderId+"&device_display_name="+devicedisplayName+"&itemTypeId="+itemTypeId;
		//alert(contentparams);
		var opt = {
				    // Use GET
				    method: 'post',asynchronous:true,
				    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
				    postBody: contentparams, //to get rid of ?, 
				    onCreate: function(t) {
				    	//if (document.getElementById('redownloadstatus'))
				       		//document.getElementById('redownloadstatus').innerHTML = '<br/><b>Sending link to Phone ..</b>';
				       	if (document.getElementById(divId))
				       		document.getElementById(divId).innerHTML = '<br/><b>Sending link to Phone ..</b>';
				    },
				     // Handle successful response
				    onSuccess: function(t) {
				    	var resp = t.responseText; //getting the disbaled array from here
//				        document.getElementById('redownloadstatus').innerHTML = '<br/><b>'+resp+'</b>';
				        document.getElementById(divId).innerHTML = '<br/><b>'+resp+'</b>';
				        
				    },
				   
				     // On Complete acts as a postfunction
				    onComplete: function(t) {
				    }
				}
			
		new Ajax.Request('content_redownload.do', opt);

}

/***************************************
	Sorts the result by categories
***************************************/
	
function sortCategories(pageURL,sortFlag,sortOrder) {

	var redirectURL = URLDecode(pageURL);
	//alert(redirectURL);
	var query = fleegix.uri.getQuery(redirectURL);
	var url_base = fleegix.uri.getBase(redirectURL); //portion before the question mark
	query = fleegix.uri.setParam('sortFlag', sortFlag, query);
	query = fleegix.uri.setParam('sortOrder', sortOrder, query);
	query = fleegix.uri.setParam('pageroffset', '0', query);
	//var finalURL = "/virgin"+url_base+"?"+query;
	var finalURL = url_base+"?"+query;
	//alert(finalURL);
	//document.location.href=finalURL;
	
	var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: query, //to get rid of ?, 
		    onCreate: function(t) {
		    	//document.getElementById('rtMainContent').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    	document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText; //getting the disbaled array from here
		        //document.getElementById('rtMainContent').innerHTML = resp;
		        document.getElementById('page_results').innerHTML = resp;
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    }
		}
			
		new Ajax.Request(url_base, opt);
}

/************************************************
	Doing pagination for Prev in Ringtones page
***************************************************/
function paginate_prev(pageURL) {
	
		//alert(pageURL);
		var query = fleegix.uri.getQuery(pageURL);
		var url_base = fleegix.uri.getBase(pageURL); //portion before the question mark
		var prev_index = fleegix.uri.getParam('prevIndex',query);
		query = fleegix.uri.setParam('pageroffset', prev_index, query);
		query = fleegix.uri.setParam('paginate', 'Y', query);
		var finalURL = url_base+"?"+query;
		//alert(finalURL);
		
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: query, //to get rid of ?, 
		    onCreate: function(t) {
		    	//document.getElementById('rtMainContent').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    	document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText; //getting the disbaled array from here
		        //document.getElementById('rtMainContent').innerHTML = resp;
		        document.getElementById('page_results').innerHTML = resp;
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    }
		}
			
		new Ajax.Request(url_base, opt);
}

/************************************************
	Doing pagination for Next in Ringtones page
***************************************************/
function paginate_next(pageURL) {
	
		//alert(pageURL);
		var query = fleegix.uri.getQuery(pageURL);
		var url_base = fleegix.uri.getBase(pageURL); //portion before the question mark
		var next_index = fleegix.uri.getParam('nextIndex',query);
		query = fleegix.uri.setParam('pageroffset', next_index, query);
		query = fleegix.uri.setParam('paginate', 'Y', query);
		//var finalURL = url_base+"?"+query;
		//alert(finalURL);
		
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: query, //to get rid of ?, 
		    onCreate: function(t) {
		    	//document.getElementById('rtMainContent').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    	document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    	
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText; //getting the disbaled array from here
		        //document.getElementById('rtMainContent').innerHTML = resp;
		        document.getElementById('page_results').innerHTML = resp;
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    }
		}
			
		new Ajax.Request(url_base, opt);
		
		//document.getElementById('rtMainContent').innerHTML = "testing next";
}

/************************************************
	Doing pagination for Category Search
***************************************************/
function paginate(pageURL,itemtype) {
	
		//alert(pageURL);
		var query = fleegix.uri.getQuery(pageURL);
		var url_base = fleegix.uri.getBase(pageURL); //portion before the question mark
		//var next_index = fleegix.uri.getParam('nextIndex',query);
		//query = fleegix.uri.setParam('pageroffset', next_index, query);
		query = fleegix.uri.setParam('paginate', 'Y', query);
		var finalURL = url_base+"?"+query;
		//alert(finalURL);
		
		
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    //postBody: 'thisvar=true&thatvar=Howdy&theothervar=2112',
		    postBody: query, //to get rid of ?, 
		    onCreate: function(t) {
		    	//document.getElementById('rtMainContent').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    	document.getElementById('page_results').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:369px;background:url(images/loading.gif) center center no-repeat;"></div>';
		    	
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText; //getting the disbaled array from here
		        //document.getElementById('rtMainContent').innerHTML = resp;
		        document.getElementById('page_results').innerHTML = resp;
		        
		    },
		   
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    	//debug_omniture_variables();
	
				/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
				var s_code=s.t();
				if(s_code) document.write(s_code);
		    }
		}
			
		new Ajax.Request(url_base, opt);
		
		//document.getElementById('rtMainContent').innerHTML = "testing next";
}

/*******************************************************

	For Getting promotion details

***********************************/
function getPromoDetails(promotionId,promotitle,promoDesc,promoType) {

	var DetailParams = new Array("keys","values");		
	DetailParams["keys"] = Array	("promotionId","promotitle","promodesc");
	DetailParams["values"] = Array	(promotionId,URLEncode(promotitle),URLEncode(promoDesc));
	
	//Item promotions
	if (1 == promoType)
		var url_1 = "promo_details.do"+createParams(DetailParams);
	
	
	//Category Based promotions	
	if (2 == promoType)
		var url_1 = "promo_getCategoriesforPromo.do"+createParams(DetailParams);
	
	
	//alert(url_1);
	
	window.location.href = url_1;
}

function rentalItemsPaginate(pageURL) {
		var query = fleegix.uri.getQuery(pageURL);
		var url_base = fleegix.uri.getBase(pageURL);
		//alert(query);
		//alert(url_base);
		var opt = {
		    // Use GET
		    method: 'post',asynchronous:true,
		    postBody: query, //to get rid of ?, 
		    onCreate: function(t) {
		    	document.getElementById('AvailableItems').innerHTML = '<div style="padding:0; text-align:center !important; width:460px; height:250px;background:url(images/loadingAnimation.gif) center center no-repeat;"></div>';
		    	
		    },
		     // Handle successful response
		    onSuccess: function(t) {
		    	var resp = t.responseText;
		        
		        document.getElementById('AvailableItems').innerHTML = resp;
		        
		    },
		     // On Complete acts as a postfunction
		    onComplete: function(t) {
		    }
		}
			
		new Ajax.Request(url_base, opt);
}

