﻿
var gReturnValue;
var gHasPendingWidget = false;
var gPendingWidgetUrl = null;
var gPendingWidgetWidth = null;
var gPendingWidgetHeight = null;
var gPendingWidgetReturnFunc = null;
var gLoading2 = "PageLoading2.htm";
var gWidget2Mask = null;
var gWidget2Container = null;
var gWidgetFrame = null;
var gReturnFunc;
var gWidgetIsShown = false;
var gHideSelects = true;
var gTabIndexes = new Array();
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

var scTop;
var scLeft;
function setWidgetLoadingPage(loading) {
	gLoading2 =loading;
}

function registerPendingWidget(url, width, height, returnFunc) 
{
    gHasPendingWidget = true;
    gPendingWidgetUrl = url;
    gPendingWidgetWidth = width;
    gPendingWidgetHeight = height;
    gPendingWidgetReturnFunc = returnFunc;
}

function processPendingWidget()
{
    if ( gHasPendingWidget )
    {
        gHasPendingWidget = false;
        showWidgetWin(gPendingWidgetUrl, gPendingWidgetWidth, gPendingWidgetHeight, gPendingWidgetReturnFunc);
        return false;
    }
        else
    {
        return true;
    }
}




function addEvent(obj, evType, fn){
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}

function removeEvent(obj, evType, fn, useCapture){
    if (obj.removeEventListener){
        obj.removeEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.detachEvent){
        var r = obj.detachEvent("on"+evType, fn);
        return r;
    } else {
        alert("Handler could not be removed");
    }
}

function getViewportHeight() 
{
	//alert(screen.height);
	
    if (window.innerHeight!=window.undefined) 
		return window.innerHeight;
		
	if (document.compatMode=='CSS1Compat') 
		return document.documentElement.clientHeight;
		
    if (document.body) 
		return document.body.clientHeight; 
	
	return window.undefined; 
	
   /* alert('text1');
    if (window.innerHeight) 
    alert('text2');
    {//netscape supported<BR>height = 
      var wheight = window.innerHeight;
      alert(wheight);
      return wheight;
   else { //for ie users<BR>height = 
    var wiheight = window.document.body.clientHeight;
    return wiheight; */
}

function getViewportWidth() {
    if (window.innerWidth!=window.undefined) return window.innerWidth; 
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
    if (document.body) return document.body.clientWidth; 
    return window.undefined;
    
    /* if(window.innerWidth) 
    {//netscape supported<BR>height = 
      var wheight = window.innerWidth;
      return wwidth;
   else { //for ie users<BR>height = 
    var wiheight = window.document.body.clientWidth;
    return wiwidth; */
     
}

if (!document.all) {
    document.onkeypress = keyDownHandler;
}

function initWidget() {
    body = document.getElementsByTagName('body')[0];
    Widget2mask = document.createElement('div');
    Widget2mask.id = 'Widget2Mask';
    Widget2cont = document.createElement('div');
    Widget2cont.id = 'Widget2Container';
    Widget2cont.innerHTML = '' +
        '<div id="Widget2Inner">' +
            '<div id="Widget2TitleBar" style="border:1px;background-color:transparent">' + 
            '</div>' +
             '<iframe src="'+gLoading2+'" style="width:570px;height:100%;background-color:transparent;"  scrolling="no" frameborder="0" allowtransparency="true" id="Widget2Frame" name="Widget2Frame" width="570" height="100%"></iframe>' +
        '</div>';
    body.appendChild(Widget2mask);
    body.appendChild(Widget2cont);
	
    gWidget2Mask = document.getElementById("Widget2Mask");
    gWidget2Container = document.getElementById("Widget2Container");
    gWidgetFrame = document.getElementById("Widget2Frame");	
	
    var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
    if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
        gHideSelects = true;
    }
	
    var elms = document.getElementsByTagName('a');
    for (i = 0; i < elms.length; i++) {
        if (elms[i].className.indexOf("submodal") == 0) { 
            elms[i].onclick = function(){
                var width = 600;
                var height = 400;
                params = this.className.split('-');
                if (params.length == 3) {
	                width = parseInt(params[1]);
	                height = parseInt(params[2]);
                }
                showWidgetWin(this.href,width,height,null); return false;
            }
        }
    }
    processPendingWidget();
}
addEvent(window, "load", initWidget);
function showWidgetWin(url, width, height, returnFunc) 
{
    window.onscroll = centerWidgetWin;
    if ( gWidget2Container == null )
    {
    //alert("1");
        registerPendingWidget(url, width, height, returnFunc);
    }
        else
    {   
   
        gWidgetIsShown = true;
        disableTabIndexes();
        gWidget2Mask.style.display = "block";
        gWidget2Container.style.display = "block";
        centerWidgetWin(width, height);
    	
        var titleBarHeight = parseInt(document.getElementById("Widget2TitleBar").offsetHeight, 10);
    	
        gWidget2Container.style.width = width + "px";
        gWidget2Container.style.height = (height+titleBarHeight) + "px";
        gWidgetFrame.style.width = parseInt(document.getElementById("Widget2TitleBar").offsetWidth, 10) + "px";
        gWidgetFrame.style.height = (height) + "px";
    	
        gWidgetFrame.src = url;
        gReturnFunc = returnFunc;    
        
        // for IE
	    if (gHideSelects == true) {
		    hideSelectBoxes();
	    }
    }        	
}

