// DISPLAYS ATTRIBUTES

function changeAttributes(attid,prodid){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var attid = attid.options[attid.selectedIndex].value;
var file = '/manage/ajax/productattributes.php?prodid='+prodid+'&attid='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + attid, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content'+prodid).innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

// TO TOGGLE THE STATE OF HIDDEN DIV'S

function toggleLayer(whichLayer) {
    if (document.getElementById(whichLayer).style.display=='none') {
         document.getElementById(whichLayer).style.display='block';
    } else {
         document.getElementById(whichLayer).style.display='none';
    }
}


// CANCEL CHANGES ALERT BOX

function disp_confirm(url)
{
var name=confirm("Any changes made won't be saved. Click OK to confirm.")
if (name==true)
{
window.location=url;
}
}

// CHECK ALL CHECKBOX

function checkAll(opt,fieldname) {
var field=document.getElementsByName(fieldname);
for (i = 0; i < field.length; i++) {
if(opt.checked)
field[i].checked = true;
else
field[i].checked = false;
}
}

// IMAGE UPLOAD AREA

function imgupload(num){
document.getElementById('upload').innerHTML="";
for (x=1; x<=num; x++) {
document.getElementById('upload').innerHTML+='<table width=100% border=0 cellspacing=2 cellpadding=2><tr><td width=36% align=right>image to upload:<\/td><td width=64% align=left> <input name=imagefile[] id=imagefile[] type=file size=40><\/td><\/tr><\/table>';
}
}

// IMAGE UPLOAD AREA

function featureupload(num){
document.getElementById('upload').innerHTML="";
for (x=1; x<=num; x++) {
document.getElementById('upload').innerHTML+='<table width=100% border=0 cellspacing=2 cellpadding=2><tr><td width=20% align=right>image to upload:<\/td><td width=40% align=left><input name=imagefile[] id=imagefile[] type=file size=50><\/td> <td width=20% align=right>featured product sku:<\/td><td width=20% align=left><input name=sku[] id=sku[] type=text size=10><\/td><\/tr><\/table>';
}
}

// BEST SELLER PRODUCT

function bestsellerupload(num){
document.getElementById('upload').innerHTML="";
for (x=1; x<=num; x++) {
document.getElementById('upload').innerHTML+='<table width=100% border=0 cellspacing=2 cellpadding=2><tr><td width=20% align=right>best seller product sku:<\/td><td width=20% align=left><input name=sku[] id=sku[] type=text size=10><\/td><\/tr><\/table>';
}
}

// COLLECTION GALLERY IMAGES

function collectionimgupload(num){
document.getElementById('upload').innerHTML="";
for (x=1; x<=num; x++) {
document.getElementById('upload').innerHTML+='<table width=100% border=0 cellspacing=2 cellpadding=2><tr><td width=20% align=right>select image to upload:<\/td><td width=20% align=left><input name=imagefile[] id=imagefile[] type=file size=30><\/td><\/tr><\/table>';
}
}


// FEATURED PRODUCT

function featuredupload(num){
document.getElementById('upload').innerHTML="";
for (x=1; x<=num; x++) {
document.getElementById('upload').innerHTML+='<table width=100% border=0 cellspacing=2 cellpadding=2><tr><td width=20% align=right>featured product sku:<\/td><td width=20% align=left><input name=sku[] id=sku[] type=text size=10><\/td><\/tr><\/table>';
}
}

//AJAX FUNCTION TO GET MULTIPLE IMAGE UPLOADS

function getImg(img_num){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var img_num = img_num.options[img_num.selectedIndex].value;
var file = '/manage/ajax/multipleimgs.php?img_num='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + img_num, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('uploadarea').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

//AJAX FUNCTION TO GET ADD IMAGE DISPLAYS

function getDisplay(choice){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var file = '/manage/ajax/display.php?display='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + choice, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

//AJAX FUNCTION TO SWITCH COUPON ADD AREAS

function getCoupon(choice){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var choice = choice.options[choice.selectedIndex].value;
var file = '/manage/ajax/coupons.php?choice='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + choice, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

//AJAX FUNCTION TO GET SALES TYPE

function getSaleType(type){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var type = type.options[type.selectedIndex].value;
var file = '/manage/ajax/salestype.php?type='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + type, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}


//AJAX FUNCTION TO SWITCH SALES ITEM FILTERS

function getSalesFilter(choice){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var choice = choice.options[choice.selectedIndex].value;
var file = '/manage/ajax/salesfilter.php?choice='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + choice, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

//AJAX FUNCTION TO GET ORDER STATUS AREAS

function getOrderStatus(orderid,status){
var xmlhttp=false; //Clear our fetching variable
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
}
var status = status.options[status.selectedIndex].value;
var file = '/manage/ajax/orderstatus.php?orderid='+orderid+'&status='; //This is the path to the file we just finished making *
xmlhttp.open('GET', file + status, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
var content = xmlhttp.responseText; //The content data which has been retrieved ***
if( content ){ //Make sure there is something in the content variable
document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
}
}
}
xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

//ADD PHONE ORDER FUNCTIONS

var phoneordercount=0;
function insRow(e)
{
if(phoneordercount<20) {
	
	var last_row=document.getElementById("add_rows").rowIndex;
	var x=document.getElementById('myTable').insertRow(last_row);
	var y=x.insertCell(0);
	var w=x.insertCell(1);
	
	y.align='left'; 
	y.innerHTML="<b>SKU</b> : <input type='text' name='sku[]'  size='15' > &nbsp; <b>Quantity</b> : <input type='text' name='qty[]' size='3'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a onclick='deleteRow(this)' style='cursor:pointer;'>delete</a>";
	w.align='left';
	w.innerHTML = "";  
	phoneordercount = phoneordercount+1;
	}
}

function deleteRow(r)
 {
  var i=r.parentNode.parentNode.rowIndex
  document.getElementById('myTable').deleteRow(i)
  phoneordercount = phoneordercount-1;
 }

$(function() {
		$("map > area").tooltip({
		bodyHandler: function() {
			return $($(this).attr("name")).html();
		},
		showURL: false
	});
	});

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function onMyMenuOpen(obj)
{		
var dl = obj.dl;
var dt = obj.dt;
var dd = obj.dd;
};

function onMyMenuClose(obj)
{
var dl = obj.dl;
var dt = obj.dt;
var dd = obj.dd;
};

var oOptions=
{	
/*all options are optional*/
/* [ bool ] if dependent is false, then each menu open/close independently*/
dependent:true,
/* [function] callback when a menu is opened*/
onOpen:onMyMenuOpen,
/* [function] ccallback when a menu is closed*/
onClose:onMyMenuClose,
/* [array] cdefault ids of opened menues' <dt>*/
openedIds:['my-dt-1'],
/* [number ] seconds for animations*/
seconds:0.4,
/*[ bool ] set true if the animation is to be played slower and slower and vise versa*/
easeOut:false,
/*[ bool ] set true if the animation is to be played*/
animation:true
}

var setting = new AccordionMenu.setting('my-dl',oOptions);
 
//VALIDATION FUNCTIONS

// EMAIL VALIDATION
function isEmailAddr(email)
{
var result = false;
var theStr = new String(email);
var index = theStr.indexOf("@");
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}

//TEXT FIELD VALIDATION
function validRequired(formField,fieldLabel)
{
  var result = true;
  if (formField.value == "")
  {
    alert('Please enter a value for the "' + fieldLabel +'" field.');
    formField.focus();
    result = false;
  }
return result;
}

// SELECT BOX VALIDATION
function validSelect(formField,fieldLabel)
{
  var result = true;
  if (formField.selectedIndex == 0) 
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
return result;
}

// EMAIL VALIDATION
function validEmail(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    formField.focus();
    result = false;
  }
return result;
}

// NUMBER VALIDATION
function validNum(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var num = parseInt(formField.value);
if (isNaN(num))
{
alert('Please enter a number for the "' + fieldLabel +'" field.');
formField.focus();    
result = false;
}
} 
return result;
}

// DATE VALIDATION
function validDate(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var elems = formField.value.split("/");
result = (elems.length == 3); 
if (result)
{
var month = parseInt(elems[0]);
var day = parseInt(elems[1]);
var year = parseInt(elems[2]);
result = !isNaN(month) && (month > 0) && (month < 13) && !isNaN(day) && (day > 0) && (day < 32) && !isNaN(year) && (elems[2].length == 4);
}
if (!result)
{
alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
formField.focus();    
}
} 
return result;
}

// RADIO BUTTON VALIDATION
function validRadio(formField,fieldLabel) 
{
strRadio=formField
for (i=0;i<strRadio.length;i++)
if (strRadio[i].checked)return true
alert('Please select "' + fieldLabel +'".');
formField.focus();
result = false;
}

// PASSWORD VALIDATION
function validatePwd(formField,formField1) {
var result = true;
var invalid = " ";
var minLength = 8;
var pw1 = formField.value;
var pw2 = formField1.value;
if (pw1 == '') {
alert('Please enter your New Password.');
formField.focus();
result = false;
}
else if (pw2 == '') {
alert('Please Confirm your new Password.');
formField1.focus();
result = false;
}
else if (formField.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
formField.focus();
result = false;
}
else if (formField.value.indexOf(invalid) > -1) {
alert("Please do not use spaces in your password.");
formField.focus();
result = false;
} else if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
formField1.focus();
result = false;
}
return result;
}

