// JavaScript Document


/* Login to myCigna.com */
function submitLogin(){
	//*************** Production **********************
	var cons_action = 'https://my.cigna.com/corp/sso/member/forms/memberlogin.fcc'; /*Updated with new URL*/
	var cons_target = 'https://my.cigna.com/corp/sso/ci/member/routeeai.do';
	// Check to see that a user id was entered
	if (document.frmLogin.USERNAME.value == "" || document.frmLogin.USERNAME.value == userNameTooltip){   
		document.getElementById('errorMsgLogin').style.display = "block";
		document.getElementById('txtLogin').className = "roundedCornerBlue errorField";
		document.getElementById('txtLogin').value='';
		document.getElementById('errorMsgLogin').innerHTML = "*Please enter User Id to continue";
		document.getElementById('txtLogin').focus();
		return false;
	} else
	{
		document.getElementById('errorMsgLogin').style.display = 'none'; 
		document.getElementById('txtLogin').className = "roundedCornerBlue";
	}
		// Check to see that a password was entered
		if (document.frmLogin.PASSWORD.value == "" || document.frmLogin.PASSWORD.value == passwordTooltip ) {
			document.getElementById('errorMsgPassword').style.display = "block";
			document.getElementById('txtPassword').style.display = "none";
			document.getElementById('txtPasswrd').style.display="block";
			document.getElementById('txtPasswrd').className = "roundedCornerBlue errorField";
			document.getElementById('errorMsgPassword').innerHTML = "*Please enter Password to continue";
			document.getElementById('txtPasswrd').focus();
			return false;
		} else
		{	
			document.getElementById('errorMsgLogin').style.display = 'none';
			document.getElementById('txtLogin').className = "roundedCornerBlue";
			document.getElementById('errorMsgPassword').style.display = 'none';
			document.getElementById('txtPasswrd').className = "roundedCornerBlue";
			document.frmLogin.action = cons_action;
			// Submit the form	
			document.frmLogin.submit(); 
			return true;
		}
}


/* Find a doctor */
function submit_prov_form() {
	// Initialize and hide error message if visible. Text value can change when checkZip() is called.
	var findDocAction = "http://cigna.benefitnation.net/cigna/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";
	
	//Defect 885332 "In 'enter city/state -or- zip code' First letter should be in cpas" is Fixed
	document.getElementById('errorMsgFindDoctor').innerHTML = "Enter city/state -or- zip code";		
	document.getElementById('errorMsgFindDoctor').style.display = "none";
	
	// Check to see if location and state and zip are all empty
	if (document.dataform.city.value == "" && document.dataform.zip.value == "") {
		document.dataform.city.className="roundedCornerBlue errorField";
		document.dataform.zip.className="roundedCornerBlue errorField";
		if(document.getElementById("state").value == 0)
		{
			document.dataform.state.className="errorField";
			document.getElementById('errorMsgFindDoctor').innerHTML  =  "Enter city/state -or- zip code";
		}
		else
		{
			document.dataform.state.className="";
			document.dataform.zip.className="roundedCornerBlue";
			document.getElementById('errorMsgFindDoctor').innerHTML  =  "Enter city";
		}
		document.getElementById('errorMsgFindDoctor').style.display = "inline";
		return false;
	}
	
	// Check to see if default location and state and zip were never changed
	else if (document.dataform.city.value == "City" && document.dataform.zip.value == "ZIP Code") {
		document.getElementById('errorMsgFindDoctor').innerHTML  = "Enter city/state -or- zip code";
		return false;
	}


	// Check to see if default state and zip code values were never changed
	if (document.dataform.zip.value == "ZIP Code" && document.dataform.state.value == "0"  ) {
		document.getElementById('errorMsgFindDoctor').innerHTML =  "Enter city/state";
		document.getElementById('errorMsgFindDoctor').style.display = "inline";
		return false;
	}

	// Check to see if location and zip code are both empty
	if (document.dataform.zip.value == "" && document.dataform.state.value == "0"  ) {
		document.dataform.zip.className="roundedCornerBlue errorField";
		document.dataform.state.className="errorField";
		document.getElementById('errorMsgFindDoctor').innerHTML = "Enter city/state";
		document.getElementById('errorMsgFindDoctor').style.display = "inline";
		return false;
	}
	
	// Check to see if both City/State and ZIP are completed. If so, clear City/State. ZIP is more accurate
	if (document.dataform.city.value != "City" && document.dataform.city.value != "" && document.dataform.state.value != "0" && document.dataform.zip.value != "ZIP Code" && document.dataform.zip.value != "") {
		document.dataform.city.value = "";
		document.dataform.state.value = "0";
	}
	

  //Scrub the default text values
	if (document.dataform.zip.value == "ZIP Code") {
		document.dataform.zip.value = "";
	}
	
	if (document.dataform.city.value == "City") {
		document.dataform.city.value = "";
		document.dataform.state.value = "0";
	}
 	if (checkZip())
    {
		// Submit the form
		document.dataform.zip.className="roundedCornerBlue";
		document.dataform.action = findDocAction;
		document.dataform.submit();
		return true;
	}
	else 
		return false;
}

