
/*###################################################
# Name   : Common.js							    #	
# Date   : 01/24/07									#	
# Author : Jerry Sponseller							#
# Desc.  : Common javascript methods inlcude file	#
# Notes  : GEMCO Website project					#
###################################################*/

function WinPopup(StrUrl, StrTitle, IntWidth, IntHeight, BlnScrollBars)
{
 // Window popup with specified URL, Title, Width and Height
 var StrOptions; 
 
 StrOptions = "'toolbar=0,"; 
 StrOptions += "location=no,"; 
 StrOptions += "directories=0,";
 StrOptions += "status=0,";
 StrOptions += "resizable=0,";
 StrOptions += "top=200,";
 StrOptions += "left=355,";
 StrOptions += "copyhistory=0,";
  
 if (BlnScrollBars == 1)
   {
    StrOptions += "scrollbars=1,";
   }
  else
   {
    StrOptions += "scrollbars=0,";
   }
  
 StrOptions += "width=" + IntWidth + ","; 
 StrOptions += "height=" + IntHeight + "'";
  
 window.open(StrUrl, StrTitle, StrOptions);	 
 return;
}
function textClearAndNormal(Txt_Search)
  {
  alert("test");
    document.getElementById("ctl00_CPH_Body_" + Txt_Search).value="";document.getElementById("ctl00_CPH_Body_"+Txt_Search).style.fontStyle= "normal";
    return;
  }
    
    function browser_back()
    {
    // Browser Back Button
        window.history.forward(1); // this works for IE standalone

        window.onbeforeunload = confirmBrowseAway; //the code below was needed for firefox 2.x 
        function confirmBrowseAway()
        {
            if (!NonExistentVariable) 
            {
            return "";
            }
         }
    }
    
function ValidateFileName(StrFieldValue)
{
 // Validate the existance of the file name
 if (StrFieldValue.length == 0) 
   {
    return false;
   }
  else
   {
    return true;
   }
}

function ValidateMemberFields()
{
 //Cycle through the elements and check for values in text and password fields

 var Form;
 var IntCounter;
  
 Form = document.forms[0];
 for (IntCounter=0; IntCounter < Form.elements.length; IntCounter++)
 {
  //Validate the text entries
  if (Form.elements[IntCounter].type == "text" || Form.elements[IntCounter].type == "password")
    {
     if (Form.elements[IntCounter].name != "MInitial" && Form.elements[IntCounter].name != "Address2" && Form.elements[IntCounter].name != "EmailAddress") 
	   {	
		if (Form.elements[IntCounter].value.length == 0) 
		  {
           alert("Please enter the required information");       
           return;
          }
       }
    } 
  //Validate the dropdown selections
  if (Form.elements[IntCounter].type == "select-one")
    {
     if (Form.elements[IntCounter].value.length == 0) 
       {
        alert("Please enter the required information!");       
        return;
       }
    }
 }
 //Validate the password entries
 if (Form.Password.value.length < 4)
   {
	alert("The password must be at least four characters in length!");       
    return;
   }
 if (Form.Password.value != Form.Password2.value)
   {
    alert("The two passwords entered do not match... Please re-enter them!");       
    return;
   }
 Form.submit();
 return;
}

function ClearForm2()
{
 //Cycle through the elements and change the value of all text objects to ""

 var Form;
 var IntCounter;

 Form = document.forms[1];
 for (IntCounter=0; IntCounter < Form.elements.length; IntCounter++)
 {
  alert(Form.elements[IntCounter].name);
  Form.elements[IntCounter].value = ""; 
 } 
 return;
} 

function ValidateLoginFields()
{
 //Validate login fields

 var Form;
  
 Form = window.document.Frm_Login;
 if (Form.UserName.value.length == 0 || Form.Password.value.length == 0)
   {
    alert("Please enter a username and a password");       
    return;
   } 	
 Form.submit();
 return;
}

function WindowStatusMask(StrStatusMsg)
{
 //Mask the window status with the variable supplied.

 window.status = StrStatusMsg;
 return;
}

function ImageRollOver(StrObject, StrImgName)
{
//Image rollover with supplied image object and image name.
 switch (StrObject)
   {
    case 'Diabetes':
		DiabetesTab.src = StrImgName;
		break;
    case 'DME':
		DMETab.src = StrImgName;
		break;
    case 'More':
		MoreTab.src = StrImgName;
		break;
   case 'MemberSignup':
		MemberSignup.src = StrImgName;
		break;
   case 'Testimonials':
		document.getElementById("Testimonials").src = StrImgName;
		break;
   case 'MemberLogin':
		MemberLogin.src = StrImgName;
		break;	
   case 'Tabs':
		Tabs.src = StrImgName;
		break;	
   case 'AddToBasket1':
		AddToBasket1.src = StrImgName;
		break;	
   case 'Tabs_Home':
		document.getElementById("Tabs_Home").src = StrImgName;
		break;
   case 'Tabs_Dia':
		document.getElementById("Tabs_Dia").src = StrImgName;
		break;
   case 'Tabs_Dme':
		document.getElementById("Tabs_Dme").src = StrImgName;
		break;	
   case 'Tabs_Spec':
		document.getElementById("Tabs_Spec").src = StrImgName;
		break;			
   }
 return;
}

function ClearForm() 
{
 var Form;
 var IntCounter;

 Form = document.forms[1];
 
 for (var IntCounter=0;IntCounter<Form.elements.length;IntCounter++) 
    {
      if (Form.elements[IntCounter].type == "text" || Form.elements[IntCounter].type == "textarea" || Form.elements[IntCounter].type == "password")
        Form.elements[IntCounter].value = "";  
      else if (Form.elements[IntCounter].type == "select-one")
        Form.elements[IntCounter].selectedIndex = 0;
      else if (Form.elements[IntCounter].type == "checkbox")
        Form.elements[IntCounter].checked = false;
    }
 return;   
} 

function total_update()
{
var Form;
var Price;
//Get the Form
Form = document.forms[1];
//blank will add 1 to cart
if (Form.ctl00$CPH_Body$txt_Qty.value == "")
{
    Form.ctl00$CPH_Body$txt_Qty.value = 1;
}
//if the quantity is not empty 
if (Form.ctl00$CPH_Body$txt_Qty.value != "")
{
    //get arrays for price and quantity
    var priceary = Form.ctl00$CPH_Body$Hdn_Price_Ary.value.split(",");
    var quantary = Form.ctl00$CPH_Body$Hdn_Quant_Ary.value.split(",");
    Form.ctl00$CPH_Body$txt_Qty.value = parseInt(Form.ctl00$CPH_Body$txt_Qty.value);
    if (isNaN(Form.ctl00$CPH_Body$txt_Qty.value))
    {
        Form.ctl00$CPH_Body$txt_Qty.value = 0;
    }
    for (var i=0; i<priceary.length; i++) 
    {
    //alert(quantary[i] + ": " + priceary[i]);
        //If price is lower than current value then change it
        if (parseInt(Form.ctl00$CPH_Body$txt_Qty.value) >= parseInt(quantary[i]))
        {
            //change price value
            Price = priceary[i];
            document.getElementById("ctl00_CPH_Body_Lbl_Price").innerHTML = formatCurrency(Price);
        }
    }
    //Set Hdn_total = the value
    Form.ctl00$CPH_Body$hdn_Total.value = Form.ctl00$CPH_Body$txt_Qty.value * Price;
    Form.ctl00$CPH_Body$txt_Total.value = formatCurrency(Form.ctl00$CPH_Body$hdn_Total.value);

    if (Form.ctl00$CPH_Body$hdn_Total.value > 9999)
    {
        Form.ctl00$CPH_Body$txt_Total.style.width = 71;
    }
    else
    {
       Form.ctl00$CPH_Body$txt_Total.style.width = 60; 
    }
    alert("Item Added To Cart");
}
else
{
    Form.ctl00$CPH_Body$txt_Total.value = ""
}
return;
}

function total_update_search()
{
var Form;
var Price;
var i = 0;
//Get the Form
Form = document.forms[1];
//While item exist on the page update them
while (document.getElementById("ctl00_CPH_Body_txt_Qty_" + i))
{
//if the quantity is not empty 
if (document.getElementById("ctl00_CPH_Body_txt_Qty_" + i).value != "")
{
    //update total
    document.getElementById("ctl00_CPH_Body_txt_Total_" + i).value = formatCurrency(document.getElementById("ctl00_CPH_Body_txt_Qty_" + i).value * document.getElementById("ctl00_CPH_Body_Hdn_Price_" + i).value);
}
else
{
    document.getElementById("ctl00_CPH_Body_txt_Total_" + i).value = ""
}
i++;
}
return;
}