function validateSignin(theForm)
{
// Start ------->
if (!validRequired(theForm.login,"Username"))
return false;
if (!validRequired(theForm.pwd,"Password"))
return false;
// <--------- End
return true;
}

//STORE VALIDATION FUNCTIONS

function validateCategory(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Category Name"))
return false;
// <--------- End
return true;
}

function validateUpdateCategoryOrder() {
var field = document.getElementsByName('sort_order[]');
for (i = 0; i < field.length; i++) {
if(field[i].value == "") {
alert("Please enter the order you want the category to appear in.");
field[i].focus();
return false;
}
}
}

function confirmDelete() {
if(confirm("Are you sure you want to delete?"))
return true;
else 
return false;
}

function swapCategorySortOrder(field) {
var sortorder = document.getElementsByName('sort_order[]');
for (i = 0; i < sortorder.length; i++) {
if(field.value == sortorder[i].value && field!=sortorder[i]) {
sortorder[i].value = "";
}
}
}

function validateSubcat(theForm)
{
// Start ------->
if (!validSelect(theForm.catid,"Category Name"))
return false;
if (!validRequired(theForm.name,"Sub-Category Name"))
return false;
// <--------- End
return true;
}

function validateSupersubcat(theForm)
{
// Start ------->
if (!validSelect(theForm.catid,"Category Name"))
return false;
if (!validSelect(theForm.subcatid,"Sub-Category Name"))
return false;
if (!validRequired(theForm.name,"Second Sub-Category Name"))
return false;
// <--------- End
return true;
}

