﻿function RequireText(obj)
{
    if(obj.value == "")
    {
        obj.style.backgroundColor = "lightyellow";
        return false;
    }
    else
    {
         obj.style.backgroundColor = "white";
         return true;
    }
} 

function SingleRequiredText(obj)
{
    if(!RequireText(obj))
    {
        alert("Please enter some value");
        return false;
    }
    return true;
}

function IsInteger(obj)
{
    var i;
    s = obj.value.toString();
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
            
        if (isNaN(c)) 
        {
           obj.value = s.substring(0, s.length-1); 
        }
    }
    return true;
}

function RequireDDL(obj, invalidValue)
{ 

    if(obj.options[obj.selectedIndex].value == invalidValue)
    {
        obj.style.backgroundColor = "lightyellow";
        return false;
    }
    else
    {
         obj.style.backgroundColor = "Transparent";
          return true;
    }
} 



function IsDecimal(obj)
{
    var i;
    s = obj.value.toString();
    var decimalCounter = 0;
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if(c == ".")
            decimalCounter= parseInt(decimalCounter) + 1;
            
        if (isNaN(c)) 
        {
            if(c ==".")
            {    if(parseInt(decimalCounter) > 1)
                    obj.value = s.substring(0, s.length-1);
            }
            else
                obj.value = s.substring(0, s.length-1); 
        }
    }
    return true;
}

function  ValidateEmailAddress(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1){
		return false;
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}
	
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	
	if (str.indexOf(" ")!=-1){
		return false;
	}

	return true;
}

 function SetProgressPosition(e) 
 {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.documentElement.scrollLeft;
        posy = e.clientY + document.documentElement.scrollTop;
    }
    document.getElementById('divProgress').style.left = posx + 10 + "px";
    document.getElementById('divProgress').style.top = posy  + "px";
}

/*************** Indicator Popup********************/
function popupLocation(logo) 
{
    var tempX = 0
    var tempY = 0
     tempX = findPosX(logo);
     tempY = findPosY(logo);
     height = window.innerHeight;
     if(window.innerWidth)
          width = window.innerWidth;
     else
        width = document.body.clientWidth;
     
         var pos = tempX * 1 + 230 + 400;
           
         if(parseInt(pos) > parseInt(width))
         {
           PositionBox(logo, tempX, tempY, 'right', 'rightbox', 'rightboxtext');
         }
         else 
         {
            PositionBox(logo, tempX, tempY, 'left', 'leftbox', 'leftboxtext');
         }
}
 function PositionBox(logo, X, Y, side, div1, div2)
 {  
        var box, div;
        
        if(side == 'left')
        {
           box = document.getElementById(div1);
           div = document.getElementById(div2); 
           X = X +190;
           Y = Y -35;
          
        }
        else
        {
           box = document.getElementById(div1);
           div = document.getElementById(div2);
           X = X - 400; 
           Y = Y -35;
        }
        var content =document.getElementById(logo.id.replace("_dvPartners", "_dvPartnerDetails"));
        box.style.left  = X +'px';
        
            box.style.top = Y +'px';
       
        div.innerHTML = content.innerHTML;
        box.style.display = 'block';
        box.style.position = 'absolute';
 }
 
 function hidepopup(div1, div2)
 {
    box = document.getElementById(div1).style.display = 'none';
    box = document.getElementById(div2).style.display = 'none';
 }

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  
function findPosY(obj)
  {
    var curtop = 0;
    if(document.body.scrollTop)
       {
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }   
       }
    else if(obj.offsetParent)
    {   while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }        
    }    
    else if(obj.y)
        curtop += obj.y;
        
    return curtop;
}

function SetProgressPosition(e) {
    var posx = 0;
    var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.documentElement.scrollLeft;
        posy = e.clientY + document.documentElement.scrollTop;
    }
    document.getElementById('dvProg').style.left = posx + 20 + "px";
    document.getElementById('dvProg').style.top = posy - 20 + "px";

}



var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    close: function () {
        $(".modal-window").remove();
        $(".modal-overlay").remove();
    },
    open: function () {

        var modal = "";
        modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
        modal += "<div class=\"imagevideobox\">" + this.content + "</div>";
        modal += "</div>";
        
        $(this.parent).append(modal);        
        $(".modal-window").append("<a class=\"close-window\"></a>");
        $(".close-window").click(function () { modalWindow.close(); });
        $(".modal-overlay").click(function () { modalWindow.close(); });
    }
};

var openMyModal = function (source) {
    modalWindow.windowId = "myModal";
    modalWindow.width = 750;
    modalWindow.height = 450;
 
    modalWindow.content = "<iframe  style=' width:710px;height:450px; padding-top:24px;' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
    modalWindow.open();
};  
