<!--
//Define Page Naming: useTitleTag="true" uses the Page Title as the Page Name
//If a pretty page name exists, userTitleTag must be false. Page name will be the prettyPageName passed
//userTitleTag ="false" and prettyPageName = "" than the default File Name will be used.


//Default Division and Property Declarations
var division = "Main";
var property = "sonypictures";
var url = document.URL.toLowerCase();
var pagelocation = url;
var useTitleTag = "";
var prettyPageName = "";

if (url.match(/^https?:\/\/.*/)) {
	site = url.replace(/^(https?:\/\/)([^\/]+\.)([^\.\/]+)(\.?(:8080)?\/.*)$/,"$3");
	} else {
	site = url.replace(/^([^\/]*\/?\/?[^\/]+\.)([^\.\/]+)(\.?(:8080)?\/.*)$/,"$2");
	}

var QI = url.indexOf("//");
if(QI != -1){
	dom = url.substring(QI+2);
	TI = dom.indexOf("/");
	if(TI != -1){
	dom = dom.substring(0,TI);
	}
	QI = dom.indexOf(".")
	while(QI >= 0)
	{
	dom = dom.substring(QI+1);
	QI = dom.indexOf(".");
	site = dom;
	}
    site = site.replace(/:8080/, "");
	site = site.replace(/:8081/, "");
	site = site.replace(/\./, "");
		
	if (site.match(/^\d+$/)) 
	{site = "us";}
	if(dom == 'com'||dom == 'net'||dom == 'org'||dom =='info')
	{site = "us";}
	
	if(site.length > 2){
	site = "us";}


}


if (document.pgOvr && document.pgOvr.pgNm)
{
  url = document.pgOvr.pgNm.value;
  url = url.replace ("/m2/ftp","http://www.sonypictures.com");
  url = url.replace ("/m2/review","http://www.sonypictures.com");

}

if (url.match(/\/intl\//)) {
   url = url.replace(/\/intl\/\w+/, "");
}

function getData()
{
    
    var foundSectionName = true;
    var foundPropertyVariable = false;
    var startDir4Property = 2;
    if (url.match(/https?:\/\/[^\/]+\/movies\/.*/i))
    {   division = "Movies";
    } else if (url.match(/https?:\/\/[^\/]+\/[^\/]+\/[^\/]+\/[^\/]+\/mini_sites\/.*/i)) {
        division = "Television";
	startDir4Property = 5;
    } else if (url.match(/https?:\/\/[^\/]+\/tv\/.*/i)) {
        division = "Television";
		startDir4Property = 3;
    } else if (url.match(/https?:\/\/[^\/]+\/homevideo\/promotions.html/i)) {
        division = "Win";
    } else if (url.match(/https?:\/\/[^\/]+\/homevideo\/.*/i)) {
        division = "DVD+&+Video";
    } else if (url.match(/https?:\/\/[^\/]+\/mobile\/.*/i)) {
        division = "Mobile";
    } else if (url.match(/https?:\/\/[^\/]+\/digent\/games\/.*/i)) {
        division = "Games";
    } else if (url.match(/https?:\/\/[^\/]+\/digent\/mediasoftware\/.*/i)) {
        division = "Media+Software";
    } else if (url.match(/https?:\/\/[^\/]+\/digent\/.*/i)) {
        division = "Digital+Entertainment";
	} else if (url.match(/https?:\/\/[^\/]+\/previews\/.*/i)) {
        division = "Previews+and+Clips";
        startDir4Property = 4;
    } else if (url.match(/https?:\/\/[^\/]+\/shop\/.*/i)) {
        division = "Shop";
    } else if (url.match(/https?:\/\/[^\/]+\/corp\/.*/i)) {
        division = "Corporate";
    } else if (url.match(/https?:\/\/[^\/]+\/win\/.*/i)) {
        division = "Win";
    } else if (url.match(/https?:\/\/[^\/]+\/jspin2\/jsp\/spn\/.*/i)) {
        division = "SPN";
    } else if (url.match(/https?:\/\/[^\/]+\/spnet\/.*/i)){
	    division = "SPN";
	} else if (url.match(/https?:\/\/[^\/]+\/cgi\/cgi-bin\/templates\/.*/i)) {
		division = "SPN";
	} else {
	    foundSectionName = false;
    }

    if (startDir4Property == 2) {
        if (url.match(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+)(\/.*$)/i)) {
            property = url.replace(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+)(\/.*$)/i, "$2");
            foundPropertyVariable = true;
        }
    } else if (startDir4Property == 3) {
        if (url.match(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+\/)([^\/]+)(\/.*$)/i)) {
            property = url.replace(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+\/)([^\/]+)(\/.*$)/i, "$3");
            foundPropertyVariable = true;
        }
    } else if (startDir4Property == 4) {
        if (url.match(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+\/)([^\/]+\/)([^\/]+)(\/.*$)/i)) {
            property = url.replace(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+\/)([^\/]+\/)([^\/]+)(\/.*$)/i, "$4");
            foundPropertyVariable = true;
        }
    } else if (startDir4Property == 5) {
        if (url.match(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+\/)([^\/]+\/)([^\/]+\/)([^\/]+)(\/.*$)/i)) {
            property = url.replace(/(^https?:\/\/[^\/]+\/[^\/]+\/)([^\/]+\/)([^\/]+\/)([^\/]+\/)([^\/]+)(\/.*$)/i, "$5");
            foundPropertyVariable = true;
    	}
    }	
	if (foundPropertyVariable == true) {
        property = property.replace(/[^\w\-]/g, "");
	
    } 

}
var vanityURL = url;
var domainCut= vanityURL.indexOf("//");
var endString = vanityURL.substring (domainCut+2);
    domainCut= endString.indexOf("/");
    if (domainCut== -1) { endString = "Home"; }
    else { endString = endString.substring (domainCut+1);
    domainCut= endString.indexOf ("?");}
    if ( endString == "" ) { endString = "Home"; }

