function GetResourceString(lKey, sDefaultValue){
  return sDefaultValue;
}
function Added() {
  alert(GetResourceString(81074, 'Your item has been added to your shopping cart'));
}
function OnLoad() {}

//--- Ajax implementation---//

function loadShippingMethods(countryID, prefix, useShipping)
{
  var xmlHttp = GetXmlHttpObject();
  if (xmlHttp != null)
  {
    var stateID='', postalCode='';
    var sel = document.getElementById('ShippingMethodID');
        if(sel != null) {
            //sel.disabled = true;
      while (sel.length > 0) {
        sel.options[0] = null;
      }
    }
    sel = find_object(prefix + 'StateID');
        if(sel != null) stateID = sel.value;
        sel = find_object(prefix + 'PostalCode');
        if(sel != null) postalCode = sel.value;
        
    var url = "ajax_contact.asp?OrderID="+sOrderID+"&CountryID="+countryID+"&GroupID="+sGroupID+"&Prefix="+prefix+"&UseShipping="+useShipping+"&StateID="+stateID+"&PostalCode="+postalCode;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
            try{
                   eval(xmlHttp.responseText)
                }
                catch(e){};
            }
    };
    if (window.XMLHttpRequest){
            xmlHttp.open("GET",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("GET",url,false);
        }
    xmlHttp.send(null);
  }
  else
  {
    Refresh();
  }
}

// update billinginfo and promotes order to open status
function updateBillingInfo(form){
  if(null == document.getElementById("ExpressCheckout"))
      return;
      
  if("undefined" == typeof(form)) return;
  
  var arrRequired = new Array("Contact_FirstName", "Contact_LastName", "Contact_Phone", 
          "Contact_Email", "Address_City", "Address_PostalCode", "Address_Address");
          
  var i;
  for(i=0; i<arrRequired.length; i++)
      if(form[arrRequired[i]].value == "") return;
  
    var xmlHttp = GetXmlHttpObject();
  if (xmlHttp != null){
        var progressDiv = find_object("progress_div");
    if(progressDiv != null) progressDiv.display();
      
      var tmp = form.Action.value;
    form.Action.value = "ajax-updatebilling";
    var querystring = getFormElements(form);
    form.Action.value = tmp;
        
        var url = "ajax_order.asp";
    
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            try{
                var progressDiv = find_object("progress_div");
                if(progressDiv) progressDiv.hide();
            }
            catch(e){
                //alert(e);
            }
            finally{
                    var progressDiv = find_object("progress_div");
                    if(progressDiv) progressDiv.hide();
                };
        }
    }
    if (window.XMLHttpRequest){
            xmlHttp.open("POST",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("POST",url,false);
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
  }
}

function refreshOrder(el, recalculate)
{
  if(document.getElementById('ExpressCheckout') == null)
      return;
      
  // in case there is no payment section and order total can change
  // call recalculate instead of refresh
  if (el.form.PaymentMethodID == null) {
      recalculateOrder();
      return;
  }
  
    var xmlHttp=GetXmlHttpObject();
  if (xmlHttp != null)
  {
        var progressDiv = find_object('progress_div');
    if(progressDiv != null) progressDiv.display();
    var prefix = '';
    if('shipaddress' == document.getElementById('ShipDestination').value){
        /*if('undefined' != typeof(el))
            if('Address_StateID' == el.name)
                return;*/
        prefix = 'ShippingInfo_';
    }
    var elState = document.getElementById(prefix + 'Address_StateID');
    var lStateID='';
    if(elState != null){
        lStateID = elState.value;
    }
    
    var elPostalCode = document.getElementById(prefix + 'Address_PostalCode');
    var sPostalCode='';
    if(sPostalCode != null){
        sPostalCode = elPostalCode.value;
    }
    
    /*var elState = document.getElementById(prefix + 'ShippingInfo_Address_StateID');
    if(elState){
        elState.value = lStateID;
    }*/
    
    var elShipping = document.getElementById('ShippingMethodID');
    var lShippingMethodID='';
    if(elShipping != null){
        lShippingMethodID = elShipping.value;
        elShipping.disabled = true;
    }

    var elPayment = document.getElementById('PaymentMethodID');
    var lPaymentMethodID='';
    if(elPayment != null){
        lPaymentMethodID = elPayment.value;
    }
    
    var url = "ajax_contact.asp?CurrentOrderID=" + sOrderID + "&CurrentShippingMethodID=" + lShippingMethodID + "&StateID=" + lStateID + "&Prefix=" + prefix + "&PostalCode=" + sPostalCode + "&PaymentMethodID=" + lPaymentMethodID;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                try{
                eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
            }
            catch(e){}
            finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                };
            }
    };
    if (window.XMLHttpRequest){
            xmlHttp.open("GET",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("GET",url,false);
        }
    xmlHttp.send(null);
  }
  else
  {
    if('undefined' == typeof(recalculate))
        Refresh();
    else{
        el.form.Action.value='recalculate';
        el.form.submit();
    }
  }
}

