﻿var objCore = new JS_Core();

var Prem = {
		Browser: {
		IE:     (window.attachEvent && !window.opera),
		Opera:  window.opera,
		WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
		Firefox:navigator.userAgent.indexOf('Firefox') > 0 ,
		Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
	  }
}


function JS_Core(){} // Create class

JS_Core.prototype.clearElement = function(objElement) // Clear the contents of an HTML element.
{
// This method would be redundant if IE supported prototyping on the HTMLElement object.
    if(objElement)
    {
        while(objElement.firstChild)
        {
        objElement.removeChild(objElement.firstChild);
        }
    }
}

JS_Core.prototype.loadScript = function(strSource)
{

     var objElem = document.createElement("script");
	 objElem.setAttribute("src",strSource);
	 objElem.setAttribute("type","text/javascript");
	 var objHead = document.getElementsByTagName("head")[0]
	 objHead.insertBefore(objElem,objHead.firstChild);
}

window.$ = function(id)
{
    return document.getElementById(id);
}


JS_Core.prototype.messageBox = function(strTitle,strMessage,objContainer,strType,strExtendSearch)
{
// strTitle = title bar text for box
// strMessage = the message to display
// objContainer = the place where the message box is created
// strType = type of message being displayted (warning, message, error);

    var box = document.createElement('div');
    var tr = document.createElement('div');
    var bordR = document.createElement('div');
    var box2 = document.createElement('div');
    var br = document.createElement('div');
    var generic = document.createElement('div');
    var generic2 = document.createElement('div');

	var imgBox = document.createElement('div');
    var txt1Box = document.createElement('div');
    var txt2Box = document.createElement('div');
  
  	var imgYesNoBox = document.createElement('div');
    var imgYesBox = document.createElement('div');
    var imgNoBox = document.createElement('div');
	

    
    var objTitle; 
	
	if(Prem.Browser.IE)
	{
		objTitle = document.createElement('h2');
		objTitle.className = 'msgBoxTitle_IE';
	}
	else
	{
		objTitle = document.createElement('h2');
		objTitle.setAttribute("class","msgBoxTitle_NONIE"); 
	}
	
    
    
    objTitle.appendChild(document.createTextNode(strTitle));
    
    var imgClose = new Image();  
    imgClose.src = 'images/msgBox/btn-x.png';
    imgClose.alt = 'Close message box';
    imgClose.title = 'Close message box';
    imgClose.id = 'msgBoxCloser';

	var imgYes = new Image();  
    imgYes.src = 'images/msgBox/yes.gif';


	var imgNo = new Image();  
    imgNo.src = 'images/msgBox/no.gif';
	
    
    var imgType = new Image()
    
    imgType.className = 'typeImage';
    switch(strType)
    {
        case "message":
            imgType.src = 'images/msgbox/icon-warning.png'
        break
        
        case "error":
            imgType.src = ''
        break
        
        case "warning":
            imgType.src = ''
        break
    }
    
	
	
	if(Prem.Browser.IE)
	{
	imgYesNoBox.className= "imgyesnobox";  
	imgYes.className="imgyesbox";  
	imgNo.className="imgnobox";  
	txt1Box.className="txt1box";  
	txt2Box.className="txt2box";  
	}
	else
	{
	imgYesNoBox.setAttribute("class","imgyesnobox");  
	imgYes.setAttribute("class","imgyesbox");  
	imgNo.setAttribute("class","imgnobox");  
	txt1Box.setAttribute("class","txt1box");  
	txt2Box.setAttribute("class","txt2box");  
	}
	
	imgYesNoBox.setAttribute("align","center");  
	txt1Box.setAttribute("align","center");  
	txt2Box.setAttribute("align","center");  
	box2.setAttribute("align","center");  

    imgClose.onclick = function(){objContainer.removeChild(box);}
    imgNo.onclick = function(){location.href = "/";}

	imgYes.onclick = function()
	{
		
			var strLocation;
			var strLandmark ;
//			alert($('chkstation').checked)
			if($('chkstation').checked)
			{
 			    strLandmark = $('landmarktxt').value + " station";
				if(strLandmark.indexOf('Landmark or Station')>0)
				{
					strLandmark = '';
				}
			}
			else
			{
				
				strLandmark = $('landmarktxt').value
				if(strLandmark.indexOf('Landmark or Station') > 0)
				{
					strLandmark = '';
				}
		    }
			//alert(strLandmark);
			if (strLandmark!="")
			{
				var strCountry = $('ddlCountry').options[$('ddlCountry').selectedIndex].value;
				var intDist;
				intDist = $('ddlRadius').options[$('ddlRadius').selectedIndex].value;
				
				if((intDist==1)||(intDist==2)(intDist==5))
				{
					intDist = 10;
					//alert('inside the dist ')
				}

				if (strCountry!=0)
				{
					strLocation = strLandmark +','+strCountry;
				}
				else
				{
					strLocation = strLandmark;
				}
				map.findStores(strLocation,strCountry,intDist,17);return false;
			}
		
	}
      
	  
	  
    box.className = "box";
    box.id = "messageBox";
    tr.className = "tr";
    bordR.className = "bordR";
    box2.className = "box2"
    br.className = "br"
    

	imgBox.appendChild(imgType)
	txt1Box.appendChild(document.createTextNode(strMessage))
	txt2Box.appendChild(document.createTextNode(strExtendSearch))

	//imgYesBox.appendChild(imgYes)
	//imgNoBox.appendChild(imgNo)
	
	imgYesNoBox.appendChild(imgYes)
	imgYesNoBox.appendChild(imgNo)


	box2.appendChild(imgBox)
	box2.appendChild(txt1Box)
	box2.appendChild(txt2Box)
	box2.appendChild(imgYesNoBox)



//	box2.appendChild(imgType);
//    box2.appendChild(document.createTextNode(strMessage));
    
    tr.appendChild(generic);
    br.appendChild(generic2);
    
    bordR.appendChild(box2);
    
    box.appendChild(imgClose);
    box.appendChild(objTitle);
    box.appendChild(tr);
    box.appendChild(bordR);
    box.appendChild(br);
     
   
    objContainer.appendChild(box);  
    
    var msgBox = document.getElementById('messageBox');  
    
    var intBoxWidth = msgBox.offsetWidth;
    var intBoxHeight = msgBox.offsetHeight;
    
    msgBox.style.marginLeft = -(intBoxWidth/2) + "px";
    msgBox.style.marginTop = -(intBoxHeight/2) + "px";
}

// Extend object object

/*HTMLElement.prototype.clear = function()
{
if(this)
{
    while(this.firstChild)
    {
        this.removeChild(this.firstChild);
    }
}
}*/