function validateBrand(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Manufacturer Name"))
return false;
// <--------- End
return true;
}


function validateProduct(theForm)
{
// Start ------->
if (!validSelect(theForm.catid1,"Category Name"))
return false;
if (!validSelect(theForm.subcatid1,"Sub-Category Name"))
return false;
if (!validRequired(theForm.sku,"Product ID"))
return false;
if (!validRequired(theForm.title,"Product Title"))
return false;
if (!validRequired(theForm.description,"Product Description"))
return false;
if (!validRequired(theForm.price,"Product Price"))
return false;
if (!validRequired(theForm.weight,"Product Weight"))
return false;
// <--------- End
return true;
}

function validateImages(theForm)
{
// Start ------->
if (!validRadio())
return false;
//if (!validRequired(theForm.imagefile[],"Product Image"))
//return false;
// <--------- End
return true;
}

function validateInventory(theForm)
{
// Start ------->
if (!validRequired(theForm.count,"Inventory Count"))
return false;
// <--------- End
return true;
}

function validateProductShipping(theForm)
{
var field = document.getElementsByName('typeid[]');
var count = 0;
for (i = 0; i < field.length; i++) {
if(field[i].checked) count++;
}
if(count==0) {
alert("Please select at least one Shipping Method");
return false;
}
return true;
}

function validateCsv(theForm)
{
// Start ------->
if (!validRequired(theForm.file,"Product Catalog CSV"))
return false;
// <--------- End
return true;
}

function validateInventoryCsv(theForm)
{
// Start ------->
if (!validRequired(theForm.file,"Product Inventory CSV"))
return false;
// <--------- End
return true;
}

function validateCoupon(theForm)
{
// Start ------->
if (!validRequired(theForm.couponid,"Coupon Code"))
return false;
if (!validRequired(theForm.title,"Coupon Title"))
return false;
if (!validSelect(theForm.choice,"Coupon Type"))
return false;
// <--------- End
return true;
}

