//swfobject.registerObject("mainHeader", "8.0.24", "swfobject/expressInstall.swf");


////Validate Email Address
//var testresults
//function checkemail(){
//	var str=document.form1.emailAddress.value
//	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
//		if (filter.test(str))
//			testresults=true
//		else{
//			alert("Please input a valid email address!")
//			testresults=false
//		}
//		return (testresults)
//}

//function checkbae(){
//	if (document.layers||document.getElementById||document.all){
//		return checkemail()
//	}else{
//		return true
//	}
//}

function formatPhone(elm, e) {
    var keychar;
    var countryType = document.getElementById(countryID)
    var countryValue = countryType.options[countryType.options.selectedIndex].text

    if (countryType.options[countryType.options.selectedIndex].text == "United States" || countryType.options[countryType.options.selectedIndex].text == "Canada") {
        // If used in onkeypress, pass in the event and this will
        // grab the character and do the right thing. This allows
        // for a smoother user experience than if the chars are
        // being visibly deleted.
        if (e) {
            var keynum;
            if (window.event) {
                keynum = e.keyCode
            }
            else if (e.which) {
                keynum = e.which
            }

            keychar = String.fromCharCode(keynum)
        }

        // Allow a backspace to go through, so the user
        // can correct any typos.
        if (/[\b]/.exec(keychar)) {
            return true;
        } else {
            var p = elm.value + keychar;

            // Don't allow a leading 1 or 0. We also strip out all
            // non-numeric characters here to make the formatting
            // easier later on. This could be modified to allow
            // letters if you consider them valid.
            p = p.replace(/^[01]/, "");
            p = p.replace(/\D+/g, "");

            // You can easily change the formatting of the phone
            // number by editing the conditionals below.
            if (p.length > 0 && p.length < 3) {
                p = "(" + p;
            }
            else if (p.length >= 3 && p.length < 7) {
                p = "(" + p.substring(0, 3) + ") " + p.substring(3);
            }
            else if (p.length >= 7 && p.length < 10) {
                p = "(" + p.substring(0, 3) + ") " + p.substring(3, 6) + "-" + p.substring(6);
            }
            else if (p.length) {
                p = "(" + p.substring(0, 3) + ") " + p.substring(3, 6) + "-" + p.substring(6, 10);
            }
            elm.value = p;

            return false;
        }
    }

}

function confirmCancel(returnURL, process) {
    var confirmMessage = confirm("Are you sure you want to the " + process + " process?")
    if (confirmMessage) {
        document.location = returnURL
    }
}

function logOff() {
    var signOut = confirm("Are you sure you want to log off SpinStitch.Com?")
    if (signOut) {
        document.location = "/UserAccount/LogOff.aspx";
    }

}

function alertUpdate(updateMessage) {
    alert(updateMessage);
}

var scrollHeightValue
var scrollBottomValue
var scrollTopValue

function setScrollValues(element, elementHeight) {
    scrollTopValue = 0;
    scrollHeightValue = element.scrollHeight;
    scrollBottomValue = scrollHeightValue - (scrollTopValue + elementHeight);

    element.scrollTop = 0;
    document.getElementById('chkBoxAgree').disabled = true;
    document.getElementById('chkBoxAgree').checked = false;
}

function getScrollPosition(element, elementToEnable) {

    if (elementToEnable) {
        if (element.scrollTop == scrollBottomValue) {
            elementToEnable.disabled = false;
        }
        else {
            elementToEnable.disabled = true;
            if (elementToEnable.type == 'checkbox') {
                elementToEnable.checked = false;
            }
        }
    }
}

function checkAgree(agreeBox) {
    if (agreeBox.checked) {
        var agree = confirm('You are agreeing to an initial fee of $125.00 USD and a year hosting contract at a $39 USD a month.');
        if (agree) {
            document.location = 'ProcessStep3.aspx?agID=1';
        }
    } else {
        alert('Please read to the bottom of the agreement and check the agree box!');
    }
}

function ValidateChecked(oSrc, args) {
    if (document.getElementByID["<%=chk.ClientID%>"].checked == false) {
        alert("Has to be checked.");
        args.IsValid = false;
    }
}

function makeUppercase(tbControl) {

    tbControl.value = tbControl.value.toUpperCase();
}
function NewWindow(mypage, myname, w, h, scroll, pos) {
    if (pos == "random") { LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100; TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100; }
    if (pos == "center") { LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100; TopPosition = (screen.height) ? (screen.height - h) / 2 : 100; }
    else if ((pos != "center" && pos != "random") || pos == null) { LeftPosition = 0; TopPosition = 20 }
    settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win = window.open(mypage, myname, settings);
}


//Project Related Methods
function deleteProject(projectID, controlID) {
    var confirmDelete = window.confirm("Are you sure you want to delete this project?")

    if (confirmDelete) {
        __doPostBack(controlID, projectID);
    }
}

function publishProject(projectID, controlID) {
    var confirmPublish = window.confirm("Are you sure you want to publish this project?")

    if (confirmPublish) {
        __doPostBack(controlID, projectID);
    }
}

function unpublishProject(projectID, controlID) {
    var confirmPublish = window.confirm("Are you sure you want to unpublish this project?")

    if (confirmPublish) {
        __doPostBack('un' + controlID, projectID);
    }
}

var tempControlID = '';