function checkZip() {
	//alert("Inside checkZip()");
	if ((document.dataform.zip.value.length < 5) && (document.dataform.zip.value != "")){
		document.getElementById('errorMsgFindDoctor').style.display = "inline";
		document.dataform.city.className="roundedCornerBlue";
		document.dataform.state.className="";
		document.getElementById('errorMsgFindDoctor').innerHTML = "Invalid Zip Code.";
		document.dataform.zip.value='ZIP Code';
		//alert("Zip < 5 and zip isn't empty");
		return false;
	}

	if ((document.dataform.zip.value.length > 4) && (document.dataform.zip.value != "ZIP Code")){
		//alert("Zip > 4 and not equal to ZIP Code");
		var ValidChars = "0123456789-";
		var IsNumber = true;
		var Char;
		var zipValue = document.dataform.zip.value;
		var zipSize = zipValue.length;

		for (var i=0; i<zipSize && IsNumber == true; i++) 
		{
			//alert("Inside checkZip() for loop");
			charVal = zipValue.charAt(i); 
			if (ValidChars.indexOf(charVal) == -1) 
			{
				//alert("Invalid character: " + charVal);
				document.dataform.zip.value='';
				//document.dataform.zip.focus();
				document.dataform.city.className="roundedCornerBlue";
				document.dataform.state.className="";
				document.getElementById('errorMsgFindDoctor').style.display = "inline";
				document.getElementById('errorMsgFindDoctor').innerHTML = "Invalid character(s) found in Zip Code field.";
				//alert ('You have entered one or more invalid characters into a numeric input field.\n\nPlease be sure to enter only values: ' + ValidChars + '.');
				IsNumber = false;
				return false;
				
			}
		}
	}
	document.dataform.city.className="roundedCornerBlue";
	document.dataform.state.className="";
	document.dataform.zip.className="roundedCornerBlue";
	return true;
}
/*function setPD_URL() {
	var bni = "http://cigna.benefitnation.net/cigna/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";
	var newLocation = location.href;
	var protocol = newLocation.split('://');
	var domain = protocol[1].split('/');
	if (domain[0] == ("wdcinp061")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}

	if (domain[0] == ("d-www.cigna.com")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}
	if (domain[0] == ("192.168.204.239")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}

	if (domain[0] == ("qawww.cigna.com")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}		
	if (domain[0] == ("qawww06.cigna.com")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}
	if (domain[0] == ("192.168.204.231")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}

	if (domain[0] == ("129.33.68.182")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}
	if (domain[0] == ("stage.cigna.com")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}
	if (domain[0] == ("129.33.68.140")) {bni = "http://staging.arvatocim.com/cigna_general_redesign/(r2pvr2jci5g4qh45dlnyliqj)/Physician.aspx";}
	var pdSearch = document.getElementById("frm_pdSearch");
	pdSearch.action = bni;
	//alert("Domain: " + domain[0] + "\n\nProvider URL: " + pdSearch);
}
*/


(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};
})(jQuery);


    /* Print Article */
    $(function(){
        $("a.printArticle").click(function(){
            document.getElementById("articlePrintCSS").href="/iwov-resources/css/printArticle.css";
            $("<div><a href='" + window.location + "' class='returnArticle'>" + returnToArticle + "</a></div>").appendTo('#contentContainer');
        });
        
    });

 
 function setFontSize(percent)
{

 var initSize = getCookie("fontSize");
 //initSize = (initSize == 'null') ? 100 : initSize; // Added by Hugues 2007-08-15
 initSize = (isNaN(initSize)) ? 100 : initSize; // Refactored by Gabe 2007-08-15
 if (!isNaN(percent)) { initSize = 100 + percent;} 
 setCookie(initSize);

if(document.getElementById)
{
	document.getElementsByTagName('body')[0].style.fontSize = initSize+'%'; 
return true; 
}else{ 
alert("This script does not work in your browser");  
return false;  
}
}

/*function setCookie(initSize) 
{
var cookieString = "fontSize=" + escape( initSize );
document.cookie = cookieString; 
return; 
} */

function getCookie(fontSize) 
{
var fontSize = document.cookie.match(fontSize + '=(.*?)(;|$)' );
if (fontSize){
	return (unescape (fontSize[1]));
} else {
	return null;
}  
}

//added by Gabe 08-16-07 - old code above
function setCookie(initSize)
{
	var url = location.href.slice(8);
	var startIn = url.indexOf("/sites/");
	var start = "/";
	if(startIn != -1) {
		start = url.slice(url.indexOf("/"), startIn);
	}
	var expiry=new Date();
	expiry.setDate(expiry.getDate()+365);
	var cookieString = "fontSize=" + escape( initSize ) + "; expires="+expiry+"; path="+start;
	document.cookie = cookieString; 
	return; 
}

function openPDF(pdfName) {
	// where the pdfs are
	var path = "/sites/cignamedicare/pdf/";
	
	// set how the window should be opened
	var wSettings = "width=1000,height=800,resizable=yes,top=0,left=0";
	
	//var selectedStatePDF = document.getElementById('sobStateSelect').value;
	var pdf = pdfName;
	
	if (pdf != "") {
		wHref = path + pdf;
		// open the window
		newWin = window.open(wHref,'', wSettings);
		newWin.focus();
	}
							
	return false;
}