function recalculateOrder(){
    if(null == document.getElementById('ExpressCheckout'))
      return;
    var xmlHttp=GetXmlHttpObject();
  if (xmlHttp != null){
        var progressDiv = find_object('progress_div');
    if(progressDiv != null) progressDiv.display();
      var form = document.fmCheckout;
    var tmp = form.Action.value;
    form.Action.value = 'ajax-recalculate';
    var querystring = getFormElements(form);
    form.Action.value = tmp;
        //var url = 'expresscheckout.asp?'+querystring;
        var url = 'expresscheckout.asp';
    var sel = document.getElementById('ShippingMethodID');
      while (sel.length > 0){
          sel.options[0] = null;
      }
      sel.disabled = true;
      xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                try{
                sel.disabled = false;
                eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
            }
            catch(e){
                //alert(e);
            }
            finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                };
            }
    }
    if (window.XMLHttpRequest){
            xmlHttp.open("POST",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("POST",url,false);
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
//alert(querystring);
  }
  else{
      var el=find_object('tdRecalculate');
        if(el != null) el.style.display='block';
    }
}

function selectForm(paymentType)
{
  var pCheckForm = document.getElementById('check-form');
  var pCardForm = document.getElementById('card-form');
  var pTitle = document.getElementById('title_grid');
  var pTitleSpace = document.getElementById('title_grid_space');

  pCardForm.style.display = 'none';
  pCheckForm.style.display = 'none';
  pTitle.style.display = 'none';
  pTitleSpace.style.display = 'none';

  if (paymentType == 'card')
  {   
    pCardForm.style.display = 'inline';
    pTitle.style.display = 'inline';
    pTitleSpace.style.display = 'inline';     
  }
  
  if (paymentType == 'check')
  {
    pCheckForm.style.display = 'inline';
    pTitle.style.display = 'inline';
    pTitleSpace.style.display = 'inline';     
  } 
  
}

function openAddressBookItem(id,customerID,paymentType)
{
  var xmlHttp=GetXmlHttpObject()
  
  if ((paymentType != 'card') && (paymentType != 'check')) {
    paymentType = '';
  }

  if (xmlHttp && (customerID.length > 0) && (id > 0)){
        var progressDiv = find_object('progress_div');
    if(progressDiv) progressDiv.display();
    document.fmObject.ID.value = id.toString();
    document.fmObject.Action.value = 'update';
  
    setValue('Contact_FirstName','');
    setValue('Contact_LastName','');
    setValue('Contact_Company','');
    setValue('Address_Address','');
    setValue('Address_Address2','');
    setValue('Address_City','');
    setValue('Address_PostalCode','');
    setValue('Address_CountryID','');
    setValue('Contact_Phone','');
    setValue('Contact_Email','');

    var pPaymentType = document.getElementById('PaymentType');
    setValue('PaymentType',paymentType);
    pPaymentType.disabled = true;
    
    var pCheckForm = document.getElementById('check-form');
    var pCardForm = document.getElementById('card-form');
    var pTitle = document.getElementById('title_grid');
    var pTitleSpace = document.getElementById('title_grid_space');
    var pRemoveButton = document.getElementById('remove-button');

    pCardForm.style.display = 'none';
    pCheckForm.style.display = 'none';
    pTitle.style.display = 'none';
    pTitleSpace.style.display = 'none';
    pRemoveButton.style.display = 'inline'

    setValue('CashAssets_Name','');
    
    setValue('Type','');
    setValue('Number','');
    setValue('Name_cardholder','');
    setValue('ExpMonth','1');
    setValue('ExpYear','2007');
    
    setValue('Bank','');
    setValue('AccountNumber','');
    setValue('RoutingNumber','');
    setValue('BankAddress','');
    setValue('BankPhone','');
    setValue('FederalID','');   

    if (paymentType == 'card')
    {
      pTitle.style.display = 'inline';
      pTitleSpace.style.display = 'inline';
      pCardForm.style.display = 'block';
    }

    if (paymentType == 'check')
    {
      pTitle.style.display = 'inline';
      pTitleSpace.style.display = 'inline';
      pCheckForm.style.display = 'block';
    }

    var sel = document.getElementById('Address_StateID');

    while (sel.length > 0) {
      sel.options[0] = null;
    }
    
    if (window.ActiveXObject)
    {
      var td1 = document.getElementById('Address_StateID_1');
      var td2 = document.getElementById('Address_StateID_2');
      
      sel.disabled=true;
      td1.style.display='none';
      td2.style.display='none';
    }   

    var url = "ajax_contact.asp?AddressBookItemID="+id+"&ClientID="+customerID+"&PaymentType="+paymentType;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                if(progressDiv != null) progressDiv.hide();
            } 
    }
     if (window.XMLHttpRequest)
     {
        xmlHttp.open("GET",url,true);
     }
     else if (window.ActiveXObject)
     {
        xmlHttp.open("GET",url,false);
     }
    xmlHttp.send(null);
  }
  else{
    window.location = location.pathname + "?ID="+id;
  }
}

