
/* This script will open and close the popup window */
/* This script will open and close the popup window */
function open_requestquote_popup(productID, e, title)
{

	var popup = "request_quote_price_control";	
		
	var posx = 0;
	var posy = 0;

	if (!e) var e = window.event;

	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	if(e.posx == 0)
		posx = event.pageX;

	document.getElementById(popup).style.top= posy +"px";
	document.getElementById(popup).style.left= posx +"px";
	document.getElementById(popup).style.display='block';

	if(title != undefined)
	{
	    document.getElementById('ctl00_requestAQuoteSection_reqTitle').innerHTML  = title;
	}  

	if(document.getElementById('ctl00_requestAQuoteSection_reqTitle').innerHTML=='')
	{
		document.getElementById('ctl00_requestAQuoteSection_reqTitle').innerHTML  = "Request a Price Quote";
	} 

	document.getElementById('ctl00_requestAQuoteSection_prdID').value = productID;
}

function open_popup(pop_id)
{
	var popup = pop_id;	
	if(popup != "flexInner" && popup != "productlist")
	{
		lastPopUp = popup;
	}
	document.getElementById(popup).style.display='block';
}

function close_popup(pop_id)
{

	var popup = pop_id;
	document.getElementById(popup).style.display='none';

}

function openSpecXY(pop_id,posX,posY)
{
	var popup = pop_id;
	document.getElementById(popup).style.left = posX+'px';
	document.getElementById(popup).style.top = posY+'px';
	document.getElementById(popup).style.display='block';
}

function showhide(id)
{ 
	if (document.getElementById)
	{ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none")
		{ 
		obj.style.display = ""; 
		
		} 
		else 
		{ 
		obj.style.display = "none"; 
		 
		} 
	} 
}

function clear(whichPop)
{       
    var ControlArray;
    var CheckboxArray;
    var Control;
    if(whichPop == "pop1")
    {
        ControlArray = ArrayPop1Controls;
        document.getElementById(ControlArray[0]).focus();
    }
    else if (whichPop == "pop2")
    {
        ControlArray = ArrayPop2Controls;
        document.getElementById(ControlArray[0]).focus();
        CheckboxArray = ArrayPop2CheckboxControls;
        for(var i=0; i<CheckboxArray.length; i++)
        {
            document.getElementById(CheckboxArray[i]).checked = false;            
        }            
    }
    
    for(var i=0;i<ControlArray.length;i++)    
    {
        Control = document.getElementById(ControlArray[i])
        if(Control.type == 'select-one')
            Control.selectedIndex = 0;
        else
            Control.value = '';
    }
    
}

function validatePop1()
{    
    //this is builtin variable
    __defaultFired=false;
    var pass = true;
    var ControlArray;    
    ControlArray = ArrayPop1Controls;
    for(var i=0;i<ControlArray.length-3;i++)
    {       
        if(document.getElementById(ControlArray[i]).value.trim() == '')
        {
            pass=false;
            document.getElementById(ControlArray[i]).focus();
            break;          
        }                
    }
    
    if (!pass)
        alert('One or more required fields are not completed. Please complete them and try again');
    else
    {
        var id = ControlArray[5];
        pass = checkZip(document.getElementById(id).value.trim())
        if (!pass)
        {
            alert('Please provide valid zip code');
            document.getElementById(id).focus();
        }        
        else 
        {
            id = ControlArray[6];
            pass = checkEmail(document.getElementById(id).value.trim())
            if (!pass)
            {
                alert('Please provide valid email address');
                document.getElementById(id).focus();
            }
            else
            {
                id = ControlArray[7];
                pass = checkPhone(document.getElementById(id).value.trim())
                if (!pass)
                {
                    alert('Please provide valid phone number');
                    document.getElementById(id).focus();
                }
                /*else
                {
                    id = ControlArray[8];
                    pass = checkPhone(document.getElementById(id).value.trim())
                    if (!pass)
                    {
                        alert('Please provide valid fax number');
                        document.getElementById(id).focus();
                    }
                    else
                    {
                        id = ControlArray[10];
                        pass = document.getElementById(id).value.trim().length > 500 ? false : true;
                        if (!pass)
                        {
                            alert('Comments/Questions should be less than 500 characters');
                            document.getElementById(id).focus();
                        }
                    }
                }*/
            }
        }
        
    }    
    return pass;
}

