﻿var services2 = new services2();
function services2() {
    this.findPartner2 = findPartner2;
    
	function findPartner2(type) {
		var zipInput = document.getElementById('zipInput2');
		
		if (zipInput == undefined) {
		    zipInput = PartnerFinderCurrentInput;
	    } else {
	        if (zipInput.value == "")
	            zipInput = PartnerFinderCurrentInput;
	   } 
	        
		var partnerFinder = document.getElementById('partnerFinderBtn2');
		
		validation2.showStatus(partnerFinder,"Searching...");
		if (type == undefined) type = "-1";//all partner types
		
		//location = '/smallbusiness/partner/vendorsearch.mspx?c=' + type + '&r=5&pc=' + zipInput.value;
		location = 'http://pinpoint.microsoft.com/en-US/category.aspx?advanced=0&configName=Default&SFSite=sbc_en&fl=' + zipInput.value;
	}
}

var validation2 = new validation2();
var tipFadeTimeout = new Array();
var tipFadeColors = "#ffff99,#ffffc0,#ffffd9,#ffffe7";
var tipFadeInit = false;
var tipInitX, tipInitY, tipCurX, tipCurY;
var tipObjCur;
var tipObjCurSrcElement;
var tipFadeLast;

function validation2 () {
    this.showTip2 = showTip2;
    this.tipMouseOut = tipMouseOut; 
    this.tipMouseOn = tipMouseOn;  
    this.mouseMove = mouseMove; 
    this.hideTip = hideTip; 
    this.showStatus = showStatus;  
   
    this.checkZip2 = checkZip2;
    this.checkIsDigit = checkIsDigit;
   
    function checkZip2(input, passStatement, evt) {
        var valid = false; 
        var tipText =  "Please enter a 5-digit ZIP code.";
        
        var e = (window.event) ? window.event : evt;
        
        if (!input.value.match(/^\d+$/) && input.value != "") {//assumes call from onkeydown event
            validation2.showTip2(input,tipText);
            valid = false;
        } else {
            if (input.value.length == 5) {
               validation2.hideTip(input);
                 if (e) {
                    if (e.type == "click") eval(passStatement);
                    if (e.type == "keydown") if (e.keyCode == 13) eval(passStatement);
               } else {
                    eval(passStatement);
               }
               valid = (passStatement == "") ? true : false;
            } else {
                if (e) {
                    if (e.type == "click") {
                        validation2.showTip2(input,tipText);
                    }
                    if (e.type == "keydown") {
                        if (e.keyCode == 13) {
                            validation2.showTip2(input,tipText);
                        }
                    }
               } else { 
                    validation2.showTip2(input,tipText);
               }
                valid = false;
            }
        } 
       
       return valid;
    }
   
    function checkIsDigit(input,passStatement,tipText) {
        var digitsOnly = /^\d+$/; 
        var checkBool =  (input.value.match(digitsOnly) != null);
       if (checkBool) { 
            validation2.hideTip(input);
            eval(passStatement);
       } else {
            validation2.showTip2(input,tipText);
       } 
        return checkBool; 
    }    
   
    function showStatus(obj, text) {
       validation2.showTip2(obj, "searching...");
       if (obj)
       if (obj.style != undefined)
       obj.style.color = "#ccc";
       obj.style.cursor = "wait";
    }     
   
     this.setMouseMoveHandler = setMouseMoveHandler;
     
    function  setMouseMoveHandler() {
        if (browserUtility.getBrowser() == "ie") {
            document.onmousemove = validation2.mouseMove;
       } else {
            window.captureEvents(Event.MOUSEMOVE);
	        window.onmousemove = validation2.mouseMove;
	   } 
    }    
   
    this.cancelMouseMoveHandler = cancelMouseMoveHandler;
   
  function cancelMouseMoveHandler() {
       
       if (browserUtility.getBrowser() == "ie") {
            document.onmousemove = "void";
       } else {
            window.captureEvents(Event.MOUSEMOVE);
	        window.onmousemove = "void";
	   } 
	     tipInitX = "";
         tipInitY = "";
    }      
   
    function showTip2(obj, text) {
        var objChange = (tipObjCurSrcElement = obj) ? false: true;
        tipObjCurSrcElement = obj; 
       
        var tip = document.createElement("span");
        tip.id = obj.id + "_tip2"; 
        tip.className = "tip";
        tip.style.left = '120px';
        tip.style.top = '60px'; 
        
       var close =  '<div title="Hide Tip" style="TOP:0px; MARGIN:0px;POSITION:relative; PADDING-RIGHT: 1px; DISPLAY: block; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; PADDING-TOP: 1px" class="tip_close" onclick="validation2.hideTip(document.getElementById(\'' + obj.id + '\'));"/>'; 
       var closeChild = document.createElement("div");
        closeChild.innerHTML = close;
       
        if (text.style != undefined || text.className != undefined) {//if obj w/ html instead of just text
            
            if (text.style.width) tip.style.width = text.style.width;
            if (text.style.height) tip.style.height = text.style.height;
            
            if (text.style.position) {
                tip.style.position = text.style.position;
               if (text.style.left)  tip.style.left = text.style.left;
               if (text.style.top)  tip.style.top = text.style.top;
            }
            tip.innerHTML += text.innerHTML;
            var firstNode = xmlUtility.getFirstComplexChild(tip);
            firstNode.insertBefore(closeChild,firstNode.childNodes[0]);
            tip.style.display = 'block'; 
       } else {
            tip.innerHTML += close;
            tip.innerHTML += '<div class="tip_text" style="POSITION:relative; TOP:0px; WIDTH:90px; PADDING-RIGHT: 1px; DISPLAY: block; PADDING-LEFT: 1px; FONT-WEIGHT: normal; FONT-SIZE: 8pt; LEFT: 15px; PADDING-BOTTOM: 1px; MARGIN: 1px; LINE-HEIGHT: normal; PADDING-TOP: 1px; FONT-">' + text + '</div>'; 
        } 
       
       
       
      
       var nextSibling = domNav.returnNextSibling(obj);
       if (nextSibling) {
            if (nextSibling.id != tip.id) {
                    obj.parentNode.insertBefore(tip,nextSibling);
            } else {
                    tip = document.getElementById(obj.id + "_tip2");
                    tip.style.display = 'block'; 
            } 
      } else {
         obj.parentNode.appendChild(tip);
     } 
     
     tipObjCur = tip; 
     //setMouseMoveHandler();//sets global tipInitX, tipInitY, etc vars
   }    
  
    function mouseMove(e) {
        var x = (browserUtility.getBrowser() == "ie") ? (event.x - 40) : e.pageX;
        var y = (browserUtility.getBrowser() == "ie") ? (event.y + document.body.scrollTop): e.pageY; 
       if (tipInitX == undefined) {
            tipInitX = x;
            tipInitY = y;
       } else {
            tipCurX = x;
            tipCurY = y;
            
            
            var tipObjX =  tipObjCur.style.width;
            tipObjX = parseInt(tipObjX.replace("px",""));
            
            var tipObjCurSrcElementX  = tipObjCurSrcElement.style.width;
            tipObjCurSrcElementX = parseInt(tipObjCurSrcElementX.replace("px",""));
            //tipObjX += tipObjCurSrcElementX;
            
           var tipObjY =  tipObjCur.style.height;
            tipObjY = parseInt(tipObjY.replace("px",""));
            
            
            var outOfBoundsX = (tipCurX > (tipInitX + tipObjX + 5) || tipCurX < (tipInitX - 5)) ? true : false;
            var outOfBoundsY = (tipCurY > (tipInitY + tipObjY + 5) || tipCurY < (tipInitY - 5)) ? true : false;
            
            //window.status = " current: " + x + " bounds:  " + (tipInitX - 5) + " to " + (tipInitX + tipObjX + 5);
            
            if ((outOfBoundsX || outOfBoundsY) && tipFadeLast != "out") tipMouseOut(tipObjCur.id);
            if (!outOfBoundsX && !outOfBoundsY && tipFadeLast != "in") tipMouseOn(tipObjCur.id);
            
       }
     }   
  
    function tipMouseOut (id) {
        tipFadeLast = "out"; 
        clearFade();
        tipFade(id,true,250,250);
      }    
     
      function tipMouseOn (id) {
       tipFadeLast = "in"; 
       clearFade();
       tipFade(id,false,10,50);
     }   
     
     function tipFade(id,boolForward, fadeWait, fadeInterval) {
         var colorArray = (boolForward) ? tipFadeColors.split(",") : tipFadeColors.split(",").reverse();   
         var display = (boolForward) ? "none": "block";
         var setMouseHandler = (boolForward) ? "validation2.cancelMouseMoveHandler()" : "validation2.setMouseMoveHandler()"; 
         
          for (i=0;i<colorArray.length;i++) {
               tipFadeTimeout[i] = window.setTimeout("document.getElementById('" + id + "').style.backgroundColor = '" + colorArray[i] + "';",fadeWait);
               fadeWait += fadeInterval; 
          }
          tipFadeTimeout[i+1] = window.setTimeout("document.getElementById('" + id + "').style.display = '" + display + "';eval(" + setMouseHandler + ");",fadeWait +fadeInterval);
     }
     
     function clearFade() {
        for (i=0;i<tipFadeTimeout.length;i++) {
            if (tipFadeTimeout[i] != "") window.clearTimeout(tipFadeTimeout[i]);
        } 
     }
   
    function hideTip(obj) {
        var tip = document.getElementById(obj.id + "_tip2"); 
        if (tip != undefined) tip.style.display = 'none'; 
    }      
   
         
}