function setValue(elementID, elementValue)
{
  var el = document.getElementById(elementID);
  if (el != null)
    el.value = elementValue;
    else{
        // try to find in forms
        for(i=0;i < document.forms.length; i++){
            el = document.forms[i].elements[elementID]
            if(el != null){
                el.value = elementValue;
                return;
            }
        }
    }
}

function loadAddressBook(addrBookID, prefix, clientID)
{
  var xmlHttp=GetXmlHttpObject();
  if (xmlHttp){
    if (addrBookID != 'empty')
    {
            var progressDiv = find_object('progress_div');
            if(progressDiv) progressDiv.display();
      //New address
      if (addrBookID == -1)
      {
        setValue(prefix+'Contact_FirstName','');
        setValue(prefix+'Contact_LastName','');
        setValue(prefix+'Contact_Company','');
        setValue(prefix+'Address_Address','');
        setValue(prefix+'Address_Address2','');
        setValue(prefix+'Address_City','');
        setValue(prefix+'Address_PostalCode','');
        setValue(prefix+'Address_CountryID','');
        setValue(prefix+'Contact_Phone','');
        setValue(prefix+'Contact_Email','');

        var sel = document.getElementById(prefix+'Address_StateID');

        while (sel.length > 0) {
          sel.options[0] = null;
        }
        
        if (window.ActiveXObject)
        {
          var td1 = document.getElementById(prefix + 'Address_StateID' + '_1');
          var td2 = document.getElementById(prefix + 'Address_StateID' + '_2');
          
          sel.disabled=true;
          td1.style.display='none';
          td2.style.display='none';
        }
      }

      //Copy Billing info to Shipping
      if (addrBookID == 0)
      {
        document.getElementById(prefix+'AddressBookItem').value = 'empty';

        setValue(prefix+'Contact_FirstName',document.getElementById('Contact_FirstName').value);
        setValue(prefix+'Contact_LastName',document.getElementById('Contact_LastName').value);
        setValue(prefix+'Contact_Company',document.getElementById('Contact_Company').value);
        setValue(prefix+'Address_Address',document.getElementById('Address_Address').value);
        setValue(prefix+'Address_Address2',document.getElementById('Address_Address2').value);
        setValue(prefix+'Address_City',document.getElementById('Address_City').value);
        setValue(prefix+'Address_PostalCode',document.getElementById('Address_PostalCode').value);
        setValue(prefix+'Address_CountryID',document.getElementById('Address_CountryID').value);
        setValue(prefix+'Contact_Phone',document.getElementById('Contact_Phone').value);
        setValue(prefix+'Contact_Email',document.getElementById('Contact_Email').value);

        var sel = document.getElementById(prefix+'Address_StateID');

        while (sel.length > 0) {
          sel.options[0] = null;
        }
        
        //if (window.ActiveXObject){
          var td1 = document.getElementById(prefix + 'Address_StateID' + '_1');
          var td2 = document.getElementById(prefix + 'Address_StateID' + '_2');
          
          sel.disabled=true;
          td1.style.display='none';
          td2.style.display='none';
        //}
        
        if (document.getElementById('Address_StateID').value > 0)
        {
          loadStates(document.getElementById('Address_CountryID').value,prefix);
          document.getElementById(prefix+'Address_StateID').value = document.getElementById('Address_StateID').value;
        }
      }
      
      //Load Address from Address Book
      if (addrBookID > 0)
      {   
        var url = "ajax_contact.asp?AddressBookID="+addrBookID+"&Prefix="+prefix+"&ClientID="+clientID;
        xmlHttp.onreadystatechange = function(){
             if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                    eval(xmlHttp.responseText);
                        var progressDiv = find_object('progress_div');
                        if(progressDiv != null) progressDiv.hide();
                    var el;
                        if(el=document.getElementById('tdRecalculate')) el.style.display='block';
                    }
        }
         if (window.XMLHttpRequest)
         {
            xmlHttp.open("GET",url,true);
         }
         else if (window.ActiveXObject)
         {
            xmlHttp.open("GET",url,false);
         }
        xmlHttp.send(null);
      }
    }
  }
  else
  {
    //Copy(this,prefix); //For Mozilla Firefox using old conception
  }
}

