/*

Written By :	Matt Murillo 
Date:			12/21/2005

*/


function overlay(curobj, subobj){


	if(!checkCompare(curobj)){

		if (document.getElementById){
			var subobj=document.getElementById(subobj)
			subobj.style.color = "orange";
			subobj.innerHTML = "Choose one or more items to compare products";
			if(curobj.checked){
				curobj.checked = true;
			}
			else{
					curobj.checked = false;
					subobj.style.color = "red";
					subobj.innerHTML = "Check to compare product";
				}
		}
		
	}else{
		//Check the values of the selected Group
		SelectedGroup(curobj,subobj);
	}
}

function SelectedGroup(curobj,subobj){

	intCounter=0;
	for( z = 0; z < document.frmCompare.checkGroup.length; z++){
				if(document.frmCompare.checkGroup[z].checked == true){
					intCounter++;
				
					var divDoc = document.getElementById("subcontent" + (z + 1) );
					divDoc.style.color = "green";
					divDoc.innerHTML = "<strong class='compareGroup'><a href='javascript:OpenDiv(\"subcontent" +  (z + 1) + "\");'>Compare Now!</a></strong>";
				
				}else{
				
					var divDoc = document.getElementById("subcontent" + (z + 1) );
					divDoc.style.color = "red";
					divDoc.innerHTML = "Check to compare product";
				}
			}
	if(intCounter >5)
	{
		var subobj=document.getElementById(subobj)
		alert("You may only compare up to 5 products!  Please uncheck another product in order to check this one.");
		curobj.checked = false;
		subobj.style.color = "red";
		subobj.innerHTML = "Check to compare product";
	}
}

//Check to see if there are other checkGroup checked
function checkCompare(){

			
	var intCounter = 0;
	//Loop thru the checkGroup

	for( i = 0; i < document.frmCompare.checkGroup.length; i++){
		if(document.frmCompare.checkGroup[i].checked == true){
			intCounter++;
		}
	}
	
	//If it's the only thing checked out there this do this.
	if(intCounter == 1){
		for( x = 0; x < document.frmCompare.checkGroup.length; x++){
			if(document.frmCompare.checkGroup[x].checked == true){
				var divDoc = document.getElementById("subcontent" + (x + 1) );
					divDoc.style.color = "orange";
					divDoc.innerHTML = "Choose one or more items to compare products";
			}
		}
	}
	
	
	if( intCounter > 1)
		return true;	
	else
		return false;
}

/*
function getposOffset(overlay, offsettype){
		var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
		var parentEl=overlay.offsetParent;
		while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
*/
function OpenDiv(strDoc){
	
	var pids = '';
	var befid = '';
	
	befdoc = document.getElementById('BEFID');
	befid =  befdoc.innerHTML;
	
	
	for( z = 0; z < document.frmCompare.checkGroup.length; z++){
		if(document.frmCompare.checkGroup[z].checked == true){
			pids += document.frmCompare.checkGroup[z].value + '-';
		}
	}
	
	
/*	
	overLayDoc = document.getElementById('overLay');
	overLayDoc.style.display = 'block';
	overLayDoc.style.left = "50px"
	overLayDoc.style.top = "100px"
*/
//	ajaxGetCompare("http://" + window.location.hostname + "/sdcControls/ProductCompareAjax/ProductCompareAjax.aspx?pid=" + pids + '&befid='+ befid);
//window.open("http://" + window.location.hostname + "/sdcControls/ProductCompareAjax/ProductCompareAjax.aspx?pid=" + pids + '&befid='+ befid,'CompareProduct',
//'toolbar=0,resizable=0,scrollbars=1,status=0,width=700,height=500');
document.location="/ProductComparecrx.aspx?pid=" + pids + '&befid='+ befid;
}

function closeDiv(){
	LayDoc = document.getElementById('overLay');
	LayDoc.style.display = 'none';
}


var rootdomain="http://"+window.location.hostname

function ajaxGetCompare(url) {
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
	try {
	page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){
	try{
	page_request = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch (e){}
	}
	}
	else
	return false
	page_request.open('GET', url, false) //get page synchronously 
	page_request.send(null)
	
	overLayDoc = document.getElementById('overLay');
	overLayDoc.innerHTML = page_request.responseText;

}

function Search(obj){
	
	
	if(obj.value != '' || obj.value != null){
		document.location.href = rootdomain + '/befid-72/keyword-' + obj.value + '/searchvrx.aspx';
		return;
	}
}


//Counting Text Box Characters
function MaxLength(name, max)
{
	var doc = document.getElementById(name);
	
	if (doc.value.length > max-2)
	{
		alert("Please note, you have exceeded the maximum length.");
		return;
	}
}

function txtCount(field, countfield, maxlimit) 
{ 
	var txtFiledDoc = document.getElementById(field);
	var txtcountFieldDoc = document.getElementById(countfield);
	
	if (txtFiledDoc.value.length > maxlimit)
		txtFiledDoc.value = txtFiledDoc.value.substring(0, maxlimit); 
	else
		txtcountFieldDoc.value = maxlimit - txtFiledDoc.value.length; 
}

function validateform(){
	
	var theForm = document.PostReviewForm;
	var SummaryDoc = document.getElementById('Summary');
	var overallDoc = document.getElementById('overall');
	var valueDoc = document.getElementById('value');
	
	if(SummaryDoc.value.length < 15){
		alert('Please Enter a Summary');
		return;
	}
	else if(overallDoc.selectedIndex == 0){
		alert("Please Select a Overall Rating.");
		return;
	}else if(valueDoc.selectedIndex == 0){
		alert("Please Select a Value Rating.");
		return;
	}else{
		theForm.action =  "/PRVcrx.aspx"
        theForm.method = "post"; // default in main page
        theForm.submit();
	}
	
}


//Sort Reviews By - productreviewsvrx.aspx
function sortReviews(obj){
	document.location.href = obj.value;
}

/* vvv SDC Product List Page vvvv*/function SDC_GoPage(){
                var strhost = window.location.host;
                var pattern = /gotopage/g;

                return {
                    validate : function(pagevars,textobj, iMaxValue){

                        //Check if a number is entered
                        if(parseInt(textobj.value)){
                        
                            var pageValueEntered = parseInt(textobj.value);

                            //Check for page max
                            if(pageValueEntered > iMaxValue || pageValueEntered < 0){
                              alert('Enter a number less than ' + iMaxValue +' and greater than zero.');
                            }else{
                              this.gotopage(pagevars, pageValueEntered)
                            }

                        }else{
                            alert('Please Enter a Number.test');
                        }
                   
                    },
                    
                    gotopage : function(pagevars,pageValueEntered){
                       var strURL = window.location.host + '' + pagevars;
                      window.location.href =  'http://' + strURL.replace(pattern, pageValueEntered);
                    }
                }
                
              };

/*^^^ SDC Product List Page ^^^*/
