﻿// JScript File
var rules=new Array();
    rules[0]='ctl00_ContentPlaceHolder1_txtQuantity|required|Please enter product quantity';
    rules[1]='ctl00_ContentPlaceHolder1_txtQuantity|integer|Please enter valid product quantity number';
    rules[2]='checkQuantity()|custom';
function checkQuantity()
{
    var val=parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_txtQuantity').value);
    if(val<1)
        return "Product Quantity must be greater than zero";
//    else if(parseInt(document.getElementById('ctl00_ContentPlaceHolder1_txtQuantity').value)>parseInt(document.getElementById('ctl00_ContentPlaceHolder1_hdnQuantity').value))
//        return "Product Quantity must be less than avaliable quantity";
    else
        return null; 
}

//----------------------------------------
// JScript File
var lastImage='';
var lastImgSRC='';
var lastDiv='';
function AjaxCall(querystring)
{
     try
    {// Firefox, Opera 8.0+, Safari, IE7
         xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {// Old IE
        try
        {
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e)
        {
            alert ("Your browser does not support XMLHTTP!");
            return;  
        }
    }
    var url="handlers/ajaxHandler.ashx"+querystring; 
    url=url+"&sid="+Math.random();  
    //alert(url);   
    xmlHttp.open("GET",url,false);
    xmlHttp.send(null);
    return xmlHttp.responseText;
}
function grayOut(vis, options,check,secondDiv) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
//  alert(options.zindex);
//  alert(options.opacity);
//  alert(options.bgcolor);
//  
    var check=check;
  var options = options || {}; 
 
  var zindex = options.zindex || 50;
   var opacity = options.opacity || 70;
   var opaque = (opacity / 100);
   var bgcolor = options.bgcolor || '#C0C0C0';
   var dark;
   if(secondDiv!='1')
    dark=document.getElementById('darkenScreenObject');
   else
    dark=document.getElementById('darkenScreenObject1');
   
   
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        if(secondDiv!='1')
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
        else
        tnode.id='darkenScreenObject1';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    if(secondDiv!='1')
        dark=document.getElementById('darkenScreenObject');  // Get the object.
    else
        dark=document.getElementById('darkenScreenObject1');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 

var _docHeight = document.height || document.body.offsetHeight;
var _docWidth ;
//Mozzila 
if (window.innerHeight && window.scrollMaxY) 
{
    _docWidth=window.innerWidth + window.scrollMaxX;
}
// IE 7
else if (document.body.scrollWidth > document.body.offsetWidth)
{
   _docWidth= document.body.scrollWidth;
}
// Older version of IE
else
{
_docWidth=document.body.offsetWidth;

}
// Setting up the Div That will come in front .....
       var pageWidth=_docWidth+"px";
       var pageHeight=_docHeight+'px';
       if (check=='1')
       {
        scroll();
       }
    //set the shader to cover the entire page and make it visible.
       
      
    dark.style.opacity=opaque;  
                      
    dark.style.MozOpacity=opaque;   
                    
    dark.style.filter='alpha(opacity='+opacity+')'; 
      
    dark.style.zIndex=zindex;      
   
    dark.style.backgroundColor=bgcolor;  
   
    dark.style.width= pageWidth;
    
    dark.style.height= pageHeight;
    
    dark.style.display='block';                          
    
  } else {
     dark.style.display='none';
  }
 
}
function genderClick(type,id)
{
 fadeIn();

document.getElementById('td_addToCart').style.visibility='hidden';
document.getElementById('td_sizes').innerHTML='';

  
   document.getElementById('td_colors').innerHTML=AjaxCall('?gender='+type+'&prodid='+id);
      fadeOut();
    if (type=='M')
 {
    document.getElementById('idM').src="images/inner/maleblue.gif";
        if(document.getElementById('idF'))
        {
        document.getElementById('idF').src="images/inner/femaleblack.gif";
        }
    }
    if(type=='F')
    {
     if(document.getElementById('idM'))
     {
        document.getElementById('idM').src="images/inner/maleblack.gif";
    }
    document.getElementById('idF').src="images/inner/femaleblue.gif";
    }

   
   
}
function colorClick(color,type,id,divId)
{

if(lastDiv!='' && lastDiv!=null &&  document.getElementById(lastDiv))
{
   
    document.getElementById(lastDiv).style.borderWidth="0";
    document.getElementById(lastDiv).style.borderColor="black";
    document.getElementById(lastDiv).style.borderStyle="none";
   
}
    lastDiv=divId.id;
    //alert("latest" + divId.id);
    divId.style.borderWidth="1";
    divId.style.borderColor="black"
    divId.style.borderStyle="groove"
    fadeIn();
    document.getElementById('td_sizes').innerHTML=AjaxCall('?gender='+type+'&prodid='+id+'&color='+color);
    fadeOut();
   
}
function sizeClick(color,type,id,size,controlid)
{
var altimage;

if (controlid.id=='smallsize')
{
altimage='smallblack.gif';
}
else if (controlid.id=='largesize')
{
altimage='largeblack.gif';
}

else if (controlid.id=='mediumsize')
{
altimage='mediumblack.gif';
}
else if (controlid.id=='xsmallsize')
{
altimage='xsblack.gif';
}

else if (controlid.id=='xlargesize')
{
altimage='xlblack.gif';
}
if(lastImage!='' && lastImgSRC!='' && lastImage!=null && lastImage!=null &&  document.getElementById(lastImage))
{
    document.getElementById(lastImage).src=lastImgSRC;
}
lastImage=controlid.id;
lastImgSRC=controlid.src;
controlid.src="Images/size/"+altimage;
    fadeIn();
   document.getElementById('imgProduct').src
   document.getElementById('imgProduct').src=AjaxCall('?gender='+type+'&prodid='+id+'&color='+color+'&size='+size);
  var imgname=AjaxCall('?gender='+type+'&prodid='+id+'&color='+color+'&size='+size);
  
    document.getElementById('txtAttributes').value=id+';'+type+';'+color+';'+size+';'+imgname;
    document.getElementById('td_addToCart').style.visibility='visible';
   
    
   
     fadeOut();
   // alert(document.getElementById('txtAttributes').value);
    
}

function fadeIn()
{
    grayOut(true,{'opacity':'60' , 'zindex':'27','bgcolor':'#FFFFFF' },'','0');
    document.getElementById('loadingDiv').style.display='block';
    document.getElementById('loadingDiv').style.left=parseInt(screen.width)/2+"px";
    document.getElementById('loadingDiv').style.top=parseInt(screen.height)/2+"px";
}
function fadeOut()
{
 document.getElementById('loadingDiv').style.display='none';
 grayOut(false,{},'','0');
     
}
function addToCart(type)
{
    if(document.getElementById('txtQuantity').value=='' || 
        document.getElementById('txtQuantity').value=='0' 
        ||eval(document.getElementById('txtQuantity').value) < 0)
        {
            alert('Please Enter a valid Quantity for adding product into your '+type+'.');
            return false;
        }
        
        else
        return true;
}