var gi = 0;
function centerWidgetWin(width, height) 
{	
	//alertSize();
	getScrollXY();
	
	if (gWidgetIsShown == true) 
	{
        if (width == null || isNaN(width)) 
        {
            width = gWidget2Container.offsetWidth;           
        }
        if (height == null) 
        {
            height = gWidget2Container.offsetHeight;           
        }
		
        var fullHeight = getViewportHeight();       
        var fullWidth = getViewportWidth();		
		
		
        var theBody = document.documentElement;		        
       // var scTop = parseInt(theBody.scrollTop,10);alert(theBody.scrollTop);
       // var scLeft = parseInt(theBody.scrollLeft,10);alert(theBody.scrollLeft);
		
		//alert(scTop);alert(scLeft);
		
        gWidget2Mask.style.height = fullHeight + "px";
        gWidget2Mask.style.width = fullWidth + "px";
        gWidget2Mask.style.top = scTop + "px";
        gWidget2Mask.style.left = scLeft + "px";
		
        window.status = gWidget2Mask.style.top + " " + gWidget2Mask.style.left + " " + gi++;
		
        var titleBarHeight = parseInt(document.getElementById("Widget2TitleBar").offsetHeight, 10);
		
		gWidget2Container.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
        gWidget2Container.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
        
        //gWidget2Container.style.top = scTop  + "px";
        //gWidget2Container.style.left =  scLeft + "px";
        
    }
}

addEvent(window, "resize", centerWidgetWin);
//window.onscroll = centerWidgetWin;

function ReloadPage()
{
  window.document.forms[0].submit();
  //window.location.reload(true);     
}

//Function Written by Paul Williams for the Profile Widget)
function ReloadWidgetParent()
{
	 window.document.forms[0].submit();
}


//Function Written by Arun Prasad.S for the Participant Management (Promoter approval)
function ReloadApproval()
{
	var MemCount = document.getElementById("hidMemcount").value;
	document.getElementById("hidStatus").value = "Y";
	document.getElementById("btnApprove").click();
}

// For Simple Sponser Signup
// Owner: Senthil.N
function ReloadSponSimpleSignUp()
{   
	var pwd = document.getElementById("hidPassword").value;
	//alert(pwd);
	document.getElementById("txtPassword").value= pwd;
	document.getElementById("txtCPassword").value= pwd;
	document.getElementById("hidCanCont").value= "Y";	
	document.getElementById("btnContinue").click();    
}

// For Dealer Simple Signup
// Owner: Senthil.N
function ReloadDealerSimpleSignUp()
{   
	var pwd = document.getElementById("hidPassword").value;
	//alert(pwd);
	document.getElementById("txtPassword").value= pwd;
	document.getElementById("txtCPassword").value= pwd;
	document.getElementById("hidCanCont").value= "Y";	
	document.getElementById("btnContinue").click();    
}

function ReloadPartRegMember()
{   
	var pwd = document.getElementById("hidPassword").value;
	//alert(pwd);
	document.getElementById("txtPassword").value= pwd;
	document.getElementById("txtCPassword").value= pwd;
	document.getElementById("hidCanCont").value= "Y";	
	document.getElementById("btnContinue").click();    
}

