// Author: Dhanabal Duraisamy (dhanaps@ocenture.com)

// $Id: /scripts/general.css.php,v 1.1 $

function autoTab(eCtrl,len)
{
  if(eCtrl.value.length >= len)  { 
    eCtrl.value = eCtrl.value.slice(0, len);
    eCtrl.form[(getIndex(eCtrl)+1) % eCtrl.form.length].focus();
  }
  
  function getIndex(eCtrl)
  {
     var index = -1, i = 0, found = false;
     while (i < eCtrl.form.length && index == -1)
      if (eCtrl.form[i] == eCtrl) { index = i; } else { i++; }
     return index;
  }
  return true;
}

// openPopWin
// winFeatures = scrollbars,toolbar,menubar,resizable
var popWin = null;    // use this when referring to pop-up window
var winCount = 0;
var winName = "popWin";
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20;  // default, pixels from screen left to window left
  var d_winTop = 20;   // default, pixels from screen top to window top
  winName = "popWin" + winCount++; //unique name for each pop-up window
  closePopWin();           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features? 
    winFeatures = "," + winFeatures;
  else 
    winFeatures = ""; 
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop);
  else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop);
  popWin = window.open(winURL, winName, "width=" + winWidth 
           + ",height=" + winHeight + winFeatures);
  }
function closePopWin(){    // close pop-up window if it is open 
  if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close() ;
  }
function getLocation(winWidth, winHeight, winLeft, winTop){
  return "";
  }

// for Netscape 4+ and IE 4+
function getLocation(winWidth, winHeight, winLeft, winTop)
{
  var winLocation = "";
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft;
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop;
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20;
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2;
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft
                + ",screenY=" + winTop + ",top=" + winTop;
  else
    winLocation = "";
  return winLocation;
  }


function openWin(winURL) 
{
	window.open(winURL);
}

function addToCart(formName, prodId)
{
  formObj = eval("document." + formName);
  formObj.fProdId.value = prodId;
  formObj.submit();
}


function loadPaymentInfo(frmObj)
{
	var i = frmObj.fProducts.selectedIndex ;

	if ( parseInt(i) >= 0) {	
	  var srtingArr = billArr[i].split("~");
	  frmObj.fCardType.value=srtingArr[0];
	  frmObj.fCardNumber.value=srtingArr[1];
	  frmObj.fExpMonth.value=srtingArr[2];
	  frmObj.fExpYear.value=srtingArr[3];
	  frmObj.fCardHolderName.value=srtingArr[4];
	  frmObj.fCCV.value=srtingArr[5];
	  frmObj.fOrderId.value=srtingArr[6];
	  frmObj.fProcType.value=srtingArr[7];
	  frmObj.fProdTitle.value=srtingArr[8];
	}
}


// Extended Tooltip Javascript
// copyright 9th August 2002, 3rd July 2005
// by Stephen Chapman, Felgall Pty Ltd

// permission is granted to use this javascript provided that the below code is not altered
var DH = 0;var an = 0;
var al = 0;var ai = 0;

if (document.getElementById) {ai = 1; DH = 1;}else {if (document.all) {al = 1; DH = 1;} else { browserVersion = parseInt(navigator.appVersion); if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {an = 1; DH = 1;}}} function fd(oi, wS) {if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi); if (al) return wS ? document.all[oi].style: document.all[oi]; if (an) return document.layers[oi];}
function pw() {return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;}
function mouseX(evt) {if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return null;}
function mouseY(evt) {if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return null;}
function popUp(evt,oi) {if (DH) {var wp = pw(); ds = fd(oi,1); dm = fd(oi,0); st = ds.visibility; if (dm.offsetWidth) ew = dm.offsetWidth; else if (dm.clip.width) ew = dm.clip.width; if (st == "visible" || st == "show") { ds.visibility = "hidden"; } else {tv = mouseY(evt) + 20; lv = mouseX(evt) - (ew/4); if (lv < 2) lv = 2; else if (lv + ew > wp) lv -= ew/2; if (!an) {lv += 'px';tv += 'px';} ds.left = lv; ds.top = tv; ds.visibility = "visible";}}} 

//IE has a problem with wanted select form tags to always be the topmost z-index or layer

function hideSelectBoxes(myDoc) {
 for(var i = 0; i < myDoc.forms.length; i++) {
   for(var e = 0; e < myDoc.forms[i].length; e++){
	 if(myDoc.forms[i].elements[e].tagName == "SELECT") {
    	myDoc.forms[i].elements[e].style.visibility="hidden";
	 }
   }
  }
}

var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);

if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
	hideSelectBoxes(document);
}

