jQuery(document).ready( function () {  

jQuery("input[name='username']").focus();

           var divLoginFlag=null;
           if(document.getElementById("targetUrl")!=null){
	           document.getElementById("targetUrl").value=window.document.location;
	        }
           if(document.getElementById("loginDivFlag")!=null){
                     divLoginFlag=document.getElementById("loginDivFlag").value;
           }
           if(divLoginFlag=="true"){
				var divLogin=document.getElementById("divLogin");
				simulateClickEvent(divLogin);
			}
                
 });
/* Mthod to simulate the clickevent on the link */
function simulateClickEvent(elementName) {
  var browser=navigator.appName;
  //Forcing user to click on the login floating div link
  if (browser == "Microsoft Internet Explorer"){
        var button = document.getElementById("divLogin");
        button.click();
        //button.fireEvent("onclick");
    }else{             
		var evt = document.createEvent("MouseEvents");
        evt.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
        elementName.dispatchEvent(evt);
       
    }
                     
}
function prepatreUrl(baseUrl,param){
var flag = changeParentUrl();
if(!flag){
	var targetUrl = document.getElementById("targetUrl").value;
	//Removing all the CIM specific parameters in the target URLs so that we can reduce the length of the floating DIV URL
	targetUrl = targetUrl.replace(/&requestId=[\w\s%]*&/, "&");
	targetUrl = targetUrl.replace(/&changePass=[YN]&/, "&");
	targetUrl = targetUrl.replace(/&PROCESSED=[Y]&/, "&");
	var url="";
	if(baseUrl.indexOf("?site=")>0){
		url=baseUrl+"&"+param+"&targetUrl="+escape(targetUrl)+"&align_to="+escape("div#mysony");
	}else{
		url=baseUrl+"?"+param+"&targetUrl="+escape(targetUrl)+"&align_to="+escape("div#mysony");
	}
	document.getElementById("divLogin").setAttribute('href', url);
}

}

function changeParentUrl(){
	if(window.location.protocol=="http:"){
		var url = window.location.href;
		if(url.indexOf("?")== -1 ){
			window.location.href = window.location.href.replace("http:","https:")+'?refresh=true';
		}else{
			window.location.href = window.location.href.replace("http:","https:")+'&refresh=true';
		}
		return true;
	}
}