function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function ready_values(count)
{
//store the values to be added into items table
var Qty = document.getElementById("ctl00_CPH_Body_txt_Qty_" + count).value
var stockid = document.getElementById("ctl00_CPH_Body_Hdn_stock_id_" + count).value
//alert(stockid);
if (isNaN(Qty)|| Qty <= -1)
{
    alert("Please enter a valid number");
}
else
{
    //if add blanks to cart then you get at least 1 in the cart.
    if (Qty == "") {Qty = 1;}
    document.getElementById("ctl00_CPH_Body_hdn_addtocart").value = stockid + "," + Qty;
    document.getElementById("ctl00_CPH_Body_hdn_addtocart_bool").value = "True";
    alert("Item added to your cart");
}

return;
}
function ready_values_dropship(count)
{
//store the values to be added into items table
var Qty = document.getElementById("ctl00_CPH_Body_txt_Qty_" + count).value
var stockid = document.getElementById("ctl00_CPH_Body_Hdn_stock_id_" + count).value
var price = document.getElementById("ctl00_CPH_Body_Hdn_Price_" + count).value

//if (document.getElementById("ctl00_CPH_Body_hdn_item_count").value >= 5)
//{
//    alert("Quick Add Menu Full.\nPlease Return And Add These Items To Your Cart.\n");   
//}
//else
//{

//alert(stockid);
    if (Qty <= -1 || isNaN(Qty))
    {
    alert("Please enter a valid number");
    }
    else
    {
    //if add blanks to cart then you get at least 1 in the cart.
    if (Qty == "") {Qty = 1;}
    document.getElementById("ctl00_CPH_Body_hdn_addtocart").value = stockid + "," + Qty+","+price;
    document.getElementById("ctl00_CPH_Body_hdn_addtocart_bool").value = "True";
    alert("Item added to your Dropship Product Selection");
    }
//}
return;
}
function check_Java()
{
//alert(document.getElementById("ctl00_CPH_Body_hdn_Java_enabled").value);
document.getElementById("ctl00_CPH_Body_hdn_Java_enabled").value = "True";
//alert(document.getElementById("ctl00_CPH_Body_hdn_Java_enabled").value);

return;
}

function Registration_Check()
{
    var strerror = "";
    var passed = true;
    
    //Build Error String 
    //1.Check For Empty Fields
//    if (document.getElementById("ctl00_CPH_Body_txt_Firstname").value == "") 
//    {
//        strerror += "Please Enter A First Name\n";
//        passed = false;
//    }
//    if (document.getElementById("ctl00_CPH_Body_txt_LastName").value == "") 
//    {
//        strerror += "Please Enter A Last Name\n";
//        passed = false;
//    } 

//   if (document.getElementById("ctl00_CPH_Body_txt_company").value == "") 
//    {
//        strerror += "Please Enter A Company Name\n";
//        passed = false;
//    } 
//    if (document.getElementById("ctl00_CPH_Body_txt_address1").value == "") 
//    {
//        strerror += "Please Enter A Valid Address\n";
//        passed = false;
//    } 
//    if (document.getElementById("ctl00_CPH_Body_txt_city").value == "") 
//    {
//        strerror += "Please Enter A City\n";
//        passed = false;
//    }
//    if (document.getElementById("ctl00_CPH_Body_DDl_state").value == "") 
//    {
//        strerror += "Please Select A State\n";
//        passed = false;
//    }  
//    //Check Zip Length
//    if (document.getElementById("ctl00_CPH_Body_txt_zipcode").value.length < 5) 
//    {
//        strerror += "Please Enter A Valid Zipcode\n";
//        passed = false;
//    } 
//    
//    //Check OldCustnum
//    if (document.getElementById("ctl00_CPH_Body_txt_Sys_Num").value.length >= 1 && isNaN(document.getElementById("ctl00_CPH_Body_txt_Sys_Num").value))
//    {
//        strerror += "Please Enter A Valid System Customer Number\n"
//        passed = false;
//    } 

    
    //Check Email
    if (document.getElementById("ctl00_CPH_Body_txt_Email").value.length < 5 || document.getElementById("ctl00_CPH_Body_txt_Email").value.indexOf("@") < 0 || document.getElementById("ctl00_CPH_Body_txt_Email").value.indexOf(".") < 0) 
    {
        strerror += "Please Enter A Valid Email Address\n";
        passed = false;
    }
    //Check Password
//    var strongRegex = new RegExp("(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,10})$", "g");
//    var pwd = document.getElementById("ctl00_CPH_Body_txt_pass1").value;
//    var check = strongRegex.test(pwd);
//    if (false == check) 
//    {
//         strerror +="Password should not contain special characters\n";
//         strerror +="Password incorrect check Password Policy";
//         passed = false;
//    }
     var string = document.getElementById("ctl00_CPH_Body_txt_pass1").value
     var iChars = ".?!:;-(){}[],/!<>`\'@&$#%^'";
            
     for (var i = 0; i < string.length; i++) 
       {
         if (iChars.indexOf(string.charAt(i)) != -1)
         {
          strerror +="Password must not contain special characters\n";
          passed = false;
         }
       }
    if (document.getElementById("ctl00_CPH_Body_txt_pass1").value.length < 6)
    {
        strerror +="Password must be at least 6 Characters\n";
        passed = false;
    }
    if (!numeric_Check(document.getElementById("ctl00_CPH_Body_txt_pass1").value))
    {
        strerror +="Password must contain a number\n";
        passed = false;
    }
    if (!isNaN(document.getElementById("ctl00_CPH_Body_txt_pass1").value))
    {
        strerror +="Password must contain a letter\n";
        passed = false;
    }

    if (document.getElementById("ctl00_CPH_Body_txt_pass1").value != document.getElementById("ctl00_CPH_Body_txt_pass2").value)
    {
        strerror +="Passwords must be the same\n";
        passed = false;
    }
    //Check to see if password is the same as the email
    if (document.getElementById("ctl00_CPH_Body_txt_pass1").value == document.getElementById("ctl00_CPH_Body_txt_Email").value)
    {
        strerror +="Password must be different than your Email Address\n";
        passed = false;
    }
    //Check Security Q and A
    if (document.getElementById("ctl00_CPH_Body_ddl_Sec_Question").value == "")
    {
        strerror +="Please select a security question\n";
        passed = false;
    }
    
    if (document.getElementById("ctl00_CPH_Body_txt_sec_answer").value == "")
    {
        strerror +="Please enter a security answer\n";
        passed = false;
    }
    
    //Check customers Are
    var i = 0;
    var checked = false;
    while (document.getElementById("ctl00_CPH_Body_Chk_Customers_" + i) != null)
    {
        if (document.getElementById("ctl00_CPH_Body_Chk_Customers_" + i).checked)
        {
            checked = true;
        }
        i++;
    }
    if (!checked)
    {
        strerror +="Please select who your customers are\n";
        passed = false; 
    }
    
    
    //Check Business type
    i = 0 
    checked = false;
    while(document.getElementById("ctl00_CPH_Body_Chk_BusinessType_" + i) != null)
    {
        if(document.getElementById("ctl00_CPH_Body_Chk_BusinessType_" + i).checked)
        {
            checked = true;
        }
        i++;
    }
    if (!checked)
    {
        strerror +="Please select your business type\n";
        passed = false; 
    }
    
    //Testing
    
    //Check To see if passed
    if (passed)
    {
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
      if(document.getElementById("ctl00_CPH_Body_Chk_Customers_5").checked || document.getElementById("ctl00_CPH_Body_Chk_Customers_6").checked)
        {
            if(confirm("Gemco Medical is a Business to Business only.\n\nClick OK if you are a consumer.\n\nClick Cancle to return and select your business type."))
            {
                document.getElementById("ctl00_CPH_Body_Hdn_IsAConsumer").value  = "True"
            }
            else
            {
                document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
            }
      }

    }
    else
    {
        alert("Please correct the following issues and save:\n" + strerror);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
    }
    return;
}

//function check_onechar(element,hideelement)
//{
//    element = "ctl00_CPH_Body_" + element;
//    if (document.getElementById(element).value != "" )
//    {
//        //Hide *
//        document.getElementById(hideelement).style.visibility = 'hidden';
//    }
//    else
//    {
//        //Show *
//        document.getElementById(hideelement).style.visibility = 'visible';
//    }

//return;
//}

function check_Length(element,hideelement,length)
{
    element = "ctl00_CPH_Body_" + element;
    if (document.getElementById(element).value.length >= length )
    {
        //Hide *
        document.getElementById(hideelement).style.visibility = 'hidden';
    }
    else
    {
        //Show *
        document.getElementById(hideelement).style.visibility = 'visible';
    }
return;
}

//check to see if email passes test if so hide the star
function check_email(element,hideelement)
{
    element = "ctl00_CPH_Body_" + element;
    if (document.getElementById(element).value.length >= 2 && document.getElementById(element).value.indexOf("@") >= 0 && document.getElementById(element).value.indexOf(".") >= 0)
    {
        //Hide *
        document.getElementById(hideelement).style.visibility = 'hidden';
    }
    else
    {
        //Show *
        document.getElementById(hideelement).style.visibility = 'visible';
    }
return;
}


//This Function Checks to see if the password will work
function check_password(element,hideelement)
{
    element = "ctl00_CPH_Body_" + element;

    var strongRegex = new RegExp("(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,10})$", "g");
    var pwd = document.getElementById(element).value;
    var check = strongRegex.test(pwd);
           
          // Hide *
          if (true == check) 
            {
             document.getElementById(hideelement).style.visibility = 'hidden';
            }
          //Show *
          else
            {
              document.getElementById(hideelement).style.visibility = 'visible';      
             }


//    if (document.getElementById(element).value.length > 5 && isNaN(document.getElementById(element).value) && numeric_Check(document.getElementById(element).value))
//    {
//        //Hide *
//        document.getElementById(hideelement).style.visibility = 'hidden';
//    }
//    else
//    {
//        //Show *
//        document.getElementById(hideelement).style.visibility = 'visible';
//    }
return;
}

