﻿//function PlayVideo(video) {


//    $('div[rel]').overlay({ top: 0, effect: 'apple', fixed: true, closeOnClick: true, oneInstance: false, closeOnEsc: true, speed: 'normal', closeSpeed: 'slow',
//        mask: { color: '#666666', loadSpeed: 200, opacity: 0.5 }
//    });

//    $('#overlay').appendTo('body');

//    $.tools.overlay.addEffect('myEffect', function(position, done) {
//        this.getOverlay().css(position).fadeIn(this.getConf().speed, done);
//    }, function(done) {
//        $('#divRetailVideo').empty();
//        this.getOverlay().fadeOut(this.getConf().closeSpeed, done);
//    });

//    $('.apple_overlay').click(function(event) {
//        var $tgt = $(event.target);
//        if ($tgt.is('.close')) { $('#divRetailVideo').empty(); }
//    });

////    $('#divRetailVideo').html("<object width=\"845\" height=\"450\"><param name=\"movie\" value=" + video + " /><param name=\"allowFullScreen\" value=\"false\" />" +
////                            "<param name=\"allowScriptAccess\" value=\"always\" /><param name=\"wmode\" value=\"transparent\" />" +
////                            "<embed src=" + video + " type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" WMODE=\"transparent\" allowscriptaccess=\"always\" width=\"845\" height=\"450\">" +
////                            "</embed></object>");
//}
        
function moveMe(id){
    if(id == 'txtAC'){
        if(GetElementById('txtAC').value.length == 3){
            GetElementById('txtPrefix').focus();
            GetElementById('txtPrefix').select();
        }
    }
    else if(id == 'txtPrefix'){
        if(GetElementById('txtPrefix').value.length == 3){
            GetElementById('txtSuffix').focus();
            GetElementById('txtSuffix').select();
        }
    }
    
}

function moveToObject(e, buttonId, buttonToHideId) {
    var bt = document.getElementById(buttonId);
    var btWatermark  = document.getElementById(buttonToHideId);
    
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                //alert('here 1');
                btWatermark.style.display = 'none';
                bt.style.display = '';
                bt.focus();
                bt.select();
                return false;
            }
        }
        else if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                //alert('here 2' + bt.id);
                btWatermark.style.display = 'none';
                bt.style.display = '';
                bt.focus();
                bt.select();
                return false;
            }
        }
    }
    return true;
}

function resetPassword(txtWatermark, txtPassword)
{   
    if(document.getElementById(txtPassword).value.trim().length == 0) 
    {
        document.getElementById(txtPassword).style.display = 'none';
        document.getElementById(txtWatermark).style.display = '';
    }
}

function clickButton(e, buttonid) {
    var bt = GetElementById(buttonid);

    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                if (bt.dispatchEvent) {
                    var e = document.createEvent("MouseEvents");
                    e.initEvent("click", true, true);
                    bt.dispatchEvent(e);
                }
                else {
                    bt.click();
                }
                //bt.click();
                return false;
            }
        }
        else if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

function isInteger(s) {
    var i;

    if (isEmpty(s))
        if (isInteger.arguments.length == 1) return 0;
    else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isDigit(c) {
    return ((c >= "0") && (c <= "9"))
}


function CallMe() {

    var txtAC = GetElementById('txtAC');
    var txtPrefix = GetElementById('txtPrefix');
    var txtSuffix = GetElementById('txtSuffix');

    if (txtAC.value.length < 3 || !isInteger(txtAC.value)) {
        alert("The phone number entered is invalid. Please enter a valid area code.");
        txtAC.select();
        return false;
    }

    if (txtPrefix.value.length < 3 || !isInteger(txtPrefix.value)) {
        alert("The phone number entered is invalid. Please enter a valid prefix.");
        txtPrefix.select();
        return false;
    }

    if (txtSuffix.value.length < 4 || !isInteger(txtSuffix.value)) {
        alert("The phone number entered is invalid. Please enter a valid suffix.");
        txtSuffix.select();
        return false;
    }

    return true;
}

function validateText(text)
{
	var arr = new Array( '`' , '~', '^', '{' , '}' , '[' , ']' , '|', '\"', '\'' , '<', '>', '/');
	
	var blnValid = true;
	for(i = 0; i < text.length; i++)
	{
		for(j = 0; j < arr.length; j++)
		{
			if(text.charAt(i) == arr[j])
			{
				result = alert('[ ' + arr[j] + ' ] is an invalid character, please try again.');													
				text = text.replace(arr[j], '');
				blnValid = false;
			}
		}
	}
	
	return blnValid;
}

function EmailMe() {
    var txtName = GetElementById('txtName');
    var txtEmail = GetElementById('txtEmail');
    var txtMessage = GetElementById('txtMessage');

    if (txtName.value.length == 0) {
        alert("Please enter a name.");
        txtName.select();
        return false;
    }
    if (txtEmail.value == ''){
        alert("Please enter an email address.");
        txtEmail.select();
        return false;
    }
    if (!IsEmail(txtEmail.value)) {
        alert("Please enter a valid email address.");
        txtEmail.select();
        return false;
    }
    if (txtMessage.value == ''){
        alert("Please enter a message.");
        txtMessage.select();
        return false;
    }
    if(!validateText(txtMessage.value)){
        //txtEmailMessage.select();
        return false;
    }   

    return true;
}

function IsEmail(email) {
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return regex.test(email);
}

function goToLink(link) {
    location.href = link
}

function showFeaturedProduct(link){
    if(siteType == 2){
        location.href = link
    }
    else{
        location.href = '/Shop/Shop.aspx?item=' + link
    }
}

function showOurProduct(link){
    if(siteType == 2){
        location.href = link
    }
    else{
        if(link.indexOf('Contact.aspx') != -1){
            location.href = link
        }
        else{
            location.href = '/Shop/Shop.aspx?item=' + link
        }
    }
}
