﻿

function clearTextBox(textBox, defaultValue)
{
  if (textBox.value == defaultValue)
  {
    textBox.value = "";
  }
}

function populateTextBox(textBox, defaultValue)
{
  if (textBox.value == "")
  {
    textBox.value = defaultValue;
  }
}

/*
this function is basically used for checking the price if price is zero than form should not be submit
*/
 function validatePriceWithForm(myForm)
 {
    var flagval = parseInt(document.getElementById('hdnFlag').value); 
    
    var objForm = eval("document." + myForm);
    
    var priceStatus = true; 
    if(flagval>0) 
    { 
        
        objForm.IsWishList.value='0';
        objForm.IsGiftRegistry.value='0';
        if(validateForm(objForm) &&  eval(myForm +"_Validator(document.getElementById('" + myForm + "'))" )   ) 
        {
            objForm.submit();
        }
    } 
    else
    {
        alert('Selected Comination doesn\'t have price select another !');
        priceStatus=false;     
    }
    
    
 }

var DefaultPrice=0;

function FetchingValue(IsDefaultPrice)
{
DefaultPrice =IsDefaultPrice;

var UrlString='';

var ddlMat = document.getElementById('ddlMaterial');
var ddlWidth = document.getElementById('ddlWidth');
var ddlHeight = document.getElementById('ddlHeight');
var ddlInch = document.getElementById('ddlInchFraction');
var ddlFinish = document.getElementById('ddlFinish');

/*
//By Faisal
var txtW=ddlWidth.options[ddlWidth.options.selectedIndex].text;
var intF= (txtW-Math.floor(txtW));
if(intF=='0'){
    var intDec= '0.0';
 }else{
    var intDec= intF;
 }
ddlInch.setfocus;
for (k=0;k<ddlInch.options.length;k++) {
    if (ddlInch.options[k].text == intDec) {
        ddlInch.options[k].selected = true;
        break;
    }
}
// By Faisal
*/

if(ddlMat==null){
    var valMat=0;
}else{
    var valMat = ddlMat.options[ddlMat.options.selectedIndex].value;
}
var valWidth = ddlWidth.options[ddlWidth.options.selectedIndex].value;
var valHeight = ddlHeight.options[ddlHeight.options.selectedIndex].value;
var valInch = ddlInch.options[ddlInch.options.selectedIndex].value;
if(ddlFinish==null){
    var valFinish=0;
}else{
    var valFinish = ddlFinish.options[ddlFinish.options.selectedIndex].value;
}
var valCatId = document.getElementById('hdnCategory').value;
UrlString ="AjaxServer.aspx?valMat="+valMat+"&valWidth="+valWidth+"&valHeight="+valHeight+"&valInch="+valInch+"&valCategory="+valCatId+"&valFinish="+valFinish+"";
SendRequest(UrlString);

}


function SendRequest(url)
{
//netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
if (window.XMLHttpRequest) 
{ // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
} 
else if (window.ActiveXObject) 
{ // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
}

http_request.onreadystatechange = ShowResponse;
http_request.open('GET', url, true);
http_request.send(null);
}
function ShowResponse()
{
    var VariantId = document.getElementById('hdnPrice').value;
    var ext = extData();
    
    if (http_request.readyState == 4)
    {
    
        //alert("http_request.readyState: " + http_request.readyState);
        //alert("http_request.status: " + http_request.status );
     
        if (http_request.status == 200)
            {
            var wholeText = http_request.responseText;
            var priceVal = wholeText.split("§");
            var PriceEx = wholeText.indexOf("§");
                      
                if(parseInt(PriceEx)>0)
                {
                    //document.getElementById("dvPrice").innerHTML = 'Price Rate :' + priceVal[0];
                    document.getElementById("PriceID").value = priceVal[0];
                    document.getElementById("hdnCombinationId").value = priceVal[1];
                    document.getElementById("VariantPrice"+"_"+VariantId).innerHTML="<span class='variantprice'><span class='LblProductPrice'>Your Price:</span>&nbsp;$"+priceVal[0]+ " " + ext +"</span>";
                    
                    if(parseInt(priceVal[0])>0)
                    {
                     document.getElementById("hdnFlag").value=1;
                    }
                    else
                    {
                     document.getElementById("hdnFlag").value=0;
                    }                 
                 
                 }
                else
                {
                    document.getElementById("hdnCombinationId").value = 0;
                    document.getElementById("PriceID").value = '';
                    document.getElementById("hdnFlag").value=0;
                   //  document.getElementById("VariantPrice"+"_"+VariantId).innerHTML='';
                   if(DefaultPrice==0)
                    {
                      document.getElementById("VariantPrice"+"_"+VariantId).innerHTML='';
                    }                
                    
                }
            }
        else
        {
           alert("Oops!!\r\n\r\nCan't send your information. Please try later!!");
        }
    }
}

function setKit()
{
    var TotalKitGroups = document.getElementById('hdnTotalKitGroups');
    var hidnKit = document.getElementById('hdnKit');
    var hdnKitVal='';
    var KitGroup;
    
    for (i=1;i<=TotalKitGroups.value;i++) 
    {
        KitGroup = document.getElementById('KitGroup_'+i);  
        hdnKitVal=hdnKitVal + KitGroup.name +","+ KitGroup.options[KitGroup.options.selectedIndex].value + "|";
    }    
    hidnKit.value=hdnKitVal;
    
}

function setFinish(sFinishid)
{
    var ddlFinish = document.getElementById('ddlFinish');
    ddlFinish.value=sFinishid;
    
}