//checks to see if 2 values are the same ie. Password 1 and password 2
function check_same2(element, checkelement, hideelement)
{
    element = "ctl00_CPH_Body_" + element;
    checkelement = "ctl00_CPH_Body_" + checkelement;
    if (document.getElementById(element).value == document.getElementById(checkelement).value)
    {
        //Hide *
        document.getElementById(hideelement).style.visibility = 'hidden';
    }
    else
    {
        //Show *
        document.getElementById(hideelement).style.visibility = 'visible';
    }
return;
}


//This Function Checks to see if the string has a number in it
function numeric_Check(check_string)
{
    var passed = false;
    if (check_string.indexOf("0") >= 0 || check_string.indexOf("1") >= 0 || check_string.indexOf("2") >= 0 || check_string.indexOf("3") >= 0 || check_string.indexOf("4") >= 0 || check_string.indexOf("5") >= 0 || check_string.indexOf("6") >= 0 || check_string.indexOf("7") >= 0 || check_string.indexOf("8") >= 0 || check_string.indexOf("9") >= 0 )
    {
        passed = true;
    }
    return passed;
}

//This Function hides all of the div's in bulk Order
function hide()
{
    //Hide all of them
    document.getElementById("ctl00_CPH_Body_Pnl_Invoice").style.visibility = 'hidden';
    document.getElementById("ctl00_CPH_Body_Pnl_COD").style.visibility = 'hidden';
    document.getElementById("ctl00_CPH_Body_Pnl_TeleCheck").style.visibility = 'hidden';
    document.getElementById("ctl00_CPH_Body_Pnl_Credit").style.visibility = 'hidden';
    document.getElementById("ctl00_CPH_Body_Pnl_Check").style.visibility = 'hidden';

    //Shrink all of them
    document.getElementById("ctl00_CPH_Body_Pnl_Invoice").className = 'HiddenPanel';
    document.getElementById("ctl00_CPH_Body_Pnl_COD").className = 'HiddenPanel';
    document.getElementById("ctl00_CPH_Body_Pnl_TeleCheck").className = 'HiddenPanel';
    document.getElementById("ctl00_CPH_Body_Pnl_Credit").className = 'HiddenPanel';
    document.getElementById("ctl00_CPH_Body_Pnl_Check").className = 'HiddenPanel';
    return;
}

//this function hides all the div's on bulk order then shows the one clicked
function show_Panel(element)
{
    hide();
    //make visible
    document.getElementById("ctl00_CPH_Body_" + element).style.visibility = 'visible';
    //Remove 0px size restraint
    document.getElementById("ctl00_CPH_Body_" + element).className = 'ShowPanel';
    return;
}

//this function load the Panels on the Bulk_Order Page from the dropdown.
function Load_Panels()
{
    //alert(document.getElementById("ctl00_CPH_Body_DDL_Payment_Type").value)
    switch (document.getElementById("ctl00_CPH_Body_DDL_Payment_Type").value) {
        case "1": show_Panel('Pnl_Credit');
                break;
        case "2": show_Panel('Pnl_COD');
                break;
        case "3": show_Panel('Pnl_Invoice');
                break;
        case "4": show_Panel('Pnl_TeleCheck');
                break;
        case "5": show_Panel('Pnl_Check');
                break;
        default: hide();
        }


return;
}

//This Function Checks and validates the fields for Bulk_Order page
function bulk_order_check()
{
    var passed = true;
    var errorstring = "Please correct the following issues before clicking purchase.\n\n";
    //Check To See If billto is loaded from mom
    if(document.getElementById("ctl00_CPH_Body_hdn_Check_Billto").value == "True")
    {
        //bill to firstname
        if (document.getElementById("ctl00_CPH_Body_txt_Billto_First").value.length < 1)
        {
            errorstring += "Please enter a bill to First Name.\n";
            passed = false;
        }
         // billto last name
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_Last").value.length < 1)
        {
            errorstring += "Please enter a bill to Last Name.\n";
            passed = false;
        }
        
        // billto Address
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_Address1").value.length < 1)
        {
            errorstring += "Please enter a bill to Address.\n";
            passed = false;
        }
        
        // billto City
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_City").value.length < 1)
        {
            errorstring += "Please enter a bill to City.\n";
            passed = false;
        }
        
        // billto State
         if (document.getElementById("ctl00_CPH_Body_ddl_Billto_State").value.length < 1)
        {
            errorstring += "Please select a bill to State.\n";
            passed = false;
        }
        
        // billto Zip
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_Zip").value.length < 5)
        {
            errorstring += "Please enter a bill to Zipcode.\n";
            passed = false;
        }
        //Billto Phone
             if (document.getElementById("ctl00_CPH_Body_txt_billto_phone").value.length < 5)
        {
            errorstring += "Please enter a bill to Phone Number.\n";
            passed = false;
        }
     }   
        
    //shipto Firstname 
     if (document.getElementById("ctl00_CPH_Body_txt_Shipto_First").value.length < 1)
    {
        errorstring += "Please enter a ship to First Name.\n";
        passed = false;
    }   
    
    // shipto last name
     if (document.getElementById("ctl00_CPH_Body_txt_Shipto_Last").value.length < 1)
    {
        errorstring += "Please enter a ship to Last Name.\n";
        passed = false;
    }

    // shipto Address
     if (document.getElementById("ctl00_CPH_Body_txt_Shipto_Address1").value.length < 1)
    {
        errorstring += "Please enter a ship to Address.\n";
        passed = false;
    }
    
    // shipto City
     if (document.getElementById("ctl00_CPH_Body_txt_Shipto_City").value.length < 1)
    {
        errorstring += "Please enter a ship to City.\n";
        passed = false;
    }
       
    // shipto State
     if (document.getElementById("ctl00_CPH_Body_ddl_Shipto_State").value.length < 1)
    {
        errorstring += "Please select a ship to State.\n";
        passed = false;
    }

    // shipto Zip
     if (document.getElementById("ctl00_CPH_Body_txt_Shipto_Zip").value.length < 5)
    {
        errorstring += "Please enter a ship to Zipcode.\n";
        passed = false;
    }
        //shipto Phone
//         if (document.getElementById("ctl00_CPH_Body_txt_shipto_phone").value.length < 5)
//    {
//        errorstring += "Please enter a bill to Phone Number.\n";
//        passed = false;
//    }
    
    //Check PO
     if (document.getElementById("ctl00_CPH_Body_txt_Ponumber").value.length < 1)
    {
        errorstring += "Please enter a valid PO number.\n";
        passed = false;
    }
    //Check SHip Method
    
    if (document.getElementById("ctl00_CPH_Body_ddl_Ship").value.length < 2)
    {
        errorstring += "Please select a shipping method.\n";
        passed = false;
    }

    
    //If passed = true then send back a true value in the validated field
    if (passed)
    {
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True";
    }
    else
    {
        alert(errorstring);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False";
        Load_Panels();
        //document.getElementById("ctl00_CPH_Body_DDL_Payment_Type").value = "0"
    }
return;
}

//This Function Checks and validates the fields for Dropship Order Processing page
function Dropship_Order_Check()
{
    var passed = true;
    var errorstring = "Please correct the following issues before clicking purchase.\n\n";
    //Check To See If billto is loaded from mom
    if(document.getElementById("ctl00_CPH_Body_hdn_Check_Billto").value == "True")
    {
        //bill to firstname
        if (document.getElementById("ctl00_CPH_Body_txt_Billto_First").value.length < 1)
        {
            errorstring += "Please enter a bill to First Name.\n";
            passed = false;
        }
         // billto last name
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_Last").value.length < 1)
        {
            errorstring += "Please enter a bill to Last Name.\n";
            passed = false;
        }
        
        // billto Address
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_Address1").value.length < 1)
        {
            errorstring += "Please enter a bill to Address.\n";
            passed = false;
        }
        
        // billto City
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_City").value.length < 1)
        {
            errorstring += "Please enter a bill to City.\n";
            passed = false;
        }
        
        // billto State
         if (document.getElementById("ctl00_CPH_Body_ddl_Billto_State").value.length < 1)
        {
            errorstring += "Please select a bill to State.\n";
            passed = false;
        }
        
        // billto Zip
         if (document.getElementById("ctl00_CPH_Body_txt_Billto_Zip").value.length < 5)
        {
            errorstring += "Please enter a bill to Zipcode.\n";
            passed = false;
        }
        //Billto Phone
             if (document.getElementById("ctl00_CPH_Body_txt_billto_phone").value.length < 5)
        {
            errorstring += "Please enter a bill to Phone Number.\n";
            passed = false;
        }
     }   
        
    //Check PO
     if (document.getElementById("ctl00_CPH_Body_txt_Ponumber").value.length < 1)
    {
        errorstring += "Please enter a valid PO number (must be 5 Characters).\n";
        passed = false;
    }
    //Check SHip Method
    
//    if (document.getElementById("ctl00_CPH_Body_ddl_Ship").value.length < 2)
//    {
//        errorstring += "Please select a shipping method.\n";
//        passed = false;
//    }
    
    //If passed = true then send back a true value in the validated field
    if (passed)
    {
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True";
    }
    else
    {
        alert(errorstring);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False";
        document.getElementById("ctl00_CPH_Body_DDL_Payment_Type").value = "0"
    }
return;
}

