﻿    // JScript File

    // comp#5, EmpID=19, 27Nov06. 
    document.onclick=ProcessOnClick;
    document.onkeydown=ProcessControlOnKeyDown;
    
    //---------------------------------------------------------------------------------------------	
	function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
		//-->

		
    //---------------------------------------------------------------------------------------------
    
	// Allows form-submission only if input is valid - onclick
	// function document.onclick()
	// comp#5, EmpID=19, 27Nov06
	function ProcessOnClick(e)
	{
		// Comp#66, Emp#5, 01Dec06 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	    
        StartFormSubmission();	
	    
	    var objEvent = e ? e : window.event; 
	    var objEventSource = e ? e.target : window.event.srcElement;        
	        
	    if(objEventSource.id == "RightBarCtrl1_ibtnGo")
	    {			
		    if(! ValidateCategoryPhrase())	
		    {
		        StopFormSubmission();		
		        return;
	        }
	    }
	    if(objEventSource.id == "HCtrl1_ibtnLogin")
	    {
		        StopFormSubmission();	
		        return;
        }
			
	    if(objEventSource.id == "HCtrl1_img_btnHome")
	    {
		    if(document.URLUnencoded.indexOf('Default.aspx')>-1)
		    {
		        StopFormSubmission();	
		        return;
	        }
	    }			
	    
	    if(objEventSource.id == "RightBarCtrl1_ibtnSearch")
		{
		    if(!ValidateInput('RightBarCtrl1_txtCardName', objEventSource))
		    {
		        StopFormSubmission();	
		        return;
	        }		        
	    }	
	    
	    // Comp#66, Emp#5, 01Dec06 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	}
	
	    
    //---------------------------------------------------------------------------------------------
    
    // Comp#66, Emp#5, 01Dec06.
    // Helps to add eventListner useful to Start/Stop Form-Submission, etc.
    function addEvent(obj, evType, fn)
    {
        if (obj.addEventListener)
        {
            obj.addEventListener(evType, fn, false);
            return true;
        }
        else if (obj.attachEvent)
        {
            var r = obj.attachEvent("on"+evType, fn);
            return r;
        }
        else
        {
            return false;
        }
    }
    
    
    //---------------------------------------------------------------------------------------------
    
    // Comp#66, Emp#5, 01Dec06.
    // Prevents Form-Submission. Required if wrong input.
    function cancel(e)
    {
        if (e && e.preventDefault)
            e.preventDefault(); // DOM style
        return false; // IE style  
    }

	//---------------------------------------------------------------------------------------------
	

	//----------------------------------------------------------------------------------------------
	//Allows form-submission only if input is valid -onKeyUp
	//function document.onkeydown()
	
	function ProcessControlOnKeyDown(e)
	{		
    	var objEvent = 0; 
    	var objSourceElement;
	    if(window.event)
	    {
	        // IE.
	        objEvent = window.event;	    
	        objSourceElement = objEvent.srcElement;
	     }
	    else
		{
		    // FireFox.
		    objEvent = e;		
		    objSourceElement = objEvent.target;    
		}
		
		//Validate only when 'return/enter' button is used
		if( objEvent.keyCode == 13 )
		{
			if(objSourceElement.id == "RightBarCtrl1_txtCardName")
			{				
				document.getElementById('RightBarCtrl1_ibtnSearch').click();
			}
			
			objEvent.returnValue=false; 
			objEvent.cancel = true;
		}
	}
	
	//---------------------------------------------------------------------------------------------
	
	
	//---------------------------------------------------------------------------------------------
		// allows to go, to card gallery page if category and phrase selected
		function ValidateCategoryPhrase()
		{
			var category = (document.getElementById('RightBarCtrl1_ddlQuickSearch')).selectedIndex;
			var phrase = (document.getElementById('RightBarCtrl1_ddlThemes')).selectedIndex;
			if(category == 0 || phrase == 0)
			{
				alert('Please select both category and sub-category.');
				return false;
			}
			else 
				return true;
		}
		
	//---------------------------------------------------------------------------------------------

	//Validates Card Sku no.
	function ValidateInput(txtElement, objEventSource)
	{		    	    		
		var val = trim(document.getElementById(txtElement).value);
		
		if(objEventSource.id == "RightBarCtrl1_ibtnSearch")
		{	
		    //Search button is clicked. Validate Card Sku no.
			
			document.getElementById(txtElement).value = trim(document.getElementById(txtElement).value);
						
			var strElementVal = new String();
			strElementVal = trim(document.getElementById(txtElement).value);			
			
			//Check whether given element's value is not emty--------------------------------------
			if( strElementVal == "" )
			{
				alert("Please enter the card SKU number, Keywords, etc.");
				document.getElementById(txtElement).value = "";
				document.getElementById(txtElement).focus();
				return false;
			}
			//-------------------------------------------------------------------------------------				
		}		
		
		// Comp#66, Emp#5, 28Sep06. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		
		// RightBarCtrl1_txtCardName should contain nos. & letters.
		var iOption = 3;
		
		var bSkuValid = CheckChars("RightBarCtrl1_txtCardName", iOption);		
		
		if(!bSkuValid)
		{
			alert("Please enter valid SKU Number or Keyword for searching card(s).");
			document.getElementById(txtElement).value = "";
			document.getElementById(txtElement).focus();
			return false;
		}
		
		// Comp#66, Emp#5, 28Sep06. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
			
		return true;
	}
			
	//---------------------------------------------------------------------------------------------
	
	//---------------------------------------------------------------------------------------------
	//Redirect user to MapQuest to see the Store using map
	function MapIt()
	{		
		var url = "http://www.mapquest.com/maps/map.adp?" +					
					"&address=315 West 33rd Street Apartment 11 A" +
					"&zip=10001" +
					"&country=United States" +
					"&zoom=5";
					
		window.open(url);
	}
	
	//---------------------------------------------------------------------------------------------
	
	// Comp#66, Emp#5, 28Sep06.
    // Returns true if the given element's value for the given option 
	// (nos., chars, nos. & chars).
	function CheckChars(txtElement, iOption)
	{
		var strElementVal   = new String();			
		strElementVal       = document.getElementById(txtElement).value;		
		
		// Set default value.
		var regExp          = /[^a-z\d ]/i;
			
		switch(iOption)
		{
		    case 1:
		        // regular expresion to accept only chars
		        regExp = /[^\d]/;
		        break;
		    case 2:
		        // regular expresion to accept only chars
		        regExp = /[^a-z ]/i;		
		        break;
		    case 3:
		        // regular expresion to accept only chars, Nuimbers & some special chars.
		        regExp = /[^a-z\d-()'.#,& /]/i;		
		        break;
		    default:
		        // regular expresion to accept only Nuimbers & chars
		        regExp = /[^a-z\d ]/i;
		        break;
		}
						
		var isValid = !(regExp.test(strElementVal));				
		
		return isValid;
	}
	
   //--------------------------------------------------------------------------------------------- 
   function SetZoom()
   {
    var viewportwidth;
    var viewportheight;
    
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined')
    {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement !=
    'undefined'&& typeof document.documentElement.clientWidth !=
    'undefined' && document.documentElement.clientWidth != 0)
    {
    viewportwidth = document.documentElement.clientWidth,
    viewportheight = document.documentElement.clientHeight
    }
    // older versions of IE
    else
    {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
    viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    //alert('Your viewport width is '+viewportwidth+'x'+viewportheight);    
        var x = screen.width;
        var y = screen.height;        
        parent.parent.document.body.style.zoom = screen.height/700;
        //var zoomPts = viewportwidth/1024;
        //increaseFontSize();
   }   
   //--------------------------------------------------------------------------------------------- 
