
//////////////////////////////////////////////////////////////////////	
/**********************************************************************
* USED IN SEVERAL FILES
**********************************************************************/	
function detailWindow(url, w, h) {
	var leftPoint = (top.screen.width - w) / 2;
	var topPoint = (top.screen.height - h) / 2;

	winDetails = window.open(url, 'detail', 'toolbar=no,location=no,directories=no,status=no,menubar=0,scrollbars=yes,left=' + leftPoint + ',top=' + topPoint + ',resizable=yes,width=' + w + ',height=' + h + '')
	if (winDetails != null)
	{
		if (winDetails.opener == null)
			winDetails.opener = self;
		else
			try {winDetails.focus();} catch (e) {};//try/catch added by OB, probs with opening PDF in pop up
	}
}



function formatPhoneNumber(txt, e)
{
	var validChars = "0123456789";
	var str = txt.value;
	var len = str.length;			
	var aChar = str.charAt(len-1);
	var keyCode;
	
	if (document.all)
		keyCode = event.keyCode;
	else
		keyCode = e.which;
	
	if (keyCode == 8)
		return;
	
	
	if (validChars.indexOf(aChar) != -1)
	{
		if ((len == 3) || (len == 7))
			txt.value = str + "-";
	}
	else
		txt.value = str.substr(0, len-1);

	
	txt.focus();		
}




function formatNumberInput(txt, e)
{
	var validChars = "0123456789";
	var str = txt.value;
	var len = str.length;			
	var aChar = str.charAt(len-1);
	var keyCode;
	
	if (document.all)
		keyCode = event.keyCode;
	else
		keyCode = e.which;
	
	if (keyCode == 8)
		return;
	
	
	if (validChars.indexOf(aChar) == -1)
		txt.value = str.substr(0, len-1);

	
	txt.focus();		
}



function formatDateOfBirth(txt, e)
{
	var validChars = "0123456789";
	var str = txt.value;
	var len = str.length;			
	var aChar = str.charAt(len-1);
	var keyCode;
	
	if (document.all)
		keyCode = event.keyCode;
	else
		keyCode = e.which;
	
	if (keyCode == 8)
		return;
	
	if (len > 10)
		txt.value = str.substr(0, len-1);
	else
	{
	
		if (validChars.indexOf(aChar) != -1)
		{
			if ((len == 2) || (len == 5))
				txt.value = str + "/";
		}
		else
			txt.value = str.substr(0, len-1);
		}
		
	

	
	txt.focus();		
}





function changeFocus(field1, field2, len) {
   	if (field1.value.length == len) {
       	field2.focus();
        field2.select();
   	    return false;
	}
   	return true;
}	


/*
Submit Once form validation- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

function submitonce(theform){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i]
			
//			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
			if(tempobj.type.toLowerCase()=="submit")
				//disable em
				tempobj.disabled=true
		}
	}
}




function submitonce_img(theform, theElem){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++){
			var tempobj=theform.elements[i]
			
			if(tempobj.type.toLowerCase()=="img" && tempobj.name == theElem)
				//disable em
				tempobj.disabled=true
		}
	}
}

//trims the leading & ending white spaces of a text
function trim( val )
{   
    // return if string is empty
    if ( null == val || val.length < 1) return val;

    var value = val;
    while (value.charAt(value.length-1) == " "){value = value.substring(0,value.length-1);}
    while(value.substring(0,1) ==" "){value = value.substring(1,value.length);}

    return value;
}   //end of function trim(val)


/**
 * author: sherwin
 * function to write text value of 
 * select box to a textbox or hidden field. 
 * parameters: select box object, id of object to be written to.
*/
function captureSelectedText(selectBox, obj)
{
    //alert(selectBox);
    if (null == selectBox || selectBox == "undefined" || null == obj || obj == "undefined")
    {
        //do nothing
    }
    else
    {
        obj.value = selectBox.options[selectBox.selectedIndex].text;
    }
}// end of function captureSelectedText
    