//This function determinds wether or not to show the *'s for the bulk order page
function check_stars_bulk()
{
    //Load stars
    check_Length('txt_Billto_First','star_Billto_First',1);
    check_Length('txt_Billto_Last','star_Billto_Last',1);
    check_Length('txt_Billto_Address1','star_Billto_Address',1);
    check_Length('txt_Billto_City','star_Billto_City',1);
    check_Length('ddl_Billto_State','star_Billto_State',1);
    check_Length('txt_Billto_Zip','star_Billto_Zip',5);
    check_Length('txt_Shipto_First','star_Shipto_First',1);
    check_Length('txt_Shipto_Last','star_Shipto_Last',1);
    check_Length('txt_Shipto_Address1','star_Shipto_Address',1);
    check_Length('txt_Shipto_City','star_Shipto_City',1);
    check_Length('ddl_Shipto_State','star_Shipto_State',1);
    check_Length('txt_Shipto_Zip','star_Shipto_Zip',5);
    check_Length('txt_Ponumber','star_Ponumber',1);
    //check_Length('txt_Shipto_Phone','star_Shipto_Phone',10);
    check_Length('txt_Billto_Phone','star_Billto_Phone',10);
    
    
    //check stars for credit card
    check_Length('txt_CCID','star_CCID',1);
    check_Length('txt_Credit_Number','star_Credit_Number',13);
    check_Length('ddl_CC_type','star_CC_type',1);
    
    //Load Bottom Panel
    Load_Panels();
    return;
}

//This function sets the ship to address the same as the bill to
function check_same()
{
    if (document.getElementById("ctl00_CPH_Body_Chk_Same").checked)
    {
        //Set All the fields equal
        set_equal('txt_Billto_First','txt_Shipto_First');
        set_equal('txt_Billto_Last','txt_Shipto_Last');
        set_equal('txt_Billto_Company','txt_Shipto_Company');
        set_equal('txt_Billto_Address1','txt_Shipto_Address1');
        set_equal('txt_Billto_Address2','txt_Shipto_Address2');
        set_equal('txt_Billto_City','txt_Shipto_City');
        set_equal('ddl_Billto_State','ddl_Shipto_State');
        set_equal('txt_Billto_Zip','txt_Shipto_Zip');
        set_equal('txt_Billto_Phone','txt_Shipto_Phone');
    }
    else
    {
    //Clear all
        document.getElementById("ctl00_CPH_Body_txt_Shipto_First").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_Last").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_Company").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_Address1").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_Address2").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_City").value = "";
        document.getElementById("ctl00_CPH_Body_ddl_Shipto_State").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_Zip").value = "";
        document.getElementById("ctl00_CPH_Body_txt_Shipto_Phone").value = "";
    }

    //check all the stars
    check_stars_bulk();
    return;
}

//Set these to fields equal
function set_equal(element, setelement)
{
    element = "ctl00_CPH_Body_" + element;
    setelement = "ctl00_CPH_Body_" + setelement;

    document.getElementById(setelement).value = document.getElementById(element).value

    return;
}

//This Function Checks the credit card values
function credit_check()
{
     //alert("Credit"); // For Testing
    var passed = "True";
    var errorString = "Please Correct the Following:\n\n";
    
    //Check all the credit card values
    if (document.getElementById("ctl00_CPH_Body_ddl_CC_type").value.length < 1)
    {
        errorString += "please select a credit card type.\n";
        passed = "False";
    }
    
    if (document.getElementById("ctl00_CPH_Body_txt_Credit_Number").value.length < 13)
    {
        errorString += "please enter a valid credit card number.\n";
        passed = "False";
    }
    
    if (document.getElementById("ctl00_CPH_Body_txt_CCID").value.length < 1)
    {
        errorString += "please enter a CCID.\n";
        passed = "False";
    }
    
    if (passed == "False")
    {
        alert(errorString);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
        
       //document.getElementById("ctl00_CPH_Body_DDL_Payment_Type").value = "0"
    }
    return;
}

function order_history_add_to_cart(orderno)
{
    document.getElementById("ctl00_CPH_Body_Hdn_Add_to_cart").value = orderno
    return;
}


function Modify_Check()
{
    var strerror = "";
    var passed = true;
    
    //Build Error String 
    //1.Check For Empty Fields
//    if (document.getElementById("ctl00_CPH_Body_txt_Firstname").value == "") 
//    {
//        strerror += "Please Enter A First Name\n";
//        passed = false;
//    }
//    if (document.getElementById("ctl00_CPH_Body_txt_LastName").value == "") 
//    {
//        strerror += "Please Enter A Last Name\n";
//        passed = false;
//    } 
//    if (document.getElementById("ctl00_CPH_Body_txt_company").value == "") 
//    {
//        strerror += "Please Enter A Company Name\n";
//        passed = false;
//    } 
//  
//    if (document.getElementById("ctl00_CPH_Body_txt_address1").value == "") 
//    {
//        strerror += "Please Enter A Valid Address\n";
//        passed = false;
//    } 
//    if (document.getElementById("ctl00_CPH_Body_txt_city").value == "") 
//    {
//        strerror += "Please Enter A City\n";
//        passed = false;
//    }
//    if (document.getElementById("ctl00_CPH_Body_DDl_state").value == "") 
//    {
//        strerror += "Please Select A State\n";
//        passed = false;
//    }  
//    //Check Zip Length
//    if (document.getElementById("ctl00_CPH_Body_txt_zipcode").value.length < 5) 
//    {
//        strerror += "Please Enter A Valid Zipcode\n";
//        passed = false;
//    } 
    
//    //Check OldCustnum
//    if (document.getElementById("ctl00_CPH_Body_txt_Sys_Num").value.length >= 1 && isNaN(document.getElementById("ctl00_CPH_Body_txt_Sys_Num").value))
//    {
//        strerror += "Please Enter A Valid System Customer Number\n"
//        passed = false;
//    } 

    
    //Check Email
        if(document.getElementById("ctl00_CPH_Body_rbl_Email_1").checked)
        {
            if (document.getElementById("ctl00_CPH_Body_txt_Email").value.length < 5 || document.getElementById("ctl00_CPH_Body_txt_Email").value.indexOf("@") < 0 || document.getElementById("ctl00_CPH_Body_txt_Email").value.indexOf(".") < 0) 
            {
                strerror += "Please Enter A Valid Email Address\n";
                passed = false;
            }
        }
    //Check Password
        if(document.getElementById("ctl00_CPH_Body_Rbl_Password_1").checked)
        {
            if (document.getElementById("ctl00_CPH_Body_txt_pass1").value.length < 6)
            {
                strerror +="Password must be at least 6 Characters\n";
                passed = false;
            }
            if (!numeric_Check(document.getElementById("ctl00_CPH_Body_txt_pass1").value))
            {
                strerror +="Password must contain a number\n";
                passed = false;
            }
            if (!isNaN(document.getElementById("ctl00_CPH_Body_txt_pass1").value))
            {
                strerror +="Password must contain a letter\n";
                passed = false;
            }
            if (document.getElementById("ctl00_CPH_Body_txt_pass1").value != document.getElementById("ctl00_CPH_Body_txt_pass2").value)
            {
                strerror +="Passwords must be the same\n";
                passed = false;
            }
            if (document.getElementById("ctl00_CPH_Body_txt_pass1").value == document.getElementById("ctl00_CPH_Body_txt_Email").value)
            {
                strerror +="Password must not be your Email Address\n";
                passed = false;
            }
    }
    
    //Check Security Q and A
//    if (document.getElementById("ctl00_CPH_Body_ddl_Sec_Question").value == "")
//    {
//        strerror +="Please select a security question\n";
//        passed = false;
//    }
//    
//    if (document.getElementById("ctl00_CPH_Body_txt_sec_answer").value == "")
//    {
//        strerror +="Please enter a security answer\n";
//        passed = false;
//    }

    //Check customers Are
    var i = 0;
    var checked = false;
    while (document.getElementById("ctl00_CPH_Body_Chk_Customers_" + i) != null)
    {
        if (document.getElementById("ctl00_CPH_Body_Chk_Customers_" + i).checked)
        {
            checked = true;
        }
        i++;
    }
    if (!checked)
    {
        strerror +="Please select who your customers are\n";
        passed = false; 
    }
    
    
    //Check Business type
    i = 0 
    checked = false;
    while(document.getElementById("ctl00_CPH_Body_Chk_BusinessType_" + i) != null)
    {
        if(document.getElementById("ctl00_CPH_Body_Chk_BusinessType_" + i).checked)
        {
            checked = true;
        }
        i++;
    }
    if (!checked)
    {
        strerror +="Please select your business type\n";
        passed = false; 
    }
    
    //Testing
    
    //Check To see if passed
    if (passed)
    {
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
      if(document.getElementById("ctl00_CPH_Body_Chk_Customers_5").checked || document.getElementById("ctl00_CPH_Body_Chk_Customers_6").checked)
        {
            if(confirm("Gemco Medical is a Business to Business only.\n\nClick OK if you are a consumer.\n\nClick Cancle to return and select your business type."))
            {
                document.getElementById("ctl00_CPH_Body_Hdn_IsAConsumer").value  = "True"
            }
            else
            {
                document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
            }
      }

    }
    else
    {
        alert("Please correct the following issues and save:\n" + strerror);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
    }
    return;
    
    
    //Check To see if passed
//    if (passed)
//    {
//        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
//    }
//    else
//    {
//        alert("Please correct the following issues and save:\n" + strerror);
//        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
//    }
//    return;
}