function loadStates(countryID, prefix)
{
  if (find_object('ExpressCheckout')) {
    recalculateExpressCheckout(countryID, prefix);
  }
  
  if (countryID > 0)
  {
        var progressDiv = find_object('progress_div');
    if(progressDiv != null) progressDiv.display();
    if (prefix == "undefined") prefix = "";
    statePrefix = prefix + "Address_StateID";
        var sel = document.getElementById(statePrefix); //Object of <select> with id="{$prefix}Address_StateID"
      var xmlHttp=GetXmlHttpObject();
    if (xmlHttp != null)
    {
      while (sel.length > 0) {
            sel.options[0] = null;
          }
            sel.disabled = true;
    }
    else{
        sel.form.action=location;
        Refresh();
        return;
    }

    var url="ajax_contact.asp?CountryID="+countryID+"&Prefix="+statePrefix;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            try{
                eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
            }
            catch(e){
            }
            finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                };
            } 
    }
    if (window.XMLHttpRequest){
        xmlHttp.open("GET",url,true);
    }
    else if (window.ActiveXObject){
        xmlHttp.open("GET",url,false);
    }
    xmlHttp.send(null);
  }
}

function recalculateExpressCheckout(countryID, prefix){
    /*var ShipDestination = document.fmCheckout.ShipDestination;
  theone = 0;
  if(document.getElementById('ShippingMethodID')) {
      theone = ('shipaddress' == ShipDestination.value)?1:0;
    var shippingMethod = document.getElementById('ShippingMethodID').value;
    loadShippingMethods(countryID, prefix, theone);
    var shipping = document.getElementById('ShippingMethodID');
    var i = 1;
    while (i < shipping.length) {
      if (shipping.options[i].value == shippingMethod)
      {
        document.getElementById('ShippingMethodID').value = shippingMethod;
      }
      i++;
    }
  } else {
    loadShippingMethods(countryID, prefix, theone);
  }*/
  recalculateOrder();
  //loadPayments();
}

function shipDestinationChanged(el){
    changeDiv('shippinginfo', ('shipaddress' == el.value)?'block':'none');
    var prefix = ('shipaddress' == el.value)?'ShippingInfo_':'';
    
    if (document.getElementById('ExpressCheckout')) {
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp != null)
        recalculateExpressCheckout(find_object(prefix + 'Address_CountryID').value, prefix);
    else{
        el.form.Action.value='recalculate';
        el.form.submit();
    }
  }
}

function loadPayments(){
    var xmlHttp = GetXmlHttpObject();
    var settlePayment = false;
    if (xmlHttp)
  {
        var progressDiv = find_object('progress_div');
    if(progressDiv != null) progressDiv.display();
    var form = document.fmCheckout;
    if(!form){
      form = document.fmSettlePayment;
      settlePayment = true;
    }
    var tmp = form.Action.value;
    form.Action.value = 'ajax-payment-method';
    var querystring = getFormElements(form);
    form.Action.value = tmp;

    var url = ((settlePayment)?'settlepayment.asp?':'expresscheckout.asp?');

    xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
            try{
                    var sResponse = xmlHttp.responseText;
                    if(sResponse != ''){
                      var divPaymentMethodContainer = find_object('divPaymentMethodContainer');
                      if(divPaymentMethodContainer != null) divPaymentMethodContainer.innerHTML = sResponse;
                      var progressDiv = find_object('progress_div');
                        if(progressDiv) progressDiv.hide();
                  }
                }
                catch(e){}
                finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                };
            }
    }
    if (window.XMLHttpRequest){
        xmlHttp.open("POST",url,true);
    }
    else if (window.ActiveXObject){
        xmlHttp.open("POST",url,false);
    }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
  }
  else
  {
    Refresh();
  }
}

function accumulateQueryString(queryString, newValues) {
    if(queryString == "") {
        queryString = newValues; 
    }
    else {
        queryString = queryString + "&" +  newValues;
    }
    return queryString;
}
    
function getFormElements(form){
    var querystring='';
    var formElements = new Array();
    if (form != null) {
        if (typeof form == "string") {
            var el = document.getElementById(form);
            if (el != null) {
                formElements = el.elements;
            }
        } else {
            formElements = form.elements;
        }
    }
    var values = toQueryString(formElements);
    return accumulateQueryString(querystring, values);
}

/** @private */
function toQueryString(elements) {
    var node = null;
    var qs = "";
    var name = "";
    
    var tempString = "";
    for(var i = 0; i < elements.length; i++) {
        tempString = "";
        node = elements[i];
        
        name = node.getAttribute("name");
        //use id if name is null
        if (!name) {
            name = node.getAttribute("id");
        }
        name = encodeURIComponent(name);
        
        if(node.tagName.toLowerCase() == "input") {
            if(node.type.toLowerCase() == "radio" || node.type.toLowerCase() == "checkbox") {
                if(node.checked) {
                    tempString = name + "=" + encodeURIComponent(node.value);
                }
            }
            
            if(node.type.toLowerCase() == "text" || node.type.toLowerCase() == "hidden" || node.type.toLowerCase() == "password") {
                tempString = name + "=" + encodeURIComponent(node.value);
            }
        }
        else if(node.tagName.toLowerCase() == "select") {
            tempString = getSelectedOptions(node);
        }
        
        else if(node.tagName.toLowerCase() == "textarea") {
            tempString = name + "=" + encodeURIComponent(node.value);
        }
        
        if(tempString != "") {
            if(qs == "") {
                qs = tempString;
            }
            else {
                qs = qs + "&" + tempString;
            }
        }
        
    }
    
    return qs;
}