function ReloadProEC()
{	
	document.getElementById("hidAttachment").value = gReturnValue;	  
	document.getElementById("lblAttachMsg").innerHTML = gReturnValue;
}

function ReloadSpoECAttachment()
{
	document.getElementById(shidAttachment).value = gReturnValue;	  
	document.getElementById(slblAttachMsg).innerHTML = gReturnValue;
}

function ReloadSpoECEmailUpload()
{
	document.getElementById(stxtFromFile).value = gReturnValue;	
}

function hideWidgetWin(callReturnFunc) {


  gWidgetFrame.src = gLoading2;
    gWidgetIsShown = false;
    restoreTabIndexes();
    if (gWidget2Mask == null) {
        return;
    }
    
    gWidget2Mask.style.display = "none";
    gWidget2Container.style.display = "none";
    
    if (callReturnFunc == true && gReturnFunc != null) {
        gReturnFunc(window.frames["Widget2Frame"].returnVal);
    }
  
    if (gHideSelects == true) {
        displaySelectBoxes();
    }
//gWidgetIsShown = false; // Modified by Jegan on 08/01/09
}



function hideWidgetWinWithValue(callReturnFunc, getValue) 
{	
	gReturnValue = getValue;
	
    gWidgetIsShown = false;
    restoreTabIndexes();
    if (gWidget2Mask == null) {
        return;
    }
    gWidget2Mask.style.display = "none";
    gWidget2Container.style.display = "none";
    if (callReturnFunc == true && gReturnFunc != null) {
        gReturnFunc(window.frames["Widget2Frame"].returnVal);
    }
    gWidgetFrame.src = gLoading2;
    if (gHideSelects == true) {
        displaySelectBoxes();
    }
   
   
}


function keyDownHandler(e) {
    if (gWidgetIsShown && e.keyCode == 9)  return false;
}

function disableTabIndexes() {
    if (document.all) {
        var i = 0;
        for (var j = 0; j < gTabbableTags.length; j++) {
            var tagElements = document.getElementsByTagName(gTabbableTags[j]);
            for (var k = 0 ; k < tagElements.length; k++) {
                gTabIndexes[i] = tagElements[k].tabIndex;
                tagElements[k].tabIndex="-1";
                i++;
            }
        }
    }
}

function restoreTabIndexes() {
    if (document.all) {
        var i = 0;
        for (var j = 0; j < gTabbableTags.length; j++) {
            var tagElements = document.getElementsByTagName(gTabbableTags[j]);
            for (var k = 0 ; k < tagElements.length; k++) {
                tagElements[k].tabIndex = gTabIndexes[i];
                tagElements[k].tabEnabled = true;
                i++;
            }
        }
    }
}

function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if( (document.forms[i].elements[e].tagName == "SELECT") || (document.forms[i].elements[e].tagName == "OBJECT") || (document.forms[i].elements[e].tagName == "EMBED")) {
				document.forms[i].elements[e].style.visibility="hidden";
				//document.forms[i].elements[e].disabled = true; // Written by Arun Prasad on 20/06/2008 to make the drop down list hidden after cancel
			}
		}
	}
}

function displaySelectBoxes() {
    for(var i = 0; i < document.forms.length; i++) {
        for(var e = 0; e < document.forms[i].length; e++){
            if( (document.forms[i].elements[e].tagName == "SELECT") || (document.forms[i].elements[e].tagName == "OBJECT") || (document.forms[i].elements[e].tagName == "EMBED")) {
            document.forms[i].elements[e].style.visibility="visible";
            //document.forms[i].elements[e].disabled = false; // Written by Arun Prasad on 20/06/2008 to make the drop down list visible after cancel
            }
        }
    }
}

function alertSize() 
{
	var myWidth = 0, myHeight = 0;
		
    //myWidth = window.innerWidth;
    //myHeight = window.innerHeight;
	
	//myWidth = document.documentElement.clientWidth;
    //myHeight = document.documentElement.clientHeight;
	  
    myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	
	window.alert( 'Width = ' + myWidth );
	window.alert( 'Height = ' + myHeight );
}

