
var gReturnValue;
var gHasPendingPopup = false;
var gPendingPopupUrl = null;
var gPendingPopupWidth = null;
var gPendingPopupHeight = null;
var gPendingPopupReturnFunc = null;
var gLoading = "PageLoading.htm";
var gPopupMask = null;
var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;
var gHideSelects = true;
var gTabIndexes = new Array();
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

var scTop;
var scLeft;
function setPopUpLoadingPage(loading) {
	gLoading = loading;
}

function registerPendingPopup(url, width, height, returnFunc) 
{
    gHasPendingPopup = true;
    gPendingPopupUrl = url;
    gPendingPopupWidth = width;
    gPendingPopupHeight = height;
    gPendingPopupReturnFunc = returnFunc;
}

function processPendingPopup()
{
    if ( gHasPendingPopup )
    {
        gHasPendingPopup = false;
        showPopWin(gPendingPopupUrl, gPendingPopupWidth, gPendingPopupHeight, gPendingPopupReturnFunc);
        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 initPopUp() {
    body = document.getElementsByTagName('body')[0];
    popmask = document.createElement('div');
    popmask.id = 'popupMask';
    popcont = document.createElement('div');
    popcont.id = 'popupContainer';
    popcont.innerHTML = '' +
        '<div id="popupInner">' +
            '<div id="popupTitleBar" style="border:1px">' + 
            '</div>' +
            '<iframe src="'+gLoading+'" style="width:570px;background-color:transparent;"  scrolling="no" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="570" height="100%"></iframe>' +
        '</div>';
    body.appendChild(popmask);
    body.appendChild(popcont);
	
    gPopupMask = document.getElementById("popupMask");
    gPopupContainer = document.getElementById("popupContainer");
    gPopFrame = document.getElementById("popupFrame");	
	
    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]);
                }
                showPopWin(this.href,width,height,null); return false;
            }
        }
    }
    processPendingPopup();
}
addEvent(window, "load", initPopUp);
function showPopWin(url, width, height, returnFunc) 
{	
    window.onscroll = centerPopWin;
    if ( gPopupContainer == null )
    {
    //alert("1");
        registerPendingPopup(url, width, height, returnFunc);
    }
        else
    {   
   
        gPopupIsShown = true;
        disableTabIndexes();
        gPopupMask.style.display = "block";
        gPopupContainer.style.display = "block";
        centerPopWin(width, height);
    	
        var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
    	
        gPopupContainer.style.width = width + "px";
        gPopupContainer.style.height = (height+titleBarHeight) + "px";
        gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
        gPopFrame.style.height = (height) + "px";
    	
        gPopFrame.src = url;
        gReturnFunc = returnFunc;    
        
        // for IE
	    if (gHideSelects == true) {
		    hideSelectBoxes();
	    }
    }        	
}

var gi = 0;
function centerPopWin(width, height) 
{	
	//alertSize();
	getScrollXY();
	
	if (gPopupIsShown == true) 
	{
        if (width == null || isNaN(width)) 
        {
            width = gPopupContainer.offsetWidth;           
        }
        if (height == null) 
        {
            height = gPopupContainer.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);
		
        gPopupMask.style.height = fullHeight + "px";
        gPopupMask.style.width = fullWidth + "px";
        gPopupMask.style.top = scTop + "px";
        gPopupMask.style.left = scLeft + "px";
		
        window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		
        var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		
		gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
        gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
        
        //gPopupContainer.style.top = scTop  + "px";
        //gPopupContainer.style.left =  scLeft + "px";
        
    }
}

addEvent(window, "resize", centerPopWin);

function ReloadPage()
{
  window.document.forms[0].submit();
  //window.location.reload(true);     
}


//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 ReloadOLRSignup()
{   
	var pwd = document.getElementById("hidPassword").value;
	document.getElementById("txtPass").value= pwd;
	document.getElementById("txtRePass").value= pwd;
	document.getElementById("hidCanCont").value= "Y";
	document.getElementById("btnSignup").click();    
}

function ReloadProEC()
{	
	document.getElementById("hidAttachment").value = gReturnValue;	  
	document.getElementById("lblAttachMsg").innerHTML = gReturnValue;
}

function ReloadSpoECAttachment()
{
    document.getElementById(slblAttachMsg).innerHTML = gReturnValue;
	document.getElementById(shidAttachment).value = gReturnValue;  
}

function ReloadSpoECEmailUpload()
{
	document.getElementById(stxtFromFile).value = gReturnValue;	
}

function hidePopWin(callReturnFunc) {
  gPopFrame.src = gLoading;
    gPopupIsShown = false;
    restoreTabIndexes();
    if (gPopupMask == null) {
        return;
    }
    gPopupMask.style.display = "none";
    gPopupContainer.style.display = "none";
    if (callReturnFunc == true && gReturnFunc != null) {
        gReturnFunc(window.frames["popupFrame"].returnVal);
    }
    if (gHideSelects == true) {
        displaySelectBoxes();
    }
}



function hidePopWinWithValue(callReturnFunc, getValue) 
{	
	gReturnValue = getValue;
	
    gPopupIsShown = false;
    restoreTabIndexes();
    if (gPopupMask == null) {
        return;
    }
    gPopupMask.style.display = "none";
    gPopupContainer.style.display = "none";
    if (callReturnFunc == true && gReturnFunc != null) {
        gReturnFunc(window.frames["popupFrame"].returnVal);
    }
    gPopFrame.src = gLoading;
    if (gHideSelects == true) {
        displaySelectBoxes();
    }
   
   
}


function keyDownHandler(e) {
    if (gPopupIsShown && 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 ;
}



// Added the below function for the video overlap over the iframe window

function showVideoPopWin(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 = centerPopWin;
    if ( gPopupContainer == null )
    {
    //alert("1");
        registerPendingPopup(url, width, height, returnFunc);
    }
        else
    {   
   
        gPopupIsShown = true;
        disableTabIndexes();
        gPopupMask.style.display = "block";
        gPopupContainer.style.display = "block";
        centerPopWin(width, height);
    	
        var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
    	
        gPopupContainer.style.width = width + "px";
        gPopupContainer.style.height = (height+titleBarHeight) + "px";
        gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
        gPopFrame.style.height = (height) + "px";
    	
        gPopFrame.src = url;
        gReturnFunc = returnFunc;    
        
        // for IE
	    if (gHideSelects == true) {
		    hideSelectBoxes();
	    }
    }        	
}

function hideVideoPopWin(callReturnFunc)
{
 
    if((typeof(window.frames["iframeDetailsView"])=="undefined") && (window.parent.document.getElementById('divutube')!=null))
    {
     
        hidePopWin(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";
                hidePopWin(false);                   
             }
         } 
         else
         {
         
         hidePopWin(false); 
         }  
     
    }
   else if((typeof(window.frames["iframeDetailsView"])=="undefined")&&(window.parent.document.getElementById('divutube')==null))
    {
       
        hidePopWin(false);
    }
    
    else{
    
     hidePopWin(false);
    }


}