function postBackMaint(doConfirm, message, width, height, controlID,validationGroup) {

    if (validationGroup != '') {
        var pageValidate = Page_ClientValidate(validationGroup);

        if (!pageValidate) {
            return false;
        }
    }
        
    
    
    
        if (doConfirm) {
            tempControlID = controlID;
            radconfirm(message, radConfirmCallBack, width, height);

        }
        else {
            __doPostBack(controlID, '');
        }
    
   



}

function postBackMaintAjax( updatePanelID, controlID, validationGroup) {

    __doPostBack(updatePanelID, controlID);
    
}
function radConfirmCallBack(arg) {
    controlID = tempControlID;
    tempControlID = '';

    if (arg) {
        __doPostBack(controlID, '');
    }

}

var varFunctionToCall = null;
var varFunctionParameters = null;

function confirmWithAction(confirmMessage, isRadWindow, windowWidth, windowHeight, functionToCall, parameters) {
    varFunctionToCall = null;
    varFunctionParameters = null;
    
    if (isRadWindow) {
        varFunctionToCall = functionToCall;
        varFunctionParameters = parameters;
        radconfirm(confirmMessage, radConfirmWithActionCallBack, windowWidth, windowHeight);
    }


}

function radConfirmWithActionCallBack(arg) {
    if (arg) {
        if (varFunctionToCall != null) {
            
            return varFunctionToCall(varFunctionParameters);
        }
    }
}


//var postBackMessage = '';
function postBackAlert(winW, winH, redirectURL,closeParentWindow) {
      if (postBackMessage.length > 0) {
        var oWnd = radalert(postBackMessage, winW, winH);        
        postBackMessage = '';
        if (redirectURL && redirectURL.length > 0) {
            var args = new Object();
            args.url = redirectURL;
            args.closeParent = closeParentWindow
            oWnd.argument = args;        
            oWnd.add_close(OnClientCloseWin);
        }
        
    }
}

function OnClientCloseWin(oWind, args) {

    if (oWind.argument.closeParent == 'true') {
        CloseRadWindow();
        GetRadWindow().BrowserWindow.document.location = oWind.argument.url;
    } else {
        document.location = oWind.argument.url;
    }
    
    
    
    

}



function generalAlert(message,winW, winH) {
    if (message.length > 0) {
        radalert(message, winW, winH);        
    }
}
//<--Validation
function numberGreaterThanZero(sender, eventArgs) {
    var numberValue = eventArgs.Value

    if (numberValue != '') {
        if (!IsNumeric(numberValue)) {
            eventArgs.IsValid = false;
            return;
        }

        if (numberValue <= 0) {
            eventArgs.IsValid = false;
            return;
        }
    }
    else {
        eventArgs.IsValid = false;
        return;
    }

    eventArgs.IsValid = true;

}

function isNumber(sender, eventArgs) {
    var numberValue = eventArgs.Value
    
    if(!IsNumeric(numberValue)){
        eventArgs.IsValid = false;
        return;
    } 
    
    eventArgs.IsValid = true;
}

function year4Digits(sender, eventArgs) {
    var numberValue = eventArgs.Value

    if (numberValue != '') {
        if (!IsNumeric(numberValue)) {
            eventArgs.IsValid = false;
            return;
        }

        if (numberValue <= 0) {
            eventArgs.IsValid = false;
            return;
        }

        if (numberValue.length < 4) {
            eventArgs.IsValid = false;
            return;
        }
    }
    else {
        eventArgs.IsValid = false;
        return;
    }

    eventArgs.IsValid = true;

}
//End Validation -->



//Utilities
function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}
function imposeMaxLength(Object, MaxLen) {
    return (Object.value.length <= MaxLen);
}

function copyToClipboard(controlID)
{
	var s = document.getElementById(controlID).value
	if( window.clipboardData && clipboardData.setData )
	{
	    clipboardData.setData("Text", s);
	    generalAlert('The code has been copied to your clipboard.', 400, 150);
	}
	else
	{
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans, null, clipid.kGlobalClipboard);

		generalAlert('The code has been copied to your clipboard.', 400, 150); 	   
	}
}

function copy(elementID) {
    var inElement = document.getElementById(elementID);
    if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range && BodyLoaded == 1)
            range.execCommand('Copy');
    } else {
        var flashcopier = 'flashcopier';
        if (!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="/flashcontect/_clipboard.swf" FlashVars="clipboard=' + encodeURIComponent(inElement.value) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
}

function openRADWindow(windowName,width,height,url,title) {

    window.setTimeout(
                             function() {
                                 var oManager = GetRadWindowManager();
                                 var rdWin = oManager.GetWindowByName(windowName);
                                 rdWin.SetUrl(url);
                                 rdWin.SetSize(width, height);
                                 rdWin.SetModal(true);
                                 rdWin.SetTitle(title);                                 
                                 rdWin.add_close(function() { SetBlank(windowName); });
                                 rdWin.Show();

                             }
                             , 1000);
}

function SetBlank(windowName) {
    var oManager = GetRadWindowManager();
    var radWindow2 = oManager.GetWindowByName(windowName);
    radWindow2.SetUrl("about:blank")
}  

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
} 


function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 

return oWindow;
}

function CloseRadWindow() {
    var oWnd = GetRadWindow();
    //close the RadWindow
    if (oWnd) {
        oWnd.close();
    } 
    
}