/**
* author: sherwin
* this function toggles a html element display
* @param String -- elementId
*/
function toggleElementDisplay(elementId)
{
    var element = document.getElementById(elementId);
    element.style.display = (element.style.display == "block") ? "none" : "block";
}
    
/**
* author: sherwin
* this function toggles a html element display
* @param String -- elementId
*/
function toggleElementDisplayInline(elementId)
{
    var element = document.getElementById(elementId);
    element.style.display = (element.style.display == "inline") ? "none" : "inline";
}

/***
* called by onmouseover/onmouseout event on table product list rows
* to highlight row
* @param String -- row_id
* @param String -- mode (over/out)
*/
function highlightRow(rowId, mode)
{
    if (document.getElementById(rowId) != null)
    {
        var row = document.getElementById(rowId);
        var cells = row.getElementsByTagName("td");
        
        for(i = 0; i < cells.length; i++ )
        {
            if (mode == "over")
            {            
                cells[i].style.backgroundColor = "#cfffe8";
            }
            else
            {
                cells[i].style.backgroundColor = "";
            }
        }
    }
}//end of highlightRow

/***
* called by onmouseover/onmouseout event
* to highlight two rows
* @param String -- row_id
* @param String -- mode (over/out)
*/
function highlightTwoRows(rowId, mode)
{
    if (document.getElementById(rowId) != null)
    {
        var row1 = document.getElementById(rowId);
        var row2 = document.getElementById(rowId + "_2");
        var cells1 = row1.getElementsByTagName("td");
        var cells2 = row2.getElementsByTagName("td");
        
        for(i = 0; i < cells1.length; i++ )
        {
            if (mode == "over")
            {            
                cells1[i].style.backgroundColor = "#cfffe8";
            }
            else
            {
                cells1[i].style.backgroundColor = "";
            }
        }
        for(i = 0; i < cells2.length; i++ )
        {
            if (mode == "over")
            {            
                cells2[i].style.backgroundColor = "#cfffe8";
            }
            else
            {
                cells2[i].style.backgroundColor = "";
            }
        }
    }
}//end of highlightTwoRow

/*
changes the focus to the next text for postal_code entry
@param current textbox, next textbox id
*/
function change_pc_txtbox_focus(txtbox, next_txtbox)
{
    var regex = /^[a-zA-Z]\d{1}[a-zA-Z]$/;
    if (regex.test(txtbox.value))
    {
        document.getElementById(next_txtbox).focus();
    }
}//end of register_change_pc_txtbox_focus

/*
changes the focus to the next text for phone/fax number entry
@param current textbox, next textbox id
*/
function change_phone_txtbox_focus(txtbox, next_txtbox)
{
    var regex = /^\d{3}$/;
    if (regex.test(txtbox.value))
    {
        document.getElementById(next_txtbox).focus();
    }    
}//end of register_change_phone_txtbox_focus
//////////////////////////////////////////////////////////////////////




//this function changes an image src
//@param image
//@param string -- src
function changeImageSrc(image, src)
{
    image.src = src;
}


/*
author: sherwin
good: 10.2, 10.20, .02

*/
function isNumeric(val)
{
    if (trim(val) != "")
    {
        var regex = /^\d{1,}(\.\d{2})?$/;
        if (regex.test(val))
        {
            return true;
        }
        else    
        {
            return false;
        }
    }
    else    
    {
        return false;
    }
}

/*
author: sherwin
good: 10
bad: 10.00, 10., 10.1
*/
function isNumber(val)
{
    if (trim(val) != "")
    {
        var regex = /^\d{1,}$/;
        if (regex.test(val))
        {
            return true;
        }
        else    
        {
            return false;
        }
    }
    else    
    {
        return false;
    }

}

function openBargain() 
	{
	var myHeight = 300;
	var myWidth = 350;
	
	var myLeft = (top.screen.width - myHeight) / 2;
	var myRight = (top.screen.Height - myWidth) / 2;
	window.open('https://builder.campaigner.com/app/campaigner/services/optinlist/processoptinrequest.jsp?oilb=88542456&builderType=paid', 'Bargain', 'height='+myHeight+',width='+myWidth+', left='+myLeft+', top='+myRight+'');
	
}


