// Writes an email hyperlink to the page.
function writeSimpleEmailLink(prefix, domain)
{
	document.write("<a href=\"mailto: " + prefix + "@" + domain + "\">" + prefix + "@" + domain + "</a>");
}

//if you need to write something other than the email address to the page.
function writeComplexEmailLink(prefix, domain, display_text)
{
	document.write("<a href=\"mailto: " + prefix + "@" + domain + "\">" + display_text + "</a>");
}

// Validates the sample request form.
function validateForm()
{
	// Call to check if javascript is enabled.
	javaScriptEnabled();
		
	// Assume invalid data
	var retVal = false;
	var errMsg = "";
	
	// Pull the form values
	var txtFirstName 	= document.getElementById("first_name");
	var txtLastName		= document.getElementById("last_name");
	var txtEmail		= document.getElementById("email");
	var ddlCategory		= document.getElementById("categorys");
	var txtComments		= document.getElementById("comments");
	
	// Validate first name
	if (trimString(txtFirstName.value) == "")
	{
		errMsg += "The first name field is required.\r\n";
	}
	
	// Validate first name
	if (trimString(txtLastName.value) == "")
	{
		errMsg += "The last name field is required.\r\n";
	}
	
	// Validate email
	if (trimString(txtEmail.value) == "")
	{
		errMsg += "The email address field is required.\r\n";
	}
	else if (!isValidEmail(trimString(txtEmail.value)))
	{
		errMsg += "The email address field is not a valid email address.\r\n";
	}
	
	// Validate category
	if (trimString(ddlCategory.value) == "")
	{
		errMsg += "The category field is required.\r\n";
	}
	
	// Validate comments
	if (trimString(txtComments.value) == "")
	{
		errMsg += "The comments field is required.\r\n";
	}
	
	// Check if we trapped an error
	if (errMsg.length > 0)
	{
		// Alert the user
		alert("The following fields are not valid, please correct the following fields and try again.\r\n\r\n" + errMsg);
	}
	else
	{
		// Set the return value
		retVal = true;
	}
	
	// Return the value
	return retVal;
}

// Returns the inString value with the 
// extra spaces removed from the string.
function trimString(inString)
{
  	inString = inString.replace(/^\s+/g, "");// strip leading
  	return inString.replace(/\s+$/g, "");// strip trailing
}

// Returns if the specified email address is valid or not.
function isValidEmail(email)
{
	// Set the expression value
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	// Create the reg expression
    var regex = new RegExp(emailReg);
	
	// Return if it matches the expression
	// which means a valid email.
    return regex.test(email);
}

// Check if javascript is enabled.
function javaScriptEnabled()
{
	var hidden_field = document.getElementById("javascript_enabled");
	if (hidden_field)
	{
		// Set the value to 1 to show that javascript is enabled.
		hidden_field.value = "9825301648";
	}
}

/*added by ej on 12/07/06 to be used in shopcheckout.asp*/
function clearBogusNum(txBox, evt)
  {
    if ((evt.keyCode == 9) || (evt.which == 9))
	  {
	    return;
	  }
  
    var dex = -1;	
	dex = txBox.value.indexOf('*');
	
	if (dex >= 0)
	  {
	    txBox.value = '';
	  }		
	  		  
	return true;    
  }
 
  /*added by ej to allow only numeric values*/  
  function intOnly(field, event)
    { 
      var key;
      var keychar;
      var msgSpot;
      var allowed;  

      allowed = "0123456789";
      
      if (window.event)
        key = window.event.keyCode;
      else if (event)
        key = event.which
      else
        return true;
        
      keychar = String.fromCharCode(key);
      
      /*check for special characters, then for numbers*/
      if ((key == null) || (key == 0))
        return true;
      else if (((allowed).indexOf(keychar) > -1))
        {          
          return true;
        }
      else
        {                            
          return false;
        }
    }
	
/*Handles customer guarantee warning label on home pages*/
function getGuarantee()
{
	var newWindow = window.open("/globalcart/html/customer_guarantee.asp",null,"location=yes,toolbar=yes,titlebar=yes,menubar=yes,height=700,width=800,scrollbars=yes,resizable=yes");	  
	//return false here to avoid the link being followed
	return false;
}

