
function ShowCertificate()
{
	MM_openBrWindow('https://www.thawte.com/core/process?process=public-site-seal-cert-details&public-site-seal-cert-details.referer=http://www.HenleysClothing.co.uk','thawte','scrollbars=yes,width=515px,height=550px')
}

function MM_openBrWindow(theURL,winName,features){ 
	window.open(theURL,winName,features);
}




function DisableClick(){ alert('disable click'); return false;}

/// get prev url used in continue shopping function.
function getPrevUrl(index)
{
    var objHistory = window.history;
    var prevUrl = document.referrer;   
    if (prevUrl != null) {     
       prevUrl = prevUrl.toLowerCase();
       if ( prevUrl.indexOf('product.asp') < 1) {  prevUrl = index; }
    }
    else { prevUrl = index; }
 
    //alert(prevUrl);  
    window.location = prevUrl;
}


/// search for tags within a form by type 
function htmlControl(str_type, str_id_part)
{
   var frm = document.getElementsByTagName("form");
   var elem = getAllFormElements(frm);
   //alert(elem); 
   if ((frm != null) && (elem != null))  {
           for (var i = 0; i < elem.length; i++) {
                if (elem[i].type  == str_type)
                    if (elem[i].id.indexOf(str_id_part) > -1){return elem[i]; }    //now check if id contains email within string 
           }
   }
    return null;
}

 //Simple Email Validation, look for an @ and . in correct sequence
function isEmail(email)
{
	if (email.indexOf('@',1) == -1) return false;
	if (email.indexOf('.',email.indexOf('@')+1) == -1) return false;
	return true;
}

function textLimit(text, maxlen)
{
    if (text.length > maxlen + 1) return false;   
    return true;
}


function isValidPostCode(postcode) {	
	postcode = postcode.toUpperCase();	
	//Test BFPO Format first
	if (/^(BFPO) ?(([0-9]{1}[ABD-HJLNP-UW-Z]{1,2})|([0-9]{1,4}))$/.test(postcode)) return true;						
	if ( !(/^[A-Z]{1,2}[0-9][0-9A-Z]{0,1} {0,1}[0-9][A-Z]{2}$/.test( postcode ) ) ) return false;
	else return true;
}

function checkHasSingleSpace(str)
{	
	if ( !( /\s{1}/.test( str ) ) ) return false;	
	else return true;
}

function getAllRadioElementsById( str_id_part, parent_node )
{
    var out = new Array();
    var rads = getElementsByTagNameMultiple([ 'input' ]);
    for (var i=0; i < rads.length; i++)
    {
        if (rads[i].type =='radio') {
            if (rads[i].id.indexOf(str_id_part) > -1) { out.push(rads[i]); } 
        }  
    }
    return out;
}

function getAllCheckBoxesById(str_id_part, parent_node )
{

 var out = new Array();
    var rads = getElementsByTagNameMultiple([ 'input' ]);
    for (var i=0; i < rads.length; i++)
    {
        if (rads[i].type =='checkbox') {
            if (rads[i].id.indexOf(str_id_part) > -1) { out.push(rads[i]); } 
        }  
    }
    alert(out);
    return out;

}


function getAllFormElements( parent_node )
{   
    return getElementsByTagNameMultiple([ 'input', 'select', 'password' ]); // searching for all tags described
}

function getElementsByTagNameMultiple( tag_names, parent_node ) 
{
    var out = new Array();
    if( parent_node == undefined )  {         parent_node = document; }

    for( var i = 0; i < tag_names.length; i++ )
    {
        elementsFound = parent_node.getElementsByTagName(tag_names[i]);
        for (var j = 0; j < elementsFound.length; j++)
            out.push( elementsFound.item(j) );
    } 
    return out;
}


function getElementsByInputType(types)
{




}


/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


// ------------------------------------------------------------------------------------
// Action: Test if page is secure page or not
// Usage: In conjuction with when back button is pressed
//
// Details: 1.) Check if page is secure page IsPageSecure() [True/False]
//          2.) if True. Check if customer is logged in or not using IsLoggedIn() [True/False
//          3.) if False (logged out) only allow customer to move forward and not back
// --------------------------------------------------------------------------------------
function LoginSecure() { if(IsPageSecure()) { if (!IsLoggedIn()) {  alert('only go forward'); window.history.forward(); } } }


/**
*
*
* login / logout  functions 
*
*/

function IsPageSecure()
{
    var url =window.location.href.toLowerCase();
    //alert('index ' + url.indexOf('mydetails.aspx',0) + ' index 2 ' + url.indexOf('ordertracking.aspx',0));
    if (url.indexOf('mydetails.aspx',0) > 0) { return true; }
    if (url.indexOf('ordertracking.aspx',0) > 0) {  return true; }
    return false; 
}

function SetLogoutCookie(value) 
{
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+1);
        var expires = "; expires="+exdate.toGMTString();
        document.cookie = "logout=" + value + expires+"; path=/";
        //alert('cookie ' + document.cookie);
}

function IsLoggedIn()  
{
    var c_start = document.cookie.indexOf("logout=");
    if (c_start!=-1){
        c_start=c_start + 7; 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) {c_end=document.cookie.length;}
        if(document.cookie.substring(c_start,c_end) == "true"){ return true;}                
    }
    //alert('check logout ' );
    return false;
}

function SetUKDefaultCountry(selectName) {
    var menu_lis = document.getElementsByTagName("select")
    if (menu_lis) {
        if (menu_lis.length > 0) {
            for (i = 0; i < menu_lis.length; i++) {
                if (menu_lis[i].name.match(selectName)){
                    if (menu_lis[i].selectedIndex == 0) {
                        menu_lis[i].selectedIndex = 1;
                    }
                    break;
                }
            }
        }
    }
}