/** @private */
function getSelectedOptions(select) {
    var options = select.options;
    var option = null;
    var qs = "";
    var tempString = "";
    
    for(var x = 0; x < options.length; x++) {
        tempString = "";
        option = options[x];
        
        if(option.selected) {
            tempString = encodeURIComponent(select.name) + "=" + encodeURIComponent(option.value);
        }
        
        if(tempString != "") {
            if(qs == "") {
                qs = tempString;
            }
            else {
                qs = qs + "&" + tempString;
            }
        }
    }
    
    return qs;
}
//---//

//-----AJAX routine-----//
function GetXmlHttpObject()
{ 
 var xmlHttp1 = false;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp1=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP"); //IE 6.0+
      }
    catch (e)
      {
      try
        {
        xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP"); //IE 5.5+
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
 return xmlHttp1;
}
//---//

function openWindow(url, name, width, height, features) {
  var win;
  var top = 0;
  var left = 0;
  
  if (screen.width > width) left = (screen.width - width) / 2;
  if (screen.height > height) top = (screen.height - height) / 2;
  
  if (typeof(features) == "undefined") win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height);
  else win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height +', ' + features);
    
  if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
}
//------------image expancion--------------//

function preview(imgSource, id){
  var divElement = find_object('preview_div'+id);
  var imgElement = find_object('preview_img'+id);
  var imgThumb = find_object('thumb_img'+id);
  //var imgElement = divElement.firstChild.firstChild.firstChild.firstChild.firstChild.firstChild;
  //alert(imgElement.nodeName);
  
  if(!divElement || !imgElement) return;
  var top = 0;
  var left = 0;
  var width = parseInt(divElement.style.width);
  var height = parseInt(divElement.style.height);
  //if (screen.width > width) left = (screen.width - width)/2;
  //if (screen.height > height) top = (screen.height - height)/2;
    
  divElement.style.display = 'inline';
  
  init(imgElement, imgThumb);
  
  if (imgElement.inited){
    //divElement.style.width=imgElement.originalWidth;
    //divElement.height=imgElement.originalHeight;
    imgElement.expand();
  }
  //divElement.style.top = top;
  //divElement.style.left = left;
  
}
 
 function init(imgElement, imgThumb)
  {
   imgElement.originalHeight = imgElement.height;
   imgElement.originalWidth = imgElement.width;
   imgElement.width = imgThumb.width;
   if(parseInt(imgElement.originalWidth)>0) imgElement.height = parseInt(imgThumb.width) / parseInt(imgElement.originalWidth ) * parseInt(imgElement.originalHeight);
   
   imgElement.expand = function() 
        {
         var factor1 = Math.round(imgElement.height*.15);
     var factor2 = Math.round(imgElement.width*.15);
         if(imgElement.width + factor2 < imgElement.originalWidth)
         {
          imgElement.width += factor2;
          imgElement.height += factor1;
          imgElement.imgDelayID = window.setTimeout(imgElement.expand,5);
         }
         else
         {
      
          imgElement.width = imgElement.originalWidth;
          imgElement.height = imgElement.originalHeight;
      clearTimeout(imgElement.imgDelayID);
         }
        };
  imgElement.inited = true;
}

function closePreview(id){
    var imgElement = find_object('preview_img'+id);
    var imgThumb = find_object('thumb_img'+id);
  if(imgElement && imgThumb)
    if(imgElement.inited){
      clearTimeout(imgElement.imgDelayID);
      imgElement.height = imgElement.originalHeight;
      imgElement.width = imgElement.originalWidth;
      imgElement.inited = false;
  }
  setVisibility('preview_div'+id, false);
}

function setVisibility(objname, vis, type){
    var obj = find_object(objname);
    if(!obj) return;
    if('visibility' == type)
        obj.style.visibility = vis?'visible':'hidden';
    else
        obj.style.display = vis?'inline':'none';
    
    
}