/*
Author: Aswath
Created On : 21th Aug 2009
Description: Display's the cost in a label as per http://smsharepoint/it/software/Lists/Maintenance/DispForm.aspx?ID=135&Source=http%3A%2F%2Fsmsharepoint%2Fit%2Fsoftware%2FLists%2FMaintenance%2Fbyowner%2Easpx%3FView%3D%7B4B08EE1B%2D6656%2D4F2A%2D8E57%2D33238C1C4898%7D%26FilterField1%3DAssignedTo%26FilterValue1%3Dcontractor%2520Maintenance1 
*/
function DisplayRates(dpd, flag) {
    var ind = dpd.selectedIndex;
    var myResult = dpd.options[ind].text;
    var actualResult = myResult.split('-');
    document.getElementById('divCost' + flag.toString()).innerHTML = actualResult[1];
    //Store the selected quantity to assign when new dosage is selected. 
    document.getElementById('drpSelectedValue').value = actualResult[0];
}
/*
Author: Aswath
Created On : 21th Aug 2009
Description: Show/Hide Quantity dropdownlists and Display's the cost in a label as per http://smsharepoint/it/software/Lists/Maintenance/DispForm.aspx?ID=135&Source=http%3A%2F%2Fsmsharepoint%2Fit%2Fsoftware%2FLists%2FMaintenance%2Fbyowner%2Easpx%3FView%3D%7B4B08EE1B%2D6656%2D4F2A%2D8E57%2D33238C1C4898%7D%26FilterField1%3DAssignedTo%26FilterValue1%3Dcontractor%2520Maintenance1 
*/
function ShowHide_control(divName) {
    var drpCount, i, drpQuantiy, j, myResult, actualResult, drpDosage
    drpCount = document.getElementById('drpCount').value;
    //Added the following 3 lines on 8th sept 2009 by Aswath for New design-II
    drpDosage = document.getElementById('drpMedicine').selectedIndex;
    drpDosage = drpDosage + 1;
    divName = divName + drpDosage;
    for (i = 1; i <= drpCount; i++) {
        if ('divQuantity' + i.toString() == divName) {
            document.getElementById(divName).style.display = 'block';
            drpQuantiy = document.getElementById('productid' + i.toString());
            // Check the previous quantity dropdown value and assign
            var pqty = document.getElementById('drpSelectedValue').value;
            if (pqty != '') {
                var dcount = drpQuantiy.options.length;
                for (j = 0; j < dcount; j++) {
                    myResult = drpQuantiy.options[j].text;
                    actualResult = myResult.split('-');
                    if (pqty == actualResult[0]) {
                        drpQuantiy.selectedIndex = j;
                    }
                }
            }
            myResult = drpQuantiy.options[drpQuantiy.selectedIndex].text;
            actualResult = myResult.split('-');
            document.getElementById('divCost'+i.toString()).innerHTML =  actualResult[1];
            
        }
        else {
            document.getElementById('divQuantity'+i.toString()).style.display = 'none';
        }
      }
    return true;
}


//
// patch of innerText for firefox
//
(function (bool) {
function setInnerText(o, s) {
while (o.childNodes.length != 0) {
o.removeChild(o.childNodes[0]);
}
o.appendChild(document.createTextNode(s));
}
function getInnerText(o) {
var sRet = "";
for (var i = 0; i < o.childNodes.length; i ++) {
if (o.childNodes[i].childNodes.length != 0) {
sRet += getInnerText(o.childNodes[i]);
}
if (o.childNodes[i].nodeValue) {
if (o.currentStyle.display == "block") {
sRet += o.childNodes[i].nodeValue + "\n";
} else {
sRet += o.childNodes[i].nodeValue;
}
}
}
return sRet;
}
if (bool) {
HTMLElement.prototype.__defineGetter__("currentStyle", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});
HTMLElement.prototype.__defineGetter__("innerText", function () {
return getInnerText(this);
})
HTMLElement.prototype.__defineSetter__("innerText", function(s) {
setInnerText(this, s);
})
}
})( /Firefox/.test(window.navigator.userAgent));



