// JavaScript Document

function swapclass(what, newclass) {
  what.className = newclass;
}

function redirect(url) {
	window.location = url;
}

function Toggle(which){
		
	if(!document.getElementById(which)){return;}
	var visible=document.getElementById(which).style.display != "none";
	//This is the div that should be expanded or collapsed.
	var obj=document.getElementById(which);
	//This is the div that is clicked to change the plus/minus sign.
	if(obj.style.display="none"){
		obj.style.display="block";
	}
	if(visible){
		obj.style.display ="none";
	}
}

//Collapses the menu completely when called.
function close(){
	divs = document.getElementsByTagName("div");
	for(i=0; i<divs.length; i++) divs[i].style.display="none";
}

function openmenu(arrmenu,selmenu){
  var arr = arrmenu.split(' ');
  for(var i=0;i < arr.length;i++){
		Toggle(arr[i]);
  }
	if(document.getElementById(selmenu)){
		var obj=document.getElementById(selmenu);
		obj.style.color='#FFFFFF';
	}
}

function view(url,store_card_id,inout_card_id,width) {
  var link   = url + "?id=" + store_card_id + "&subid=" + inout_card_id;
  status = "width=" + width + ",resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";   
  window.open(link,"_blank",status);
}

function validEmail(email) 
{
        invalidChars = " /:,;"
        if (email == "") 
        { 
	        return true;
        }

    for (i=0; i<invalidChars.length; i++)  // does it contain any invalid characters?
        { 
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar,0) > -1) 
                {
                         return false
        }
        }

        atPos = email.indexOf("@",1)                    // there must be one "@" symbol
                if (atPos == -1) 
                {       
                        return false                   
                }
        if (email.indexOf("@",atPos+1) != -1) // and only one "@" symbol
                { 
                return false                
                }

        periodPos = email.indexOf(".",atPos)
        if (periodPos == -1)                                            // and at least one "." after the "@"
                {                                  
                return false
                }

        if (periodPos+3 > email.length)                         // must be at least 2 characters after the "."
                {               
                        return false               
                }


     return true
}

function openwindow(url,width,height) {
  var link   = url;
  status = "width=" + width + ",height=" + height + ",resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";   
  window.open(link,"_blank",status);
}

function openimage(url,width,height) {
  var link   = url;
  status = "width=" + width + ",height=" + height + ",resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no";   
  window.open(link,"_blank",status);
}