function modify_show_email_panel()
{
    var Form;
    Form = document.forms[0];

    if(document.getElementById("ctl00_CPH_Body_rbl_Email_1").checked)
    {
    //Show
        document.getElementById("ctl00_CPH_Body_Pnl_change_Email").style.visibility = 'visible';
        document.getElementById("ctl00_CPH_Body_Pnl_change_Email").className = 'ShowPanel';
    }
    else
    {
    //Hide   
          document.getElementById("ctl00_CPH_Body_Pnl_change_Email").style.visibility = 'hidden';
          document.getElementById("ctl00_CPH_Body_Pnl_change_Email").className = 'HiddenPanel';

    }

return;
}

function modify_show_Password_panel()
{
    var Form;
    Form = document.forms[0];

    if(document.getElementById("ctl00_CPH_Body_Rbl_Password_1").checked)
    {
    //Show
        document.getElementById("ctl00_CPH_Body_Pnl_password").style.visibility = 'visible';
        document.getElementById("ctl00_CPH_Body_Pnl_password").className = 'ShowPanel';
    }
    else
    {
    //Hide   
          document.getElementById("ctl00_CPH_Body_Pnl_password").style.visibility = 'hidden';
          document.getElementById("ctl00_CPH_Body_Pnl_password").className = 'HiddenPanel';

    }

return;
}

function shopping_cart_confirm(hidden_element,displaytext)
{
    hidden_element = "ctl00_CPH_Body_" + hidden_element;
    
    if(confirm(displaytext))
    {
        document.getElementById(hidden_element).value = "True";

    }
    
    return;
}

//Add this to the common
function add_To_Favorites(count)
{
    var itemnum = document.getElementById("ctl00_CPH_Body_Hdn_stock_num_" + count).value;
   
    document.getElementById("ctl00_CPH_Body_hdn_addtofave").value = itemnum;
    document.getElementById("ctl00_CPH_Body_hdn_addtofave_bool").value = "True";
    //alert(document.getElementById("ctl00_CPH_Body_hdn_addtofave_bool").value);
    alert('Item Added To Favorites.')
    return;
}

function bulk_order_load_address(billto_shipto, ddl, txtbillto_shipto)
{
    
   ddl = "ctl00_CPH_Body_" + ddl;
   var firstarray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_first").value.split(",");
   var lastarray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_last").value.split(",");
   var comparray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_company").value.split(",");
   var addr1array = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_addr1").value.split(",");
   var addr2array = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_addr2").value.split(",");
   var cityarray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_city").value.split(",");
   var statearray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_state").value.split(",");
   var ziparray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_zip").value.split(",");
   var phonearray = document.getElementById("ctl00_CPH_Body_hdn_" + billto_shipto + "_phone").value.split(",");
   
   var selectedvalue = document.getElementById(ddl).value
   
   if (selectedvalue != 0) 
   {
   selectedvalue--
//   alert(firstarray[selectedvalue]);
//   alert(lastarray[selectedvalue]);
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_First").value = firstarray[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Last").value = lastarray[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Company").value = comparray[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Address1").value = addr1array[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Address2").value = addr2array[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_City").value = cityarray[selectedvalue];
   document.getElementById("ctl00_CPH_Body_ddl_" + txtbillto_shipto + "_State").value = statearray[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Zip").value = ziparray[selectedvalue];
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Phone").value = phonearray[selectedvalue];
   

   
   }
   else
   {
      document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_First").value = "";
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Last").value = "";
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Company").value = "";
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Address1").value = "";
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Address2").value = "";
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_City").value = "";
   document.getElementById("ctl00_CPH_Body_ddl_" + txtbillto_shipto + "_State").value = "";
   document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Zip").value = "";
    document.getElementById("ctl00_CPH_Body_txt_" + txtbillto_shipto + "_Phone").value = "";
   
   }
     //check all the stars
    check_stars_bulk();

    return;
}


function add_to_cart_fave(number)
{
    if (number != "0")
    {
         document.getElementById("ctl00_CPH_Body_Hdn_AddtoCart").value = number + ",1";
         alert("Item Added To Your Cart");
    }
    else
    {
        document.getElementById("ctl00_CPH_Body_Hdn_AddtoCart").value = "0";
    }
    return;
}

//function Enable_Dropship_Order_Entry()
//{
// var Form;
// 
// Form = document.forms[1];
// 
// //alert("Check:" + document.getElementById("ctl00$CPH_Body$Chk_AddressVerification").checked); 
// //alert("Item 1:" + document.getElementById("ctl00$CPH_Body$Txt_Item1").name);
//                                
// 
// if (document.getElementById("ctl00$CPH_Body$Chk_AddressVerification").checked == true) 
// {
//  alert("Checked");
//  document.getElementById("ctl00$CPH_Body$Txt_Item1").readonly = "true";
//  document.getElementById("ctl00$CPH_Body$Txt_QTY1").readonly = "true";
// }
//  else
// {
//  alert("Not Checked");
//  Form.ctl00$CPH_Body$Txt_Item1.enabled = "false";
//  Form.ctl00$CPH_Body$Txt_QTY1.enabled = "false";
// } 
// return; 
//}

function dia_dme_search(storenum)
{
//alert("Worked");
document.getElementById("ctl00_CPH_Body_Hdn_Redirect_string").value = "/src/main/SearchProds.aspx?NAV=1&SearchCriteria=" + document.getElementById("txt_Menu_Search").value + "&Dept=&storenum=" + storenum

return 0;
}
function Drop_Customer_Update_Check()
{
    var strerror = "";
    var passed = true;
    

   //Check Firstname
    if (document.getElementById("ctl00_CPH_Body_Txt_FirstName").value.length < 1)
    {
        strerror +="Please enter a first name\n";
        passed = false;
    }
     //Check LAst Name
        if (document.getElementById("ctl00_CPH_Body_Txt_LastName").value.length < 1)
    {
        strerror +="Please enter a last name\n";
        passed = false;
    }
         //Check Addr1
        if (document.getElementById("ctl00_CPH_Body_Txt_Address1").value.length < 1)
    {
        strerror +="Please enter a line 1 address\n";
        passed = false;
    }
             //Check City
        if (document.getElementById("ctl00_CPH_Body_Txt_City").value.length < 1)
    {
        strerror +="Please enter a city\n";
        passed = false;
    }
    //enter a state
    if (document.getElementById("ctl00_CPH_Body_ddl_State").value == "") 
    {
        strerror += "Please select a state\n";
        passed = false;
    }  
                 //Check City
        if (document.getElementById("ctl00_CPH_Body_Txt_Zipcode").value.length < 5)
    {
        strerror +="Please enter a valid zip code\n";
        passed = false;
    }
    
    //Check To see if passed
    if (passed)
    {
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
        alert("Customer Updated");

    }
    else
    {
        alert("Please correct the following items:\n" + strerror);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False";
    }
    return;
}
//This Function Checks the Dropship Customer Add
function Drop_Customer_Add_Check()
{
    var strerror = "";
    var passed = true;
    

   //Check Firstname
    if (document.getElementById("ctl00_CPH_Body_Txt_FirstName").value.length < 1)
    {
        strerror +="Please enter a first name\n";
        passed = false;
    }
     //Check LAst Name
        if (document.getElementById("ctl00_CPH_Body_Txt_LastName").value.length < 1)
    {
        strerror +="Please enter a last name\n";
        passed = false;
    }
         //Check Addr1
        if (document.getElementById("ctl00_CPH_Body_Txt_Address1").value.length < 1)
    {
        strerror +="Please enter a line 1 address\n";
        passed = false;
    }
             //Check City
        if (document.getElementById("ctl00_CPH_Body_Txt_City").value.length < 1)
    {
        strerror +="Please enter a city\n";
        passed = false;
    }
    //enter a state
    if (document.getElementById("ctl00_CPH_Body_ddl_State").value == "") 
    {
        strerror += "Please select a state\n";
        passed = false;
    }  
                 //Check City
        if (document.getElementById("ctl00_CPH_Body_Txt_Zipcode").value.length < 5)
    {
        strerror +="Please enter a valid zip code\n";
        passed = false;
    }
    
    //Check To see if passed
    if (passed)
    {
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
        alert("Customer Added");

    }
    else
    {
        alert("Please correct the following items:\n" + strerror);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False";
    }
    return;
}
//This Function Confirms the removal on Dropship_Product_Selection
function Drop_Customer_Remove_Check()
{
    if(confirm("Click OK to remove this Customer from your order.\n\nClick Cancel to keep this customer on the order."))
        {
            document.getElementById("ctl00_CPH_Body_Hdn_Remove").value = "True";
        }
    return;
}

//THis Function clears the text of what ever is sent to it
function Clear_Text(name, findstring)
{
    if (findstring == document.getElementById("ctl00_CPH_Body_" + name).value)
    {
        document.getElementById("ctl00_CPH_Body_" + name).value = "";
    }
    document.getElementById("ctl00_CPH_Body_" + name).focus()
    document.getElementById("ctl00_CPH_Body_" + name).select()
    
}