function getScrollXY() 
{
	 var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) 
	{	
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	{	
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	{		
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	//window.alert( 'Chk1: ' + 'X = ' + scrOfX + ', Y = ' + scrOfY);
	scTop = scrOfY ;
	scLeft = scrOfX ;
}

function showutube(url, width, height, returnFunc) 
{
    window.onscroll = centerWidgetWin;
    if(navigator.userAgent.indexOf('Chrome')>-1)
    {
       if(document.getElementById('ctl00_ctl00_TopMenu_MiniTab_divutube').style.visibility=="visible")
         {
           document.getElementById('ctl00_ctl00_TopMenu_MiniTab_divutube').style.visibility="hidden";  
         }         

    }
    
    
    
    if ( gWidget2Container == null )
    {
    //alert("1");
        registerPendingWidget(url, width, height, returnFunc);
    }
        else
    {   
   
        gWidgetIsShown = true;
        disableTabIndexes();
        gWidget2Mask.style.display = "block";
        gWidget2Container.style.display = "block";
        centerWidgetWin(width, height);
    	
        var titleBarHeight = parseInt(document.getElementById("Widget2TitleBar").offsetHeight, 10);
    	
        gWidget2Container.style.width = width + "px";
        gWidget2Container.style.height = (height+titleBarHeight) + "px";
        gWidgetFrame.style.width = parseInt(document.getElementById("Widget2TitleBar").offsetWidth, 10) + "px";
        gWidgetFrame.style.height = (height) + "px";
    	
        gWidgetFrame.src = url;
        gReturnFunc = returnFunc;    
        
        // for IE
	    if (gHideSelects == true) {
		    hideSelectBoxes();
	    }
    }        	
}

function hideVideoWidgetWin(callReturnFunc)
{
 
    if((typeof(window.frames["iframeDetailsView"])=="undefined") && (window.parent.document.getElementById('divutube')!=null))
    {
     
        hideWidgetWin(false);
    }

    else if((window.frames["iframeDetailsView"]!=null)&&(window.parent.document.getElementById('divutube')==null ))
    {     
        if(window.frames["iframeDetailsView"].document.getElementById("divutube")!=null)
        {   
            if(window.frames["iframeDetailsView"].document.getElementById("divutube").style.display = "none")
            {
                window.frames["iframeDetailsView"].document.getElementById("divutube").style.display = "block";
                hideWidgetWin(false);                   
             }
         } 
         else
         {
         
         hideWidgetWin(false); 
         }  
     
    }
   else if((typeof(window.frames["iframeDetailsView"])=="undefined")&&(window.parent.document.getElementById('divutube')==null))
    {
       
        hideWidgetWin(false);
    }
    
    else{
    
     hideWidgetWin(false);
    }


}


// Added the below function for the video overlap over the iframe window

function showVideoPartWin(url, width, height, returnFunc) 
{	

    if((navigator.userAgent.indexOf('Chrome')>-1)||(navigator.userAgent.indexOf('Firefox')>-1)||(navigator.userAgent.indexOf('MSIE')>-1)||(navigator.userAgent.indexOf('Opera')>-1))
    {
       if(window.frames["iframeDetailsView"].document.getElementById("divutube").style.display = "block")
         {
           window.frames["iframeDetailsView"].document.getElementById("divutube").style.display = "none";  
         }         

    }   
     window.onscroll = centerWidgetWin;
    if ( gWidget2Container == null )
    {
    //alert("1");
        registerPendingWidget(url, width, height, returnFunc);
    }
        else
    {   
   
        gWidgetIsShown = true;
        disableTabIndexes();
        gWidget2Mask.style.display = "block";
        gWidget2Container.style.display = "block";
        centerWidgetWin(width, height);
    	
        var titleBarHeight = parseInt(document.getElementById("Widget2TitleBar").offsetHeight, 10);
    	
        gWidget2Container.style.width = width + "px";
        gWidget2Container.style.height = (height+titleBarHeight) + "px";
        gWidgetFrame.style.width = parseInt(document.getElementById("Widget2TitleBar").offsetWidth, 10) + "px";
        gWidgetFrame.style.height = (height) + "px";
    	
        gWidgetFrame.src = url;
        gReturnFunc = returnFunc;    
        
        // for IE
	    if (gHideSelects == true) {
		    hideSelectBoxes();
	    }
    }        	
    
    
}