function checkCartQuantity(formObj)
{
	if (formObj.fQuantity.value == '') {
	  alert("Quantity cannot be empty.");
	  return false;
	} else if (isNaN(formObj.fQuantity.value)) {
	  alert("Please enter numeric values only in Quantity field.");
	  return false;
	} else if (formObj.fQuantity.value <= 0) {
	  alert("Quantity cannot be less than 1.");
	  return false;
	} else {
	  return true;
	}
}

function getPageSize() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  return( new Array(myWidth, myHeight) );  
	}
	function openThickTest( url, width, height ) {
		if ( width > 0 && height > 0 ) {
			pageHeight = height;
			pageWidth = width;
		}
		else {
		    var pageSize = getPageSize();    
		    pageHeight = pageSize[ 1 ] * 0.9 ;
		    if (pageHeight > 550) {
		        pageHeight = 550;
		    }
		    pageWidth = pageSize[ 0 ] * 0.7 ;
		}
	    url += '&keepThis=true&TB_iframe=true&height=' + pageHeight + '&width=' + pageWidth;
	    tb_show('', url, false);
	}
	function openThickProportions( url ) {
	    var pageSize = getPageSize();    
	    pageHeight = pageSize[ 1 ] * 0.9 ;
	    pageWidth = pageSize[ 0 ] * 0.9 ;
	    url += '&keepThis=true&TB_iframe=true&height=700&width=1200';
	    alert( url );
	    tb_show('', url, false);
	}
	//This function works when url is ended with .html or .php

	function openThickTest1( url, pageWidth, pageHeight ) {		
		if ( pageWidth === false || pageHeight === false ) {
		    var pageSize = getPageSize();    
		    pageHeight = pageSize[ 1 ] * 0.9 ;
		    if (pageHeight > 550) {
		        pageHeight = 550;
		    }
		    pageWidth = pageSize[ 0 ] * 0.7 ;
		}
	    url += '?keepThis=true&TB_iframe=true&height=' + pageHeight + '&width=' + pageWidth;     //Here & character whas replaced with ?	  
	  
	    if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		    tb_show('', url, false);
			tb_showIframe();
			if($('#TB_iframeContent').length != 0){
			    var savedSrc = $('#TB_iframeContent').attr('src');		
				$('#TB_iframeContent').removeAttr('src').attr('src', savedSrc);			
			}
	    }	else	{
	    	tb_show('', url, false);
		}
	}


	function setThickboxStyleLinks( parentObject ) {                    
	    var pageSize = getPageSize();    
	    pageHeight = pageSize[ 1 ] * 0.9 ;
	    pageWidth = pageSize[ 0 ] * 0.7 ;
	    ahrefs = parentObject.getElementsByTagName( "A" );
	    for ( i = 0; i < ahrefs.length; i ++ ) {
	        hrefString = ahrefs[ i ].href;                        
	        if ( hrefString.match( /\?/ ) ) {
	            ahrefs[ i ].href = ahrefs[ i ].href + "&";
	        }
	        else {
	            ahrefs[ i ].href = ahrefs[ i ].href + "?";
	        }
	        ahrefs[ i ].href = ahrefs[ i ].href + "KeepThis=true&TB_iframe=true&height=" + pageHeight + "&width=" + pageWidth;
	    }
	}
	
	
	function changeMenuClass( obj, newState ) {
		var initialState = obj.getAttribute( "initialState" );
		var initialStyle = obj.getAttribute( "initialStyle" );	
		if ( newState == 1 && initialState == '' ) {
			obj.className = initialStyle + 'On';
		}
		else {
			obj.className = initialStyle;
		} 
	}

	function changeImage ( id ) {
	      if ( document.getElementById('img_'+id+'_off').style.display != "none" ) {
	        document.getElementById('img_'+id+'_on').style.display = "block";
	        document.getElementById('img_'+id+'_off').style.display = "none";   
	      }
	      else {
	        document.getElementById('img_'+id+'_off').style.display = "block";
	        document.getElementById('img_'+id+'_on').style.display = "none";  
	      }
	}
	   
	function setHeight() {
	 var myWidth = 0, myHeight = 0;
	      if( typeof( window.innerWidth ) == 'number' ) {
	        //Non-IE
	        myWidth = window.innerWidth;
	        myHeight = window.innerHeight;
	      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	        //IE 6+ in 'standards compliant mode'
	        myWidth = document.documentElement.clientWidth;
	        myHeight = document.documentElement.clientHeight;
	      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	        //IE 4 compatible
	        myWidth = document.body.clientWidth;
	        myHeight = document.body.clientHeight;
	      }
	       document.body.style.height = myHeight +'px';
	       var iframeElement = parent.document.getElementById('frameContent');
	       headerHeight =  document.getElementById('header').clientHeight;
	       footerHeight = document.getElementById('footer').clientHeight;
	       iframeHeight = myHeight-footerHeight-210;
	       iframeElement.style.height = iframeHeight + 'px';  
	       
	}
	