//This Function Removes Non-Numerics from the field listed
function remove_non_numeric(name)
{
            if (document.getElementById("ctl00_CPH_Body_" + name).value == "" )
            {
            document.getElementById("ctl00_CPH_Body_" + name).value = 1;
            }
        
    if (isNaN(document.getElementById("ctl00_CPH_Body_" + name).value))
    {
        var i = 0
        while ( i < document.getElementById("ctl00_CPH_Body_" + name).value.length)
        {
           if (isNaN(document.getElementById("ctl00_CPH_Body_" + name).value.charAt(i)))
            {
                document.getElementById("ctl00_CPH_Body_" + name).value = document.getElementById("ctl00_CPH_Body_" + name).value.substr(0,i) + document.getElementById("ctl00_CPH_Body_" + name).value.substr(i + 1, document.getElementById("ctl00_CPH_Body_" + name).value.length);
                break;
            }
            
            i++;
        }
    }
    return;
}

//This Function Updates the Total
function Product_Select_QTY_Update(num_of_rows, qty_base_name, prod_price_base_name, prod_total_base_name, total_name, item_name)
{
    
    var i = 1
    var running_tot = 0 
        
    while (i <= num_of_rows)
    {
            if(document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value == 0 && document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value != "")
                {
                    document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value = 1;
                }
        //If Not Blank run through totals
        if (document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value != "" && document.getElementById("ctl00_CPH_Body_" + prod_price_base_name + i).value != "")
        {
        //alert(i);
                    //alert("ctl00_CPH_Body_" + prod_total_base_name + i);
                    
            update_price_drop(item_name, prod_price_base_name, qty_base_name, i) 
            //Set Item Total to Qty * Price   
            document.getElementById("ctl00_CPH_Body_" + prod_total_base_name + i).innerHTML =  formatCurrency_No_Dollar_Sign(parseFloat(document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value) *  parseFloat(document.getElementById("ctl00_CPH_Body_" + prod_price_base_name + i).innerHTML));
            //add to running total
            running_tot = running_tot + parseFloat(document.getElementById("ctl00_CPH_Body_" + prod_total_base_name + i).innerHTML);
        }
        i++;
    }
    //Display Item Total
    document.getElementById("ctl00_CPH_Body_" + total_name).innerHTML = formatCurrency(running_tot)
    
    update_drop_cart_totals(prod_price_base_name, item_name, qty_base_name, prod_total_base_name, num_of_rows, num_of_rows)
    
    return;
}     

//Use this one for bulk
function Product_Select_QTY_Update_Bulk(num_of_rows, qty_base_name, prod_price_base_name, prod_total_base_name, total_name, item_name)
{
    var i = 1
    var running_tot = 0 
    while (i <= num_of_rows)
    {
  
        //If Not Blank run through totals
        if (document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value != "" && document.getElementById("ctl00_CPH_Body_" + prod_price_base_name + i).value != "")
        {
        //alert(i);
                    //alert("ctl00_CPH_Body_" + prod_total_base_name + i);
            //update_price_drop(item_name, prod_price_base_name, qty_base_name, i) 
            //Set Item Total to Qty * Price   
            document.getElementById("ctl00_CPH_Body_" + prod_total_base_name + i).innerHTML =  formatCurrency_No_Dollar_Sign(parseFloat(document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).value) *  parseFloat(document.getElementById("ctl00_CPH_Body_" + prod_price_base_name + i).innerHTML));
            //add to running total
            running_tot = running_tot + parseFloat(document.getElementById("ctl00_CPH_Body_" + prod_total_base_name + i).innerHTML);
        }
        i++;
    }
    //Display Item Total
    document.getElementById("ctl00_CPH_Body_" + total_name).innerHTML = formatCurrency(running_tot)
    
    update_drop_cart_totals(prod_price_base_name, item_name, qty_base_name, prod_total_base_name, num_of_rows, num_of_rows)
    
    return;
}   

//This Function Enables the textboxes
function Product_Select_Enable_Boxes(check_box_name, num_of_rows, product_base_name, qty_base_name)
{
    var i = 1
    while(i <= num_of_rows)
    {
        if (document.getElementById("ctl00_CPH_Body_" + check_box_name).checked)
        {
            document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).disabled=false;
            document.getElementById("ctl00_CPH_Body_" + product_base_name + i).disabled=false;

        }
        else
        {
            document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).disabled=true;
            document.getElementById("ctl00_CPH_Body_" + product_base_name + i).disabled=true;

        }
        i++;
    }
    return;
}

//THis Function formats for money without the sign
function formatCurrency_No_Dollar_Sign(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '' + dblValue + '.' + strCents);
}

//This Function adds the Enter ItemText Back into the  item line in the product order page.
function Product_Select_add_text_back(name)
{
    if (document.getElementById("ctl00_CPH_Body_" + name).value.replace(/" "/g, "") == "")
    {   
        document.getElementById("ctl00_CPH_Body_" + name).value = "Enter Product Number" 
    }
    return;
}   

//This function looks to see if item is able to be added to the cart.
function shopping_cart_item_update(error_name, price_base_name, item_name, qty_name, item_total_name, num)
{
    var i = 0;
    var found = 0;
    var item_array = document.getElementById("ctl00_CPH_Body_Hdn_Items").value.split(",");
    var price_array = document.getElementById("ctl00_CPH_Body_Hdn_Prices").value.split(",");
    
    if (document.getElementById("ctl00_CPH_Body_" + item_name + num).value.replace(/ /g, "") == "")
    {   
        document.getElementById("ctl00_CPH_Body_" + item_name + num).value = "Enter Product Number";
            //Clear Values
            document.getElementById("ctl00_CPH_Body_" + error_name + num).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + item_name + num).value = 'Enter Product Number';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + qty_name + num).value = '';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).innerHTML = '';
        
        
        //Clear Red Text
        document.getElementById("ctl00_CPH_Body_" + error_name + num).className = '';
        document.getElementById("ctl00_CPH_Body_" + item_name + num).className = 'AlignLeft';
        document.getElementById("ctl00_CPH_Body_" + price_base_name + num).className = 'AlignRight';
        document.getElementById("ctl00_CPH_Body_" + qty_name + num).className = 'AlignRight';
        document.getElementById("ctl00_CPH_Body_" + item_total_name + num).className = 'AlignRight';
        
    }
    else
    {  
        
        while (item_array[i] != null)
        {
            if (document.getElementById("ctl00_CPH_Body_" + item_name + num).value == item_array[i])
            {
             document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = formatCurrency_No_Dollar_Sign(price_array[i]);
             //alert(i);
             //alert(document.getElementById("ctl00_CPH_Body_" + item_name).value.toUpperCase);
             if(document.getElementById("ctl00_CPH_Body_" + qty_name + num).value == "" ||document.getElementById("ctl00_CPH_Body_" + qty_name + num).value == " " )
             {             
             document.getElementById("ctl00_CPH_Body_" + qty_name + num).value = 1;
             }
             update_shopping_cart_totals(price_base_name, item_name, qty_name, item_total_name, num)
             found = 1;
            break;
            }
        
        i++;
        }
        //alert(item_array[item_array.length - 1]);
        //alert(document.getElementById("ctl00_CPH_Body_" + item_name).value);

        //If The Item is found
        if (found == 1)
        {
            //alert("Found");
            
            document.getElementById("ctl00_CPH_Body_" + error_name + num).className = '';
            document.getElementById("ctl00_CPH_Body_" + item_name + num).className = 'AlignLeft';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + qty_name + num).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).className = 'AlignRight';
            
            //Erase Error Message
            document.getElementById("ctl00_CPH_Body_" + error_name + num).innerHTML = '';
        }
        else //Else the item is not in the system
        {   
            //Set All to red text
            document.getElementById("ctl00_CPH_Body_" + error_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + item_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + qty_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).className = 'redtext';
            
            //Set Prices = to 0
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).innerHTML = "0.00";
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = "0.00";
            
            //Write Error Message
            document.getElementById("ctl00_CPH_Body_" + error_name + num).innerHTML = 'Item Not Found';
        }
    }

    return;
}

//This function Clears all the boxes for shopping cart
function bulk_cart_clear_quick_add(error_name, price_base_name, item_name, qty_name, item_total_name, num)
{
    var i = 1
    
    while (i <= num)
    {
            //Clear Values
            document.getElementById("ctl00_CPH_Body_" + error_name + i).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + item_name + i).value = 'Enter Product Number';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + i).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + qty_name + i).value = '';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + i).innerHTML = '';
    
            //Set Css Class Back to Normal
            document.getElementById("ctl00_CPH_Body_" + error_name + i).className = '';
            document.getElementById("ctl00_CPH_Body_" + item_name + i).className = 'AlignLeft';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + i).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + qty_name + i).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + i).className = 'AlignRight';
            
            //Erase Error Message
            document.getElementById("ctl00_CPH_Body_" + error_name + num).innerHTML = '';
    
        i++;
    }

    return;
}    

