// JavaScript Document - Global functions


//preload images
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

var swap_text_boxes = [];
function init_swap_text_boxes(){
  $('input[type=text][value].bmg_swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  $('input[type=text][value].bmg_swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
  	  $(this).select(); 
	  if ($(this).hasClass("bmg_swap_color")){
	  	 $(this).addClass("bmg_swaptextboxMod");
	  }	
    }
  });
  $('input[type=text][value].bmg_swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
	if ($(this).hasClass("bmg_swap_color")){
	  	 $(this).removeClass("bmg_swaptextboxMod");
	  }	  	  
    }
  });
}

var UTIL = UTIL || {};
UTIL.popup = UTIL.popup || {};
UTIL.popup.open = function (href, params)
{
   var defaultParams = {
       "width":       "600",   
       "height":      "520",   
       "top":         "0",     
       "left":        "0",     
       "directories": "no",   
       "location":    "no",    
       "resizeable":  "yes",   
       "menubar":     "no",    
       "toolbar":     "no",    
       "scrollbars":  "yes",   
       "status":      "no"     
   };
    var windowName = params["windowName"] || "new_window";
    var i, useParams = "";
   for (i in defaultParams)
   {
       useParams += (useParams === "") ? "" : ",";
       useParams += i + "=";
       useParams += params[i] || defaultParams[i];
   }
    return window.open(href, windowName, useParams);
};

$(document).ready(function(){
	$.preloadImages("/qptcms/qCmsRepository/Global/largeBusiness/images/loading-circle.gif","/qptcms/qCmsRepository/Global/largeBusiness/images/loading-image-bg.gif");						   
  	$("a.bmg_popup").each(function (i){
       $(this).click(function(event) {
           event.preventDefault();
           var params = $(this).data("bmg_popup") || {};            
           if ($(this).attr("target"))
           {
               params.windowName = $(this).attr("target");
           }
           var windowObject = UTIL.popup.open(this.href, params);
           $(this).data("windowObject", windowObject);
       });
   });
			$.fn.alphanumeric = function(pq) { 
		pq = $.extend({
			ichars: "!@#$%^&*()_-+=[]\\\';,/{}|\":<>?~`. ",
			nchars: "",
			allow: ""
		  }, pq);	
		return this.each
			(
				function() 
				{
					if (pq.nocaps) pq.nchars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
					if (pq.allcaps) pq.nchars += "abcdefghijklmnopqrstuvwxyz";					
					sq = pq.allow.split('');
					for ( i=0;i<sq.length;i++) if (pq.ichars.indexOf(sq[i]) != -1) sq[i] = "\\" + sq[i];
					pq.allow = sq.join('|');		
					var reg = new RegExp(pq.allow,'gi');
					var ch = pq.ichars + pq.nchars;
					ch = ch.replace(reg,'');
					 $(this).unbind("keypress");
					$(this).keypress
						(
							function (e)
								{
									if (!e.charCode) k = String.fromCharCode(e.which);
										else k = String.fromCharCode(e.charCode);
										
									if (ch.indexOf(k) != -1) e.preventDefault();
									if (e.ctrlKey&&k=='v') e.preventDefault();	
								}						
						);
					$(this).bind('contextmenu',function () {return false});				
				}
			);
	};
	$.fn.numeric = function(pq) {
	
		var atoz = "abcdefghijklmnopqrstuvwxyz";
		atoz += atoz.toUpperCase();

		pq = $.extend({
			nchars: atoz
		  }, pq);
		return this.each (function()
			{
				$(this).alphanumeric(pq);
			}
		);
	};
	$.fn.alpha = function(pq) {
		var nm = "1234567890";
		pq = $.extend({
			nchars: nm
		  }, pq);
		return this.each (function()
			{
				$(this).alphanumeric(pq);
			}
		);
			
	}; 
	
try { 
	document.execCommand('BackgroundImageCache', false, true);
} 
catch(e) {}
	init_swap_text_boxes();				   

}); 


function gotoContactUs(){
	  if(channelE=='Large Business'){
			location.href=  "/business/contact-us-v1b.html"; }
		/*else if(channelE=='Industry Analysts'||channelE=='Consultants'||channelE=='Partners'||channelE=='Systems Integrators')
		{
			document.bmg_mainForm.submit(); return false;
			}*/
        else  {   location.href=  "/business/contact-us.html"; 	}
}
