﻿ var clipResult= "nothing";  
     
     
      //GetLastClipsPublicationDate 
      //GetVideoUrlFromCommand
      //http://cdws05.cgdev.com:1002/sandbox_minisite/KeysClipService.asmx/GetVideoUrlFromCommand
      // url: "http://localhost:2031/FMK/KeysClipService.asmx/GetVideoUrlFromCommand",
     
      function alertClip(rslt){
        clipResult =rslt.clip;         
      }
      function test2(keywords,keyslocation){
      var qs = "command=" + keywords + '&keyslocation='+keyslocation;
      clipResult="waiting";
      var t;
        jsonp("http://cdws05.cgdev.com:1000/FMK/jp.aspx","myCallBack","alertClip",qs); 
      //  alert("1: " + clipResult);
        
        
        return clipResult;
      }
       
    
      function jsonp(url,callback,name, query){                
    
            if (url.indexOf("?") > -1)
                url += "&jsonp=" 
            else
                url += "?jsonp=" 
                url += name + "&";
                
            if (query)
                url += (query) + "&";   
                url += new Date().getTime().toString(); // prevent caching        
   
            var script = document.createElement("script");        
            script.setAttribute("src",url);
            script.setAttribute("type","text/javascript");                
            document.body.appendChild(script);
        }
 
        
     
        
         function getClipPath(keywords,keyslocation){
         clipResult = "error";
            options = {
                    type: 'post',
                    url: "/FMK/KeysClipService.asmx/GetVideoUrlFromCommand",                    
                    data: 'command='+ keywords + '&keyslocation='+ keyslocation,
                    dataType: "xml",
                    async: false,
                    success: function(xml){clipResult= $(xml).find("string").text();},
                    error: function(xml){clipResult= "error"}
                    };

            jQuery.ajax(options); 
            return clipResult;
        }
        function getClipPathCrossDomain(){
                return clipResult
        
        }
       function parseUri(sourceUri){
	    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"],
		uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri),
		uri = {};
	
	    for(var i = 0; i < 10; i++){
		    uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
	    }
	
	    /* Always end directoryPath with a trailing backslash if a path was present in the source URI
	    Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key */
	    if(uri.directoryPath.length > 0){
		    uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
	    }
	
	        return uri;
        }