function find_object(sID)
{
  if (document.getElementById)
  {
    return document.getElementById(sID);
  }
  else if (document.all)
  {
    return document.all[sID];
  }
  else if (document.layers)
  {
    return document.layers[sID];
  }
  else
  {
    return null;
  }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
    //---//     
	
	
	
// Tigra Calendar v4.0.2 (12-01-2009) European (dd-mm-yyyy)
// http://www.softcomplex.com/products/tigra_calendar/
// Public Domain Software... You're welcome.

// default settins
var A_TCALDEF = {
	'months' : ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
	'weekdays' : ['Pz', 'Pzt', 'Sa', 'Ça', 'Pe', 'Cu', 'Cmt'],
	'yearscroll': true, // show year scroller
	'weekstart': 1, // first day of week: 0-Su or 1-Mo
	'centyear'  : 70, // 2 digit years less than 'centyear' are in 20xx, othewise in 19xx.
	'imgpath' : 'img/' // directory with calendar images
}
// date parsing function
function f_tcalParseDate (s_date) {

	var re_date = /^\s*(\d{1,2})\-(\d{1,2})\-(\d{2,4})\s*$/;
	if (!re_date.exec(s_date))
		return alert ("Invalid date: '" + s_date + "'.\nAccepted format is dd-mm-yyyy.")
	var n_day = Number(RegExp.$1),
		n_month = Number(RegExp.$2),
		n_year = Number(RegExp.$3);

	if (n_year < 100)
		n_year += (n_year < this.a_tpl.centyear ? 2000 : 1900);
	if (n_month < 1 || n_month > 12)
		return alert ("Invalid month value: '" + n_month + "'.\nAllowed range is 01-12.");
	var d_numdays = new Date(n_year, n_month, 0);
	if (n_day > d_numdays.getDate())
		return alert("Invalid day of month value: '" + n_day + "'.\nAllowed range for selected month is 01 - " + d_numdays.getDate() + ".");

	return new Date (n_year, n_month - 1, n_day);
}
// date generating function
function f_tcalGenerDate (d_date) {
	return (
		(d_date.getDate() < 10 ? '0' : '') + d_date.getDate() + "-"
		+ (d_date.getMonth() < 9 ? '0' : '') + (d_date.getMonth() + 1) + "-"
		+ d_date.getFullYear()
	);
}

// implementation
function tcal (a_cfg, a_tpl) {

	// apply default template if not specified
	if (!a_tpl)
		a_tpl = A_TCALDEF;

	// register in global collections
	if (!window.A_TCALS)
		window.A_TCALS = [];
	if (!window.A_TCALSIDX)
		window.A_TCALSIDX = [];
	
	this.s_id = a_cfg.id ? a_cfg.id : A_TCALS.length;
	window.A_TCALS[this.s_id] = this;
	window.A_TCALSIDX[window.A_TCALSIDX.length] = this;
	
	// assign methods
	this.f_show = f_tcalShow;
	this.f_hide = f_tcalHide;
	this.f_toggle = f_tcalToggle;
	this.f_update = f_tcalUpdate;
	this.f_relDate = f_tcalRelDate;
	this.f_parseDate = f_tcalParseDate;
	this.f_generDate = f_tcalGenerDate;
	
	// create calendar icon
	this.s_iconId = 'tcalico_' + this.s_id;
	this.e_icon = f_getElement(this.s_iconId);
	if (!this.e_icon) {
		document.write('<img src="' + a_tpl.imgpath + 'cal.gif" id="' + this.s_iconId + '" onclick="A_TCALS[\'' + this.s_id + '\'].f_toggle()" class="tcalIcon" alt="Open Calendar" />');
		this.e_icon = f_getElement(this.s_iconId);
	}
	// save received parameters
	this.a_cfg = a_cfg;
	this.a_tpl = a_tpl;
}

function f_tcalShow (d_date) {

	// find input field
	if (!this.a_cfg.controlname)
		throw("TC: control name is not specified");
	if (this.a_cfg.formname) {
		var e_form = document.forms[this.a_cfg.formname];
		if (!e_form)
			throw("TC: form '" + this.a_cfg.formname + "' can not be found");
		this.e_input = e_form.elements[this.a_cfg.controlname];
	}
	else
		this.e_input = f_getElement(this.a_cfg.controlname);

	if (!this.e_input || !this.e_input.tagName || this.e_input.tagName != 'INPUT')
		throw("TC: element '" + this.a_cfg.controlname + "' does not exist in "
			+ (this.a_cfg.formname ? "form '" + this.a_cfg.controlname + "'" : 'this document'));

	// dynamically create HTML elements if needed
	this.e_div = f_getElement('tcal');
	if (!this.e_div) {
		this.e_div = document.createElement("DIV");
		this.e_div.id = 'tcal';
		document.body.appendChild(this.e_div);
	}
	this.e_shade = f_getElement('tcalShade');
	if (!this.e_shade) {
		this.e_shade = document.createElement("DIV");
		this.e_shade.id = 'tcalShade';
		document.body.appendChild(this.e_shade);
	}
	this.e_iframe =  f_getElement('tcalIF')
	if (b_ieFix && !this.e_iframe) {
		this.e_iframe = document.createElement("IFRAME");
		this.e_iframe.style.filter = 'alpha(opacity=0)';
		this.e_iframe.id = 'tcalIF';
		this.e_iframe.src = this.a_tpl.imgpath + 'pixel.gif';
		document.body.appendChild(this.e_iframe);
	}
	
	// hide all calendars
	f_tcalHideAll();

	// generate HTML and show calendar
	this.e_icon = f_getElement(this.s_iconId);
	if (!this.f_update())
		return;

	this.e_div.style.visibility = 'visible';
	this.e_shade.style.visibility = 'visible';
	if (this.e_iframe)
		this.e_iframe.style.visibility = 'visible';

	// change icon and status
	this.e_icon.src = this.a_tpl.imgpath + 'no_cal.gif';
	this.e_icon.title = 'Close Calendar';
	this.b_visible = true;
}

function f_tcalHide (n_date) {
	if (n_date)
		this.e_input.value = this.f_generDate(new Date(n_date));

	// no action if not visible
	if (!this.b_visible)
		return;

	// hide elements
	if (this.e_iframe)
		this.e_iframe.style.visibility = 'hidden';
	if (this.e_shade)
		this.e_shade.style.visibility = 'hidden';
	this.e_div.style.visibility = 'hidden';
	
	// change icon and status
	this.e_icon = f_getElement(this.s_iconId);
	this.e_icon.src = this.a_tpl.imgpath + 'cal.gif';
	this.e_icon.title = 'Open Calendar';
	this.b_visible = false;
}

function f_tcalToggle () {
	return this.b_visible ? this.f_hide() : this.f_show();
}

function f_tcalUpdate (d_date) {

	var d_today = this.a_cfg.today ? this.f_parseDate(this.a_cfg.today) : f_tcalResetTime(new Date());
	var d_selected = this.e_input.value == ''
		? (this.a_cfg.selected ? this.f_parseDate(this.a_cfg.selected) : d_today)
		: this.f_parseDate(this.e_input.value);

	// figure out date to display
	if (!d_date)
		// selected by default
		d_date = d_selected;
	else if (typeof(d_date) == 'number')
		// get from number
		d_date = f_tcalResetTime(new Date(d_date));
	else if (typeof(d_date) == 'string')
		// parse from string
		this.f_parseDate(d_date);
		
	if (!d_date) return false;

	// first date to display
	var d_firstday = new Date(d_date);
	d_firstday.setDate(1);
	d_firstday.setDate(1 - (7 + d_firstday.getDay() - this.a_tpl.weekstart) % 7);
	
	var a_class, s_html = '<table class="ctrl"><tbody><tr>'
		+ (this.a_tpl.yearscroll ? '<td' + this.f_relDate(d_date, -1, 'y') + ' title="Previous Year"><img src="' + this.a_tpl.imgpath + 'prev_year.gif" /></td>' : '')
		+ '<td' + this.f_relDate(d_date, -1) + ' title="Previous Month"><img src="' + this.a_tpl.imgpath + 'prev_mon.gif" /></td><th>'
		+ this.a_tpl.months[d_date.getMonth()] + ' ' + d_date.getFullYear()
			+ '</th><td' + this.f_relDate(d_date, 1) + ' title="Next Month"><img src="' + this.a_tpl.imgpath + 'next_mon.gif" /></td>'
		+ (this.a_tpl.yearscroll ? '<td' + this.f_relDate(d_date, 1, 'y') + ' title="Next Year"><img src="' + this.a_tpl.imgpath + 'next_year.gif" /></td></td>' : '')
		+ '</tr></tbody></table><table><tbody><tr class="wd">';

	// print weekdays titles
	for (var i = 0; i < 7; i++)
		s_html += '<th>' + this.a_tpl.weekdays[(this.a_tpl.weekstart + i) % 7] + '</th>';
	s_html += '</tr>' ;

	// print calendar table
	var n_date, n_month, d_current = new Date(d_firstday);
	while (d_current.getMonth() == d_date.getMonth() ||
		d_current.getMonth() == d_firstday.getMonth()) {
	
		// print row heder
		s_html +='<tr>';
		for (var n_wday = 0; n_wday < 7; n_wday++) {

			a_class = [];
			n_date = d_current.getDate();
			n_month = d_current.getMonth();

			// other month
			if (d_current.getMonth() != d_date.getMonth())
				a_class[a_class.length] = 'othermonth';
			// weekend
			if (d_current.getDay() == 0 || d_current.getDay() == 6)
				a_class[a_class.length] = 'weekend';
			// today
			if (d_current.valueOf() == d_today.valueOf())
				a_class[a_class.length] = 'today';
			// selected
			if (d_current.valueOf() == d_selected.valueOf())
				a_class[a_class.length] = 'selected';

			s_html += '<td onclick="A_TCALS[\'' + this.s_id + '\'].f_hide(' + d_current.valueOf() + ')"' + (a_class.length ? ' class="' + a_class.join(' ') + '">' : '>') + n_date + '</td>'

			d_current.setDate(++n_date);
			while (d_current.getDate() != n_date && d_current.getMonth() == n_month) {
				d_current.setHours(d_current.getHours + 1);
				d_current = f_tcalResetTime(d_current);
			}
		}
		// print row footer
		s_html +='</tr>';
	}
	s_html +='</tbody></table>';
	
	// update HTML, positions and sizes
	this.e_div.innerHTML = s_html;

	var n_width  = this.e_div.offsetWidth;
	var n_height = this.e_div.offsetHeight;
	var n_top  = f_getPosition (this.e_icon, 'Top') + this.e_icon.offsetHeight;
	var n_left = f_getPosition (this.e_icon, 'Left') - n_width + this.e_icon.offsetWidth;
	if (n_left < 0) n_left = 0;
	
	this.e_div.style.left = n_left + 'px';
	this.e_div.style.top  = n_top + 'px';

	this.e_shade.style.width = (n_width + 8) + 'px';
	this.e_shade.style.left = (n_left - 1) + 'px';
	this.e_shade.style.top = (n_top - 1) + 'px';
	this.e_shade.innerHTML = b_ieFix
		? '<table><tbody><tr><td rowspan="2" colspan="2" width="6"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td><td width="7" height="7" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.a_tpl.imgpath + 'shade_tr.png\', sizingMethod=\'scale\');"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td></tr><tr><td height="' + (n_height - 7) + '" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.a_tpl.imgpath + 'shade_mr.png\', sizingMethod=\'scale\');"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td></tr><tr><td width="7" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.a_tpl.imgpath + 'shade_bl.png\', sizingMethod=\'scale\');"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.a_tpl.imgpath + 'shade_bm.png\', sizingMethod=\'scale\');" height="7" align="left"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td><td style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.a_tpl.imgpath + 'shade_br.png\', sizingMethod=\'scale\');"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td></tr><tbody></table>'
		: '<table><tbody><tr><td rowspan="2" width="6"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td><td rowspan="2"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td><td width="7" height="7"><img src="' + this.a_tpl.imgpath + 'shade_tr.png"></td></tr><tr><td background="' + this.a_tpl.imgpath + 'shade_mr.png" height="' + (n_height - 7) + '"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td></tr><tr><td><img src="' + this.a_tpl.imgpath + 'shade_bl.png"></td><td background="' + this.a_tpl.imgpath + 'shade_bm.png" height="7" align="left"><img src="' + this.a_tpl.imgpath + 'pixel.gif"></td><td><img src="' + this.a_tpl.imgpath + 'shade_br.png"></td></tr><tbody></table>';
	
	if (this.e_iframe) {
		this.e_iframe.style.left = n_left + 'px';
		this.e_iframe.style.top  = n_top + 'px';
		this.e_iframe.style.width = (n_width + 6) + 'px';
		this.e_iframe.style.height = (n_height + 6) +'px';
	}
	return true;
}

function f_getPosition (e_elemRef, s_coord) {
	var n_pos = 0, n_offset,
		e_elem = e_elemRef;

	while (e_elem) {
		n_offset = e_elem["offset" + s_coord];
		n_pos += n_offset;
		e_elem = e_elem.offsetParent;
	}
	// margin correction in some browsers
	if (b_ieMac)
		n_pos += parseInt(document.body[s_coord.toLowerCase() + 'Margin']);
	else if (b_safari)
		n_pos -= n_offset;
	
	e_elem = e_elemRef;
	while (e_elem != document.body) {
		n_offset = e_elem["scroll" + s_coord];
		if (n_offset && e_elem.style.overflow == 'scroll')
			n_pos -= n_offset;
		e_elem = e_elem.parentNode;
	}
	return n_pos;
}

function f_tcalRelDate (d_date, d_diff, s_units) {
	var s_units = (s_units == 'y' ? 'FullYear' : 'Month');
	var d_result = new Date(d_date);
	d_result['set' + s_units](d_date['get' + s_units]() + d_diff);
	if (d_result.getDate() != d_date.getDate())
		d_result.setDate(0);
	return ' onclick="A_TCALS[\'' + this.s_id + '\'].f_update(' + d_result.valueOf() + ')"';
}

function f_tcalHideAll () {
	for (var i = 0; i < window.A_TCALSIDX.length; i++)
		window.A_TCALSIDX[i].f_hide();
}	

function f_tcalResetTime (d_date) {
	d_date.setHours(0);
	d_date.setMinutes(0);
	d_date.setSeconds(0);
	d_date.setMilliseconds(0);
	return d_date;
}

f_getElement = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };

if (document.addEventListener)
	window.addEventListener('scroll', f_tcalHideAll, false);
if (window.attachEvent)
	window.attachEvent('onscroll', f_tcalHideAll);
	
// global variables
var s_userAgent = navigator.userAgent.toLowerCase(),
	re_webkit = /WebKit\/(\d+)/i;
var b_mac = s_userAgent.indexOf('mac') != -1,
	b_ie5 = s_userAgent.indexOf('msie 5') != -1,
	b_ie6 = s_userAgent.indexOf('msie 6') != -1 && s_userAgent.indexOf('opera') == -1;
var b_ieFix = b_ie5 || b_ie6,
	b_ieMac  = b_mac && b_ie5,
	b_safari = b_mac && re_webkit.exec(s_userAgent) && Number(RegExp.$1) < 500;
	