//This Function Updates all the Totals
function update_shopping_cart_totals(price_base_name, item_name, qty_name, item_total_name, num)
{
    var i = 1;
    while (i <= num)
    {
        document.getElementById("ctl00_CPH_Body_" + item_total_name + i).innerHTML = formatCurrency_No_Dollar_Sign((document.getElementById("ctl00_CPH_Body_" + price_base_name + i).innerHTML) * (document.getElementById("ctl00_CPH_Body_" + qty_name + i).value))
        
        if (document.getElementById("ctl00_CPH_Body_" + item_name + i).innerHTML == "Enter Product Number")
        {
            document.getElementById("ctl00_CPH_Body_" + item_total_name + i).innerHTML = ""
        }
        i++;
    }
    
    return;
}

//THis Funciton Checks to see if they would like to add the items in their quick add menu to their cart before moving on.
function shopping_cart_add_items_from_quick(item_name, num, hdn_name, hdn_update, box_name, hdn_box_name)
{
    var i = 1
    while (i <= num)
    {
        //Find Items in Quick add that arent in the cart    
        if (document.getElementById("ctl00_CPH_Body_" + item_name + i).value != "" && document.getElementById("ctl00_CPH_Body_" + item_name + i).value != "Enter Product Number")
            if(confirm("Would You Like To Add The Items In Your Quick Add Menu To The Cart?\n\n Click OK To Add The Items To The Cart.\n\n Click Cancel to Continue With The Items Already In Your Cart."))
            {
                document.getElementById("ctl00_CPH_Body_" + hdn_name).value = "True"
                //alert("Update");
            }
        i++;
    }
    
    if (!shopping_cart_check_changed_qtys (box_name, hdn_box_name))
    {
        if(confirm("Quantities In Your Cart Have Changed. Would You Like To Update Them?\n\nClick OK To Update Quantities In Cart.\n\nClick Cancel To Keep Old Quantities."))
        {
            document.getElementById("ctl00_CPH_Body_" + hdn_update).value = "True";
            //alert("again");
        }
    }

    return;
}    

function shopping_cart_check_changed_qtys (box_name, hdn_box_name)
{
    var i = 1;
    var returnval = true;
    while (i <= document.getElementById("ctl00_CPH_Body_Hdn_Rows").value)
    {
        if (document.getElementById("ctl00_CPH_Body_" + box_name + i).value != document.getElementById("ctl00_CPH_Body_" + hdn_box_name + i).value) 
        {
        returnval =  false;
        break;
        }
        i++;
    }
    return (returnval);
}    

//This Function Makes the Qty Highlighted   
function shopping_cart_highlight(name)
{
    document.getElementById("ctl00_CPH_Body_" + name).focus()
    document.getElementById("ctl00_CPH_Body_" + name).select()
    return;
}    

//This Function Displays The Error Message Stored in the Hdn_Error Field
function universal_show_error()
{
    if (document.getElementById("ctl00_Hdn_Error_Message").value != "")
    {
        alert(document.getElementById("ctl00_Hdn_Error_Message").value);
    }
    document.getElementById("ctl00_Hdn_Error_Message").value = "";        
    return;
}    

//This function redirects from the select page to the cart pages
//function select_redirect(url, hidden_field)
//{
//    document.getElementById("ctl00_CPH_Body_" + hidden_field).value = url;
//    return;
//}    

//This Function Does the line item for the Dropship Items
function drop_cart_item_update(desc_name, price_base_name, item_name, qty_name, item_total_name, num, all_num)
{
    var i = 0;
    var found = 0;
    var item_array = document.getElementById("ctl00_CPH_Body_Hdn_Items").value.split(",");
    var price_array = document.getElementById("ctl00_CPH_Body_Hdn_Prices").value.split(",");
    var desc_array = document.getElementById("ctl00_CPH_Body_Hdn_Desc").value.split("`");
    
    if (document.getElementById("ctl00_CPH_Body_" + item_name + num).value.replace(/ /g, "") == "")
    {   
        document.getElementById("ctl00_CPH_Body_" + item_name + num).value = "Enter Product Number";
            //Clear Values
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + item_name + num).value = 'Enter Product Number';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + qty_name + num).value = '';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).innerHTML = '';
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).style.height = '1.5em'
        
        
        //Clear Red Text
        document.getElementById("ctl00_CPH_Body_" + desc_name + num).className = '';
        document.getElementById("ctl00_CPH_Body_" + item_name + num).className = 'AlignLeft';
        document.getElementById("ctl00_CPH_Body_" + price_base_name + num).className = 'AlignRight';
        document.getElementById("ctl00_CPH_Body_" + qty_name + num).className = 'AlignRight';
        document.getElementById("ctl00_CPH_Body_" + item_total_name + num).className = 'AlignRight';
        
    }
    else
    {  
        
        while (item_array[i] != null)
        {
            if (document.getElementById("ctl00_CPH_Body_" + item_name + num).value == item_array[i])
            {
             document.getElementById("ctl00_CPH_Body_" + qty_name + num).value = 1;
             document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = formatCurrency_No_Dollar_Sign(get_price_drop(price_array[i],document.getElementById("ctl00_CPH_Body_" + qty_name + num).value));
             document.getElementById("ctl00_CPH_Body_" + desc_name + num).innerHTML = desc_array[i];
             //alert(i);
             //alert(document.getElementById("ctl00_CPH_Body_" + item_name).value.toUpperCase);
             
             
             
             found = 1;
            break;
            }
        i++;
        }
      
        //alert(item_array[item_array.length - 1]);
        //alert(document.getElementById("ctl00_CPH_Body_" + item_name).value);

        //If The Item is found
        if (found == 1)
        {
            //alert("Found");
            
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).className = 'AlignLeft';
            document.getElementById("ctl00_CPH_Body_" + item_name + num).className = 'AlignLeft';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + qty_name + num).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).className = 'AlignRight';
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).style.height = (Math.ceil(document.getElementById("ctl00_CPH_Body_" + desc_name + num).innerHTML.length/35) * 1.5) + 'em';

            //Erase Error Message
            //document.getElementById("ctl00_CPH_Body_" + error_name + num).innerHTML = '';
        }
        else //Else the item is not in the system
        {   
            //Set All to red text
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + item_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + qty_name + num).className = 'redtext';
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).className = 'redtext';
            
            //Set Prices = to 0
            document.getElementById("ctl00_CPH_Body_" + item_total_name + num).innerHTML = "0.00";
            document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = "0.00";
            
            //Write Error Message
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).innerHTML = 'Item Not Found';
            document.getElementById("ctl00_CPH_Body_" + desc_name + num).style.height = '1.5em'

        }
    }
    //update the totals
    update_drop_cart_totals(price_base_name, item_name, qty_name, item_total_name, num, all_num)
    return;
}

function update_drop_cart_totals(price_base_name, item_name, qty_name, item_total_name, num, all_num)
{
    var i = 1;
    var shipping = 0;
    var total = 0;
    while (i <= all_num)
    {
        document.getElementById("ctl00_CPH_Body_" + item_total_name + i).innerHTML = formatCurrency_No_Dollar_Sign((document.getElementById("ctl00_CPH_Body_" + price_base_name + i).innerHTML.replace(/,/,'')) * (document.getElementById("ctl00_CPH_Body_" + qty_name + i).value))
        total = total + (document.getElementById("ctl00_CPH_Body_" + price_base_name + i).innerHTML.replace(/,/,'')) * (document.getElementById("ctl00_CPH_Body_" + qty_name + i).value)
        if (document.getElementById("ctl00_CPH_Body_" + item_name + i).innerHTML == "Enter Product Number")
        {
            document.getElementById("ctl00_CPH_Body_" + item_total_name + i).innerHTML = ""
        }
        i++;
    }
    //alert(total);
    document.getElementById("ctl00_CPH_Body_lbl_MerchandiseTotalValue").innerHTML = formatCurrency(total);
   
   shipping = drop_get_shipping();
   total = (shipping * 1) +  total;
  // alert(total);
   // alert(total.valueOf() + document.getElementById("ctl00_CPH_Body_Lbl_ShippingTotal").innerHTML.slice(1).valueOf());
    if (document.getElementById("ctl00_CPH_Body_Lbl_InvoiceTotalValue") != null)
    {
        document.getElementById("ctl00_CPH_Body_Lbl_InvoiceTotalValue").innerHTML = formatCurrency(total);
    }    
    return;
}

//THis Gets the shipping total
function drop_get_shipping()
{
//alert(document.getElementById("ctl00_CPH_Body_ddl_Ship").value);
    var shipping_tot = 0
    if (document.getElementById("ctl00_CPH_Body_ddl_Ship") != null)
    {
        if(document.getElementById("ctl00_CPH_Body_ddl_Ship").value != 'USP' && document.getElementById("ctl00_CPH_Body_ddl_Ship").value != 'UPS')
        {
            shipping_tot = 0;
            document.getElementById("ctl00_CPH_Body_Lbl_ShippingTotal").innerHTML = 'Customer Service Will Determine';
        }
        else
        {
            if(document.getElementById("ctl00_CPH_Body_ddl_Ship").value == 'USP')
            {
                shipping_tot = document.getElementById("ctl00_CPH_Body_Hdn_USPS_Price").value
            }
            if(document.getElementById("ctl00_CPH_Body_ddl_Ship").value == 'UPS')
            {
                shipping_tot = document.getElementById("ctl00_CPH_Body_Hdn_UPS_Price").value
            }
            document.getElementById("ctl00_CPH_Body_Lbl_ShippingTotal").innerHTML = formatCurrency(shipping_tot)
        }
    }        
    return shipping_tot;
}    