function validatePop2()
{
     //this is builtin variable
     __defaultFired=false;
    var pass = true;
    var ControlArray;
    var CheckboxArray;
    var Control;
    ControlArray = ArrayPop2Controls;
    CheckboxArray = ArrayPop2CheckboxControls;
    for(var i=0;i<ControlArray.length-1;i++)
    {   
        Control = document.getElementById(ControlArray[i]);
        if(Control.type == 'select-one' && Control.selectedIndex == 0)
        {
            pass=false;
            break;
        }
        else if(i!=3 && Control.value.trim() == '')
        {
            pass=false;
            document.getElementById(ControlArray[i]).focus();
            break;          
        }                
    }
    
    if (!pass)
        alert('One or more required fields are not completed. Please complete them and try again');
    else
    {
        pass = false;
        for(var i=0;i<CheckboxArray.length; i++)
        {
            Control = document.getElementById(CheckboxArray[i]);
            if(Control.checked)
                pass = true; 
        }
        if(!pass)
        {
           alert('Please choose atleast one product category'); 
        }
        else
        {
            id = ControlArray[6];
            pass = checkZip(document.getElementById(id).value.trim())
            if (!pass)
            {
                alert('Please provide valid zip code');
                document.getElementById(id).focus();
            }
            else
            {
                id = ControlArray[7];
                pass = checkEmail(document.getElementById(id).value.trim())
                if (!pass)
                {
                    alert('Please provide valid email address');
                    document.getElementById(id).focus();
                }
                else
                {
                    id = ControlArray[8];
                    pass = checkPhone(document.getElementById(id).value.trim())
                    if (!pass)
                    {
                        alert('Please provide valid phone number');
                        document.getElementById(id).focus();
                    }                    
                }
            } 
        }    
    }    
    return pass;
}

function checkEmail(strValue)
{   
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(strValue))
        return true;     
    return false;      
}

function checkPhone(strValue)
{
    var objRegEx1 = /^[/\(](\d{3})[/\)](\s{1})(\d{3})[/\-](\d{4})$/;
    var objRegEx2 = /^(\d{10})$/;
    var objRegEx3 = /^[/\(](\d{3})[/\)](\d{3})[/\-](\d{4})$/;
    var objRegEx4 = /^(\d{3})[/\-](\d{3})[/\-](\d{4})$/;
    if(objRegEx1.test(strValue) || objRegEx2.test(strValue) || objRegEx3.test(strValue) || objRegEx4.test(strValue))
        return true;        
    return false;
}

function checkZip(strValue)
{
    var objRegEx1 = /^(\d{5})$/;
    var objRegEx2 = /^(\d{9})$/;
    var objRegEx3 = /^(\d{5})[/\-](\d{4})$/;    
    
    if(objRegEx1.test(strValue) || objRegEx2.test(strValue) || objRegEx3.test(strValue))
        return true;        
    return false;    
}

function checkPostalCode(strValue)
{
    var objRegEx1 = /^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/;
    var objRegEx2 = /^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}[A-Z,1-9]{1}$/;
    
    
    if(objRegEx1.test(strValue) || objRegEx2.test(strValue))
        return true;        
    return false;    
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
 
/* Ecommerce relative popup start*/

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onclick = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var mousePosX = 0
var mousePosY = 0
var lastPopUp;
// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	try{
	  if (IE) { // grab the x-y pos.s if browser is IE
		mousePosX = event.clientX + getScrollXY()[0]
		mousePosY = event.clientY + getScrollXY()[1]
	  } else {  // grab the x-y pos.s if browser is NS
		mousePosX = e.pageX
		mousePosY = e.pageY
	  }  
	  // catch possible negative values in NS4
	  if (mousePosX < 0){mousePosX = 0}
	  if (mousePosY < 0){mousePosY = 0} 	  
	  
	}catch(e){		
	  
	}
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function open_popupRelative(popUpDivID,divApproxWidth, divApproxHeight,closeLastPopUp){
	//alert(getScrollXY()[1]);alert("open_popupRelative is" + popUpDivID);
	if(!divApproxWidth){
		divApproxWidth = 0;
	}
	if(!divApproxHeight){
		divApproxHeight = 0;
	}	
	if(closeLastPopUp){
		if(lastPopUp){
			//alert(lastPopUp);
			close_popup(lastPopUp);
		}
	}
	var popup = popUpDivID;	
	if(popup != "flexInner" && popup != "productlist")
	{
		lastPopUp = popup;
	}
	var divElement = document.getElementById(popup);
	divElement.style.left = mousePosX-divApproxWidth + 'px';
	divElement.style.top = mousePosY-divApproxHeight + 'px';
	//alert('x:'+mousePosX+'::y:'+mousePosY+'divX:'+divApproxWidth+'divY:'+divApproxHeight);
	divElement.style.display='block';
}
/* Ecommerce relative popup ends */