//Updates tag for Movie and Tv Show Names
getData();
var subdivision = division.toLowerCase();
//Dynamic variables passed to the Global Include
var title = escape (document.title.toLowerCase());
var affiliate = property + "-" + site;

    if (document.flag && document.flag.useTitleTag.value == "true" && !document.pageName){
	 useTitleTag = document.flag.useTitleTag.value;
	 document.write("<form style='display:inline' name='h_xes_ao'><input type=hidden name='x_ao' value='53~" + endString + "~232~" + division + "~28~" + affiliate + "~221~" + site + "~" + "225~" + site + "^" + property + "^" + subdivision + "^" + title + "~5~" + title + "~'></form>");
  } else if (document.pageName && document.pageName.prettyPageName){
	 prettyPageName = document.pageName.prettyPageName.value;
	 if(prettyPageName == ""){
	  document.write("<form style='display:inline' name='h_xes_ao'><input type=hidden name='x_ao' value='53~" + endString + "~232~" + division + "~28~" + affiliate + "~221~" + site + "~" + "225~" + site + "^" + property + "^" + subdivision + "^" + endString + "~5~" + pagelocation + "~'></form>");
     	 }else{
	 if(!document.flag){	 
	  document.write("<form style='display:inline' name='h_xes_ao'><input type=hidden name='x_ao' value='53~" + endString + "~232~" + division + "~28~" + affiliate + "~5~" + prettyPageName + "~221~" + site + "~" + "225~" + site + "^" + property + "^" + subdivision + "^" + prettyPageName + "~'></form>");
  	 } else if(document.flag.useTitleTag.value == "false"){
	  document.write("<form style='display:inline' name='h_xes_ao'><input type=hidden name='x_ao' value='53~" + endString + "~232~" + division + "~28~" + affiliate + "~5~" + prettyPageName + "~221~" + site + "~" + "225~" + site + "^" + property + "^" + subdivision + "^" + prettyPageName + "~'></form>");
  	 } else{ 
	  document.write("<form style='display:inline' name='h_xes_ao'><input type=hidden name='x_ao' value='53~" + endString + "~232~" + division + "~28~" + affiliate + "~221~" + site + "~" + "225~" + site + "^" + property + "^" + subdivision + "^" + endString + "~5~" + pagelocation + "~'></form>");
  	 }}
  } else{
     document.write("<form style='display:inline' name='h_xes_ao'><input type=hidden name='x_ao' value='53~" + endString + "~232~" + division + "~28~" + affiliate + "~221~" + site + "~" + "225~" + site + "^" + property + "^" + subdivision + "^" + endString + "~5~" + pagelocation + "~'></form>");
  }
//-->