function $(element) {
	if (typeof(element) == 'string') element = document.getElementById(element);
	return element;
}

function toggleValue(id, value) {
	if ($(id).value == value)
		$(id).value = '';
	else
		if ($(id).value == '')
			$(id).value = value;
}

function checkFiltering() {
	if ($('travel_type').value)
		return true;
	if ($('t_from_date').value != 'month/day/year')
		return true;
	else {
		window.alert('Please select "From" date');
		$('t_from_date').value = '';
		$('t_from_date').focus();
		return false;
	}
}
 function showDetails( obj, over) {
    var initObj = obj;
    var curleft = curtop = 0;
    if ( over == 1 ) {
        if (obj.offsetParent) {
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
        }
        messageFound = false;
        var continer = initObj;
        while ( !messageFound ) {
            continer = continer.parentNode;
            if ( continer.tagName == "HTML" ) {
                cvmessage = "";    
                messageFound = true;
            }
            else {
                spans = continer.getElementsByTagName( "SPAN" );
                for ( i = 0; i < spans.length; i ++ ) {
                    if ( spans[ i ].getAttribute( "cvmessage" ) == "true" ) {
                        cvmessage = spans[ i ].innerHTML;    
                        messageFound = true;
                    }
                }
            }                
        }
        if ( document.getElementById( "customMessage" ) ) {
            var detailsDiv = document.getElementById( "customMessage" );
        }
        else {
            detailsDiv = document.createElement( "DIV" );
            detailsDiv.innerHTML = cvmessage;                   
            document.body.appendChild(detailsDiv);        
        }
        detailsDiv.id = "customMessage";
        detailsDiv.style.left = (curleft + 10 ) + "px";
        detailsDiv.style.top = (curtop  + 10 ) + "px";
    }
    else {
        if ( document.getElementById( "customMessage" ) ) {
            var detailsDiv = document.getElementById( "customMessage" );
            detailsDiv.parentNode.removeChild( detailsDiv );
        }
    }                
}
//Browser Detection Javascript
 function detectBrowser() {
	 var agt=navigator.userAgent.toLowerCase();
	 if (agt.indexOf("opera") != -1) return 'Opera';
	 if (agt.indexOf("chrome") != -1) return 'Chrome';
	 if (agt.indexOf("firefox") != -1) return 'Firefox';
	 if (agt.indexOf("safari") != -1) return 'Safari';
	 if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	 if (agt.indexOf("netscape") != -1) return 'Netscape';
	 if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	 
	 if (agt.indexOf('\/') != -1) {
		 if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
			 return navigator.userAgent.substr(0,agt.indexOf('\/'));
		 }
		 else 
			 return 'Netscape';
	 } else if (agt.indexOf(' ') != -1)
		 return navigator.userAgent.substr(0,agt.indexOf(' '));
	 else return navigator.userAgent;
 }

 function showFieldNotes( triggerObject, fieldId, showMessage ) {
		fieldObj = document.getElementById( fieldId );
		if ( showMessage == 1 ) {
			var fieldNotes = fieldObj.getAttribute( "fielddetails" );
			var noteElement = document.createElement( "span" );
			noteElement.setAttribute( "class", "fieldNotes" );
			noteElement.setAttribute( "id", fieldId + "_notes" );
			noteElement.innerHTML = fieldNotes; 
			triggerObject.parentNode.appendChild( noteElement );
		}
		else {
			if ( document.getElementById( fieldId + "_notes" ) ) {			
				noteElement = document.getElementById( fieldId + "_notes" );
				noteElement.parentNode.removeChild( noteElement );
			}
		}
	}
 function setThinkboxStyleLinks( parentObject ) {                    
	    var pageSize = getPageSize();    
	    pageHeight = pageSize[ 1 ] * 0.9 ;
	    pageWidth = pageSize[ 0 ] * 0.7 ;
	    ahrefs = parentObject.getElementsByTagName( "A" );
	    for ( i = 0; i < ahrefs.length; i ++ ) {
	        hrefString = ahrefs[ i ].href;                        
	        if ( hrefString.match( /\?/ ) ) {
	            ahrefs[ i ].href = ahrefs[ i ].href + "&";
	        }
	        else {
	            ahrefs[ i ].href = ahrefs[ i ].href + "?";
	        }
	        ahrefs[ i ].href = ahrefs[ i ].href + "KeepThis=true&TB_iframe=true&height=" + pageHeight + "&width=" + pageWidth;
	    }
	}

function loadIDReportByMonth( lastScanDate, pageName ) {
	
	if (lastScanDate == '') {
		alert ("No recent scan available at this time. Please check back later.");
	} else {	
		var url = location.protocol + '//' + location.host + '/' + pageName + '/' + lastScanDate;
		var newWindow = window.open(url, '_blank');
		newWindow.focus();
	}
}