function fillSelectFromArray(selectCtrl, itemArray, goodPrompt,  badPrompt, defaultItem) {
    var i, j;
    var prompt;
	
    // empty existing items
    for (i = selectCtrl.options.length-1; i >= 0; i--) {
        selectCtrl.options[i] = null;
    }
    prompt = (itemArray != null) ? goodPrompt : badPrompt;
    if (prompt == null) {
        j = 0;
    } else {
        selectCtrl.options[0] = new Option(prompt);
        selectCtrl.options[0].value = prompt;
        j = 1;
    }
    if (itemArray != null) {
        // add new items
        for (i = 0; i < itemArray.length; i++) {
            selectCtrl.options[j] = new Option(itemArray[i][0]);
            if (itemArray[i][1] != null) {
                selectCtrl.options[j].value = itemArray[i][1];
            }
            j++;
        }
        // select first item (prompt) for sub list
        selectCtrl.options[0].selected = true;
    }
}


function ClearForm(form) {
	for (var i = 0; i < form.length; i++) {
  		if (form.elements[i].type != 'hidden' &&  form.elements[i].type != 'image'
  		&& form.elements[i].type != 'submit' 
  		&& form.elements[i].type != 'reset') form.elements[i].value = '';
 	} 
 	
	document.getElementById('country_select').value = 'US'
	country_list.change_country('US', 'state_select')
}

function CheckColorSelected(SelectCtrl) {
    if (SelectCtrl.options[0].text=="Size") {
        alert("Please select a color first");
    }
}

function checksize(size, prod, color)
{
    if (size == null || (size.length != 3 && !(size.length == 0 && prod.substring(0,3) == 'LGC'))) {
        alert('Please select a color and size!!');
        return false;
    } else {
        return true;
    }
}

function checkCardHolderQty()
{
    var vGiftCardQty = parseInt(document.getElementById("giftcard_qty_a").value);

    var vLGCH100 = parseInt(document.getElementById("item_qty_a[LGCH100]").value);
    var vLGCH101 = parseInt(document.getElementById("item_qty_a[LGCH101]").value);
    var vLGCH102 = parseInt(document.getElementById("item_qty_a[LGCH102]").value);
    var vLGCH103 = parseInt(document.getElementById("item_qty_a[LGCH103]").value);
/*
    alert("vGiftCardQty = " + vGiftCardQty);
    alert("vLGCH100 = " + vLGCH100);
    alert("vLGCH101 = " + vLGCH101);
    alert("vLGCH102 = " + vLGCH102);
    alert("vLGCH103 = " + vLGCH103);
*/
    var vLGCHTotal = 0;
    if (vLGCH100 > 0) vLGCHTotal += vLGCH100;
    if (vLGCH101 > 0) vLGCHTotal += vLGCH101;
    if (vLGCH102 > 0) vLGCHTotal += vLGCH102;
    if (vLGCH103 > 0) vLGCHTotal += vLGCH103;

    if (vLGCHTotal > vGiftCardQty) {
        alert('Please change the quantity of gift card holder(s) to equal the number of gift card(s) ordered.\n You ordered ' + vGiftCardQty + ' gift card(s) and selected ' + vLGCHTotal + ' card holder(s).');
        return false;
    }
    return true;
}

function turnOnPromo(state) {
	var saleText = document.getElementById("saleText");
	if (saleText == null) return;
	
	var priceText = document.getElementById("priceText");
	var normalPrice = document.getElementById("normalPrice");

	if (state) {
		priceText.innerHTML = "Original";
		normalPrice.className = "withStrike";
		saleText.className = "saleOn";
		
	} else {
		priceText.innerHTML = "Price:";
 		normalPrice.className = "noStrike";
 		saleText.className = "saleOff";
	}
}

function WinOpen(mypage, myname, w, h, winl, wint, scroll) {	
    var wint = (screen.height - h) / 2;
	if (winl = 0 ){
        var winl = (screen.width - w) / 2 + winl;
    } else {    
        var winl = (screen.width - w) / 2;    
    }
    
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl
             + ',scrollbars='+scroll+',resizable=yes, horizontalscrollbar=no, screenX='
             +winl+',screenY='+wint+'';
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

function CheckPasswd(form, field1, field2) {
    var e, e1, e2;
    for (var i=0; i < form.length; i++) {
    	e = form.elements[i];
  		if ((e1 == null) && e.name.indexOf(field1) == 0) { e1 = e; }
		if ((e2 == null) && e.name.indexOf(field2) == 0) { e2 = e; }
 	}
 	if (e1.value != e2.value) {
  		alert("Password and Confirmation do not match. Please retype.");
  		e1.value = "";
  		e2.value = "";
  		e1.focus();
  		return false; 
 	}
 	return true;
}

function CheckForm(form, required) {
	var msg="", e, missing_field=false;
 	for (var i=0; i < form.length; i++) {
 		e = form.elements[i];
  		if (required.indexOf("|" + e.name + "|") >= 0 && e.value == "") {
   			if (e.title == null) { 
   				msg += "- " + e.name + "\n"; 
   			} else { 
   				msg += "- " + e.title + "\n"; 
   			}
   			missing_field = true;
  		}
 	} 
 	if (missing_field) {
  		alert("Fields Marked with a red asterisk(*) are required fields.\nMissing Fields: \n" + msg);
 	}
 	return !missing_field; 
}

function CheckEmail(form) {
	var e, invalid_email=false, msg="";
 	var re = /^.*@.*\.[a-z]+$|^$/i;
 	var email = /^email/i;
 	for (var i=0; i < form.length; i++) {
  		e = form.elements[i];
  		if (email.test(e.name) && !re.test(e.value)) {
   			if (e.title == null) { 
   				msg += "- " + e.name + "\n"; 
   			} else { 
   				msg += "- " + e.title + "\n"; 
   			}
   			invalid_email = true;
  		}
 	}
 	if (invalid_email) {
  		return !confirm("Incorrect/Invalid email(s) entered: \n" + msg + '\n\nWould you like to correct it? (Or press Cancel to continue.)');
 	}
 	return true;
}

/******************************************
* Popup Box- By Jim Silver @ jimsilver47@yahoo.com
* Visit http://www.dynamicdrive.com/ for full source code
* This notice must stay intact for use
******************************************/

var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
/////////////////////////////////

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for ie4+ and NS6////
/////////////////////////////////


function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

function movepic(img_name,img_src) {
document[img_name].src=img_src;
}
