// Implements AC_GenerateObj() function. This is a generic function used to generate // object/embed/param tags. It is used by higher level api functions. /************** LOCALIZABLE GLOBAL VARIABLES ****************/ var MSG_EvenArgs = 'The %s function requires an even number of arguments.' + '\nArguments should be in the form "atttributeName","attributeValue",...'; var MSG_SrcRequired = "The %s function requires that a movie src be passed in as one of the arguments."; /******************** END LOCALIZABLE **********************/ // Finds a parameter with the name paramName, and checks to see if it has the // passed extension. If it doesn't have it, this function adds the extension. function AC_AddExtension(args, paramName, extension) { var currArg, paramVal, queryStr, endStr; for (var i=0; i < args.length; i=i+2){ currArg = args[i].toLowerCase(); if (currArg == paramName.toLowerCase() && args.length > i+1) { paramVal = args[i+1]; queryStr = ""; // Pull off the query string if it exists. var indQueryStr = args[i+1].indexOf('?'); if (indQueryStr != -1){ paramVal = args[i+1].substring(0, indQueryStr); queryStr = args[i+1].substr(indQueryStr); } endStr = ""; if (paramVal.length > extension.length) endStr = paramVal.substr(paramVal.length - extension.length); if (endStr.toLowerCase() != extension.toLowerCase()) { // Extension doesn't exist, add it args[i+1] = paramVal + extension + queryStr; } } } } // Builds the codebase value to use. If the 'codebase' parameter is found in the args, // uses its value as the version for the baseURL. If 'codebase' is not found in the args, // uses the defaultVersion. function AC_GetCodebase(baseURL, defaultVersion, args) { var codebase = baseURL + defaultVersion; for (var i=0; i < args.length; i=i+2) { currArg = args[i].toLowerCase(); if (currArg == "codebase" && args.length > i+1) { if (args[i+1].indexOf("http://") == 0) { // User passed in a full codebase, so use it. codebase = args[i+1]; } else { codebase = baseURL + args[i+1]; } } } return codebase; } // Substitutes values for %s in a string. // Usage: AC_sprintf("The %s function requires %s arguments.","foo()","4"); function AC_sprintf(str){ for (var i=1; i < arguments.length; i++){ str = str.replace(/%s/,arguments[i]); } return str; } // Checks that args, the argument list to check, has an even number of // arguments. Alerts the user if an odd number of arguments is found. function AC_checkArgs(args,callingFn){ var retVal = true; // If number of arguments isn't even, show a warning and return false. if (parseFloat(args.length/2) != parseInt(args.length/2)){ alert(sprintf(MSG_EvenArgs,callingFn)); retVal = false; } return retVal; } function AC_GenerateObj(callingFn, useXHTML, classid, codebase, pluginsPage, mimeType, args){ if (!AC_checkArgs(args,callingFn)){ return; } // Initialize variables var tagStr = ''; var currArg = ''; var closer = (useXHTML) ? '/>' : '>'; var srcFound = false; var embedStr = '\n"; document.write(tagStr); }