﻿// Global variable
var color = "";






// Javascript function for showing the captcha explanation
function ShowCaptcha()
{

    // Grab the current page height
    var PageHeight = screen.height;
    var PageWidth = screen.width;
    
    
    // Determine the top and left positions
    var PageTop = ((PageHeight - 440) / 2);
    var PageLeft = ((PageWidth - 440) / 2);
        
    
    // Open up the new window
    window.open("/sno/Dynamic/Captcha/codeverification.html", "null", "width=440, height=440, top=" + PageTop + ", Left=" + PageLeft + "location=no, menubar=no, resizeable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");


}






// Javascript function removes the e-mail text on focus
function RemoveEmail(TextBox)
{
    if (TextBox.value == "E-mail address")
    {
        TextBox.value = "";
    }
}






// Javascript function resets the e-mail textbox
function ResetEmail(TextBox)
{
    if (TextBox.value == "")
    {
        TextBox.value = "E-mail address";
    }
}






// Javascript function for viewing larger images
function ViewImage(ImgWidth, ImgHeight, ImgPath)
{


    // Grab the current page height
    var PageHeight = screen.height;
    var PageWidth = screen.width;
    
    
    
    // Determine the top and left positions
    var PageTop = ((PageHeight - ImgHeight) / 2);
    var PageLeft = ((PageWidth - ImgWidth) / 2);
    
    
    // Open up the new window
    window.open(ImgPath, "null", "width=" + ImgWidth + ", height=" + ImgHeight + ", top=" + PageTop + ", left=" + PageLeft + ", location=no, menubar=no, resizeable=no, scrollbars=no, titlebar=no, toolbar=no");


}





// Function validates an e-mail address
function ValidateEmail(){
	var emailID=document.NewsletterBox.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("E-mail Address is Required to Register")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 
 
 
 
 
 // Function validates an e-mail address and coincides with function ValidateForm()
 function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address Entered")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address Entered")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address Entered")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address Entered")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address Entered")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address Entered")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address Entered")
		    return false
		 }

 		 return true					
	}
	
	
	
	
	
	
// Javascript function for opening the issue preview flash application window
function PreviewIssue()
{


    // Grab the current page height
    var PageHeight = screen.height;
    var PageWidth = screen.width;
    
    
    // Determine the top and left positions
    var PageTop = ((PageHeight - 430) / 2);
    var PageLeft = ((PageWidth - 660) / 2);
    
    
    // Open the new window
    window.open("/ext/dynamic/issuepreview.aspx", "null", "width=660, height=430, left=" + PageLeft + ", top=" + PageTop + ", location=no, menubar=no, resizeable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");


}






// Function opens up the tell a friend about an article window
function TellFriend(ArticleID)
{

    // Grab the current window width and height
    var WindowWidth = screen.width;
    var WindowHeight = screen.height;
    
    
    
    // Determine the top and left positions
    var Top = (WindowHeight - 600) / 2;
    var Left = (WindowWidth - 850) / 2;
    
    
    
    // Set the window link and properties
    var Link = "/ctr/dynamic/emailarticle.aspx?id=" + ArticleID;
    var Properties = "width=850, height=600, top=" + Top + ", left=" + Left;
    
    
    
    // Open the new window
    window.open(Link, "null", Properties);

}








// Function fixes the transparent png on IE 6
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}







// Function for changing color of a gridview control row on check
function changeColor(obj, gridview)
{

    var rowObject = getParentRow(obj);
    var parentTable = document.getElementById(gridview);
    
    
    if (color == "")
    {
        color = getRowColor();
    }
    
    
    if (obj.checked)
    {
        rowObject.style.backgroundColor = "Yellow";
    }
    else
    {
        rowObject.style.backgroundColor = color;
        color = "";
    }

}






// Gets a rows coor
function getRowColor()
{
    if (rowObject.style.backgroundColor == "")
    {
        return parentTable.style.backgroundColor;
    }
    else
    {
        return rowObject.style.backgroundColor;
    }
}






// Gets the parent row of the object
function getParentRow(obj)
{
   do
   {
    obj = obj.parentElement;
   }
   while (obj.tagName != "TR")
   return obj;
}