function Drop_Product_Select_Enable_Boxes(check_box_name, num_of_rows, product_base_name, qty_base_name)
{
    var i = 1
    while(i <= num_of_rows)
    {
        if (document.getElementById("ctl00_CPH_Body_" + check_box_name).checked)
        {
            document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).disabled=false;
            document.getElementById("ctl00_CPH_Body_" + product_base_name + i).disabled=false;
            //document.getElementById("ctl00_CPH_Body_RBT_UPS").disabled=false;
            //document.getElementById("ctl00_CPH_Body_RBT_USPS").disabled=false;
        }
        else
        {
            document.getElementById("ctl00_CPH_Body_" + qty_base_name + i).disabled=true;
            document.getElementById("ctl00_CPH_Body_" + product_base_name + i).disabled=true;
            //document.getElementById("ctl00_CPH_Body_RBT_UPS").disabled=true;
            //document.getElementById("ctl00_CPH_Body_RBT_USPS").disabled=true;
        }
        i++;
    }
    return;
}

//This function checks the see if dropship product select passes verification
function Dropship_Prod_Select_Page_Check(item_name,qty_name,num)
{

    var errormsg = "";
    var i = 1;
    var items_valid = true;
    var passed = true
    var has_items=false;
    var item_save= "";
    var qty_save= "";
    
    while ( i <= num)
    {
        item_save += document.getElementById("ctl00_CPH_Body_" + item_name + i).value + ",";
        qty_save += document.getElementById("ctl00_CPH_Body_" + qty_name + i).value + ",";
        
        if(document.getElementById("ctl00_CPH_Body_" + item_name + i).className == 'redtext')
        {
            items_valid = false;
          
        }
        if(document.getElementById("ctl00_CPH_Body_" + item_name + i).value != 'Enter Product Number' && document.getElementById("ctl00_CPH_Body_" + item_name + i).className != 'redtext' )
        {
            has_items = true;
        }
        i++;
    }
     item_save = item_save.substring(0,item_save.length-1);
     qty_save = qty_save.substring(0,qty_save.length-1);
     document.getElementById("ctl00_CPH_Body_Hdn_SaveQty").value = qty_save
     document.getElementById("ctl00_CPH_Body_Hdn_SaveItem").value = item_save
       
    if (!document.getElementById("ctl00_CPH_Body_Chk_AddressVerification").checked)
    {
        passed = false;
        errormsg = "Please Verify Shipping Address.\n"
    }
    if (document.getElementById("ctl00_CPH_Body_ddl_Ship").value.length < 2)
    {
        passed = false;
        errormsg = errormsg + "Please Select A Shipping Method.\n"
    }
    if(!has_items)
    {
        passed=false;
        errormsg = errormsg+ "Please Enter a Valid Item.\n"
     }

    if (passed)
    {
    
        if(!items_valid)
        {
            alert("Items Not Found Will Not Be Added To This Order.");
        }
        
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
    }
    else
    {
        alert("Please Correct The Following Issues:\n\n" + errormsg);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
    }
    return;
}    


//This Function Checks to see if the address is verified
function Prod_Sel_Verify_Addr(check_shipping)
{
    var passed = true;
    var errorstr = ""
    if (!document.getElementById("ctl00_CPH_Body_Chk_AddressVerification").checked)
    {
        passed = false;
        errorstr = "Please Verify Address.\n"
    }
    if(check_shipping == '1')
    {
        if (document.getElementById("ctl00_CPH_Body_ddl_Ship").value.length < 2)
        {
            passed = false;
            errorstr = errorstr + "Please Select A Shipping Method.\n"
        }
    }
    if(passed)
    {
         document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "True"
    }
    else
    {
        alert("Please Correct The Following Issues:\n\n" + errorstr);
        document.getElementById("ctl00_CPH_Body_Hdn_Validate").value = "False"
    
    }
    return;
}

//This Fucntion Confirms the Cancel
function dropship_cancel_click(hdn_name)
{
    if(confirm("This Will Delete All Orders On This Page. Whould You Like To Continue?\n\nClick OK To Delete All These Orders.\n\nClick Cancel To Keep All These Orders."))
    {
        document.getElementById("ctl00_CPH_Body_" + hdn_name).value = "True";
    }
    return;
}    

function bulk_product_search_ready_values(count)
{
//store the values to be added into items table
var Qty = document.getElementById("ctl00_CPH_Body_txt_Qty_" + count).value
var stockid = document.getElementById("ctl00_CPH_Body_Hdn_stock_id_" + count).value

//alert(stockid);
if (document.getElementById("ctl00_CPH_Body_hdn_item_count").value >= 5)
{
    alert("Quick Add Menu Full.\nPlease Return And Add These Items To Your Cart.\n");   
}
else
{
//    if (isNaN(Qty))
    if(Qty <= -1 || isNaN(Qty))
    {
        alert("Please enter a valid number");
    }
    else
    {
        //if add blanks to cart then you get at least 1 in the cart.
        if (Qty == "") {Qty = 1;}
        document.getElementById("ctl00_CPH_Body_hdn_addtocart").value = stockid + "," + Qty;
        document.getElementById("ctl00_CPH_Body_hdn_addtocart_bool").value = "True";
        alert("Item added to your cart");
    }
}

return;
}

//This funciton returns the correct Price for the Item
function get_price_drop(pricestr,qty)
{
    if (pricestr != null)
    {
        var priceary = pricestr.split("|")
        var returnprice = 10000000000;
        var pricepairarray = ",,,,".split(",")
        var i = 0
        while (priceary[i] != null)
        {
            pricepairarray = priceary[i].split("~")
            if (pricepairarray[1] <= qty && pricepairarray[0] < returnprice)
            {
                returnprice = pricepairarray[0];          
            }
            i++;
        }
        
       return returnprice;
    }   
    else
    {
        return 0;
    }
} 


function update_price_drop(item_name, price_base_name, qty_name, num)
{

       var i = 0;
    var found = 0;
    var item_array = document.getElementById("ctl00_CPH_Body_Hdn_Items").value.split(",");
    var price_array = document.getElementById("ctl00_CPH_Body_Hdn_Prices").value.split(",");
       while (item_array[i] != null)
        {
            if (document.getElementById("ctl00_CPH_Body_" + item_name + num).value == item_array[i])
            {
             document.getElementById("ctl00_CPH_Body_" + price_base_name + num).innerHTML = formatCurrency_No_Dollar_Sign(get_price_drop(price_array[i],document.getElementById("ctl00_CPH_Body_" + qty_name + num).value));
            break;
            }
        i++;
        }
    return;
}    



//this function activates and disbles answers in the update upums page
function pump_page_update()
{
    //Hide All
    document.getElementById("ctl00_CPH_Body_Pnl_O3").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O1").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O2").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O2_O1").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O3_O1").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O3_O2").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O3_O3").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O3_O4").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O4_O1").disabled=true;
    document.getElementById("ctl00_CPH_Body_Pnl_O4_O2").disabled=true;
   
   
   
   //Option 1
    if (document.getElementById("ctl00_CPH_Body_RB_Free_Backup").checked)
    {
        document.getElementById("ctl00_CPH_Body_Pnl_O1").disabled=false;
    }
    
    //Option 2
    if (document.getElementById("ctl00_CPH_Body_RB_Free_Cell").checked)
    {
        document.getElementById("ctl00_CPH_Body_Pnl_O2").disabled=false;
        //Check Box Insulin
        if(document.getElementById("ctl00_CPH_Body_Chk_02_Pump").checked)
        {
            document.getElementById("ctl00_CPH_Body_Pnl_O2_O1").disabled=false;
        }
    }
    
    //Option 3
    if (document.getElementById("ctl00_CPH_Body_RB_Free_Infusion").checked)
    {
        document.getElementById("ctl00_CPH_Body_Pnl_O3").disabled=false;
        
        //Ultra
        if(document.getElementById("ctl00_CPH_Body_RB_O3_Ultra").checked)
        {
            document.getElementById("ctl00_CPH_Body_Pnl_O3_O1").disabled=false;
        }  
        
        //Tender
        if(document.getElementById("ctl00_CPH_Body_RB_O3_Tender").checked)
        {
            document.getElementById("ctl00_CPH_Body_Pnl_O3_O2").disabled=false;
        }  

        //Rapid
        if(document.getElementById("ctl00_CPH_Body_RB_O3_Rapid").checked)
        {
            document.getElementById("ctl00_CPH_Body_Pnl_O3_O3").disabled=false;
        }  
        
        //Insulin Pump
        if(document.getElementById("ctl00_CPH_Body_Chk_O3_Pump").checked)
        {
            document.getElementById("ctl00_CPH_Body_Pnl_O3_O4").disabled=false;
        }  

    }
    
    //TriCot
    if (document.getElementById("ctl00_CPH_Body_RB_Tricot").checked)
    {
        document.getElementById("ctl00_CPH_Body_Pnl_O4_O1").disabled=false;
    }
 
 
    
    //Alcantara
    if (document.getElementById("ctl00_CPH_Body_RB_Alcantara").checked)
    {
        document.getElementById("ctl00_CPH_Body_Pnl_O4_O2").disabled=false;
    }
 
}

//This Function Checks for errors on the pump upgrade page
function pump_page_Check_Error()
{
}