/*Author  Nandish@unosofttech.com
Date    18/04/09


NOTE:
PROBLEM
Internet Explorer doesn’t like scripts appending elements to the 
existing DOM, for that reason its give's Operation aborted error in alert message and firefox won't 
give becuase its forgivable

SOLUTION
One way to circumvent the error is to wait till the entire page DOM has been rendered. 
You can do that with window.onload or if you prefer using Jquery Javascript Framework 
jQuery has the ready method but numerous frameworks come with their own implementation.*/

// ----------------------------------------------------------------------
function checkBrowserType() {
	var browsertype = $.browser.msie
		return (browsertype) ? "msie" :"mozilla";
}
// ----------------------------------------------------------------------
function checkBrowserVersion() {
	var brwoserversion = $.browser.version ;
	return parseInt(brwoserversion);
}
// ----------------------------------------------------------------------
function calljqueryBlock(){
	    
		$.blockUI.defaults.css = {      
		padding:        0,
        margin:         0,
        width:          '52%', 
        top:            '35%', 
        left:           '25%', 
        textAlign:      'center', 
        color:          '#000', 
		height:         '15%',
        border:         '3px solid #aaa',
        backgroundColor:'white',
        cursor:         'hand'
		};
	  document.getElementById('dilogBody').style.visibility="visible";
	  document.getElementById('browserWarning').style.visibility="visible";
	  if(document.getElementById('flashbox')!= null) {
	  document.getElementById('flashbox').style.visibility="hidden";
	  }
	  if(document.getElementById('banner')!= null) {
	  document.getElementById('banner').style.visibility="hidden";
	  }
      jQuery.blockUI({message:$('#dilogBody').fadeIn("slow")}); 
	}
    // ----------------------------------------------------------------------
    function checkBrowserCompatibility() {
		 var version = checkBrowserVersion();
		 var browname = checkBrowserType();
    // for IE, create dynamic element when the dom object is ready along with other related stuff also
          switch(browname){
			  case "msie":
				  if(version <=6){
                       if (!checkCookieExist()) { 
						$(document).ready(function() {
						DynamicElement();
						calljqueryBlock();
						close();
						$("#browserWarning").html("<p style='font-size:12px;font-family:Arial;color:#000000';>You are using an unsupported version of the browser. This website is designed for <b>IE 7+</b><br/>Some of the features on the website might not work with your current browser.<br/>Click on the <b>Close button</b> to continue.</p3>");
						});
					}
                 }
                 break;
			 case "mozilla":
				     
			           if (!checkCookieExist()) {
					       DynamicElement();
						   calljqueryBlock();
                       $("#browserWarning").html("<p style='font-size:12px;font-family:Arial;color:#000000';>You are using an unsupported version of the browser. This website is designed for <b>IE 7+</b><br/>Some of the features on the website might not work with your current browser.<br/>Click on the <b>Close button</b> to continue.</p3>");
					}
                  break;
             default :
				       if (!checkCookieExist()) {
						   DynamicElement();
						   calljqueryBlock();
                      $("#browserWarning").html("<p style='font-size:12px;font-family:Arial;color:#000000';>You are using an unsupported version of the browser. This website is designed for <b>IE 7+</b><br/>Some of the features on the website might not work with your current browser.<br/>Click on the <b>Close button</b> to continue.</p3>");
					}
					   break;
		  } // End of Switch
	}
// ---------------------------------------------------------------------------
     function close() {	
	    $(document).ready(function() {
		$("#close").click(function() {
             jQuery.unblockUI();
			 if(document.getElementById('banner')!= null) {
				document.getElementById('banner').style.visibility="visible";
			 }
			  if(document.getElementById('flashbox')!= null) {
				document.getElementById('flashbox').style.visibility="visible";
			  }
             $('#browserWarning').css({"visibility":"hidden"});
		     $('#dilogBody').css({"visibility":"hidden"});
			 $('#dilogBody').css({"display":"none"});
		     $('#browserWarning').css({"display":"none"});
	 });});
	 }

// ---------------------------------------------------------------------------
	 $(document).ready(function() {
		$("#close").click(function() {
             jQuery.unblockUI();
			 if(document.getElementById('banner')!= null) {
				document.getElementById('banner').style.visibility="visible";
			 }
			  if(document.getElementById('flashbox')!= null) {
				document.getElementById('flashbox').style.visibility="visible";
			  }
			 $('#browserWarning').css({"visibility":"hidden"});
		     $('#dilogBody').css({"visibility":"hidden"});
			 $('#dilogBody').css({"display":"none"});
		     $('#browserWarning').css({"display":"none"});
			});});



// ---------------------------------------------------------------------------

function DynamicElement() {
	//Note try to assign style attributes using Dom style properties when creating elements in dynamically
	try{
	parentDiv = document.createElement('div');
	parentDiv.setAttribute("id","dilogBody");
	parentDiv.style.width = "100%";
	parentDiv.style.visibility = "hidden";


    childDiv  =  document.createElement('div');
	childDiv.setAttribute("id","head");
    childDiv.style.cursor = "pointer";     //if i set pointer will hand in fireox
	childDiv.style.height = "18px";
	childDiv.style.backgroundColor = "#75bede";
    childDiv.style.fontWeight = "900";
	childDiv.style.textAlign = "right";



	spanDiv   =  document.createElement('span');
	spanDiv.setAttribute ("id","close");
    spanDiv.setAttribute ("title","Click here to close");
    spanDiv.style.fontFamily = "Arial";
    spanDiv.style.fontWeight = "900";
	spanDiv.style.fontSize = "12px";
	spanDiv.style.color = "#000000";
	// assingn attribute of onclick when the browser type is msie and the version less than 6
	if(checkBrowserType == "msie" &&  checkBrowserVersion <=6) {
    spanDiv.setAttribute ("onClick","close();"); 
	}
	

	spanText  =  document.createTextNode('Close(X)');
	spanDiv.appendChild(spanText);
	


	dialogDiv = document.createElement('div');
	dialogDiv.setAttribute("id","browserWarning");
    dialogDiv.style.textAlign = "left";
	dialogDiv.style.visibility = "hidden";
	dialogDiv.style.height = "90%";
	dialogDiv.style.overflow="auto";
	dialogDiv.style.color ="white";
	dialogDiv.style.paddingLeft = "10px";

    childDiv.appendChild(spanDiv);
    parentDiv.appendChild(childDiv);
	parentDiv.appendChild(dialogDiv);
	document.body.appendChild(parentDiv);
	}
	catch(e) {}
	}
// ---------------------------------------------------------------------------

	function  checkCookieExist() {
		 var visitors = "visitors";
        if(ReadCookie(visitors)!= "true" || ReadCookie(visitors) == "") {
			setCookie(visitors,"true",04);
		            return false;
		} else {
					return true;
					
		}

    }


// ---------------------------------------------------------------------------
function setCookie(c_name,value,expireHour) {
var cookie_date=new Date();
//set four hours to expire
cookie_date.setHours(cookie_date.getHours() + expireHour);
document.cookie=c_name+ "=" +value+((expireHour==null) ? "" : ";expires="+cookie_date.toGMTString());
}


// ---------------------------------------------------------------------------

//read cookie based on CookieName
function ReadCookie(cookieName) {
  var theCookie= "" + document.cookie;
  var ind= theCookie.indexOf(cookieName);
  if (ind== -1 || cookieName== "") 
	  return ""; 
  var ind1= theCookie.indexOf(';',ind);
  if (ind1== -1) 
	  ind1= theCookie.length; 
  return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
// ---------------------------------------------------------------------------
