

Vudu.util.getMovieHomePage = function( root, title , year )        {
	
	var isHd = false;
	var isSeries = false;
	
	/* remove suffix from title */
	if(title.match(/\[HD\]$/))	{
		title = title.replace(/\[HD\]$/, "");
		isHd = true;
	}
	else if(title.match(/\[TV Series\]$/))	{
		title = title.replace(/\[TV Series\]$/, "");
		isSeries = true;
	}
	
	// drop all non word chars
	title = title.replace(/[^\w\s]+/g, "");
	// clean leading and ending spaces
	title = title.replace(/^\s+|\s+$/g, '') ;
	// replace all prev spaces to -
	title = title.replace(/\W+/g, "-");
	// close the title string    
	
	if(year)	{
		year = year.replace(/(\d{4})(-\d{2}-\d{2})/, '$1');
		title += "/"+year+"/";
	}
	else	{
		title += "/";
	}
	
	
	if(isHd)	{
		title += "HD/";
	}
	else if(isSeries)	{
		title += "SERIES/";
	}
	
	return root+"/"+title;
}


Vudu.util.calculateParamValueFromRequest = function( oRequest , oParam )        {
	
	var sIndex = oRequest.indexOf(oParam);
	if( sIndex != -1 )      {
		return oRequest.substring(
			sIndex + oParam.length + 1 /* for = */, 
			oRequest.indexOf('&', sIndex ) != -1 ? oRequest.indexOf('&', sIndex ): oRequest.length
		);
	}
	
	return null;
}


Vudu.util.TextWrap = function( text  , charLength , splitChar , suffix )        {
       
        var sArray = text.split(splitChar);
       
        var chars = 0;
        var resultText = '';
        var lWordIndex = 0;
        var i =0 ;
        for( ; i < sArray.length; i++)    {               
			// update char count
			chars += sArray[i].length + 1;
			// check if it exceeds desired
			if(chars > charLength)  {
				// if the first word is too long
				if(resultText.length <= 0 )     {
					resultText = text.substring(0,charLength);
				}
				// if add suffix 
				if(suffix)	{
					resultText += suffix;
				}
				break;  
			}
			// if not - append to array
			resultText += sArray[i] + splitChar;
        }
       
        return resultText;
}

Vudu.util.parseDirectorJSONResponse = function( text ) {
	
	var results = null;
	text = text.replace(/\/\*-secure-/ , "result = ");
	text = text.replace(/\*\// , "");
	        
    eval(text);
	
	return result;
}
