///COPYRIGHT L.FAITH OPTIK GRAPHICS 2010///


function validation() {
this.error_check=0;
this.warning = "You must complete the following fields:";
}

validation.prototype.isChecked=isChecked;
validation.prototype.numerical=numerical;
validation.prototype.isOneChecked=isOneChecked;
validation.prototype.emptyCheck=emptyCheck;
validation.prototype.valueCheck=valueCheck;
validation.prototype.priceMoreThan=priceMoreThan;
validation.prototype.amountCheck=amountCheck;
validation.prototype.emailVerify=emailVerify;
validation.prototype.inputVerify=inputVerify;
validation.prototype.alphaNum=alphaNum;
validation.prototype.realName=realName;
validation.prototype.fileType=fileType;
validation.prototype.expiryDate=expiryDate;
validation.prototype.CVS=CVS;
validation.prototype.cardNo=cardNo;
validation.prototype.noMatch=noMatch;
validation.prototype.atLeastOneValue=atLeastOneValue;


function isChecked(groupName,warningTxt){

g=document.getElementById(groupName).getElementsByTagName('input');
warningCheck=0;

for(var i=0;i<g.length;i++){
if(!g[i].checked){
this.error_check++;
warningCheck++;
}
}


if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);

}

}


function numerical(groupName,warningTxt){

g=document.getElementById(groupName).getElementsByTagName('input');
warningCheck=0;

for(var i=0;i<g.length;i++){
if((!g[i].value.match(/^[0-9]+$/))&&(g[i].value!="")){
this.error_check++;
warningCheck++;
}
}


if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);

}

}


function inputVerify(groupName,warningTxt,tagType){

warningCheck=0;

groupNameCheck=groupName.replace("Verify", "");
g=document.getElementById(groupName).getElementsByTagName(tagType);
h=document.getElementById(groupNameCheck).getElementsByTagName(tagType);

if(g[0].value!=h[0].value){
this.error_check++;
warningCheck++;
}



if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}

}


function emailVerify(groupName,warningTxt,tagType){

warningCheck=0;

g=document.getElementById(groupName).getElementsByTagName(tagType);

filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
for(var i=0;i<g.length;i++){
if (!filter.test(g[i].value)) {
this.error_check++;
warningCheck++;
}
}


if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}

}

function alphaNum(groupName,warningTxt,tagType){

g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if((!g[i].value.match(/^[0-9a-zA-Z]+$/))&&(g[i].value!="")){
this.error_check++;
warningCheck++;
}
}

if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}

}


function realName(groupName,warningTxt,tagType){

g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if((!g[i].value.match(/^[a-zA-Z\s.'-]+$/))&&(g[i].value!="")){
this.error_check++;
warningCheck++;
}
}

if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}

}





function isOneChecked(groupName,warningTxt){
g=document.getElementById(groupName).getElementsByTagName('input');
warningCheck=0;

for(var i=0;i<g.length;i++){
if(g[i].checked){
warningCheck++;
}
}


if(warningCheck==0){
this.error_check++;
this.warning=this.warning.concat(warningTxt);
}

}




function emptyCheck(groupName,warningTxt,tagType){

g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if(g[i].value==""){
this.error_check++;
warningCheck++;
}
}


if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);

}

}




function priceMoreThan(groupName,warningTxt,limit){

b=document.getElementById(groupName).value;
if(b==""){
b=0;
}

u=document.getElementById(groupName+'_unit').value
if(u==""){
u=0;
}


base=parseInt(b);
sub_unit=parseInt(u)/100;

total=base+sub_unit

if(total<limit){
this.error_check++;
this.warning=this.warning.concat(warningTxt);
}

}


function amountCheck(groupName,warningTxt,tagType,limit){
	
g=document.getElementById(groupName).getElementsByTagName(tagType);


for(var i=0;i<g.length;i++){

if(i==0){
b=g[i].value;
if(b==""){
b=0;
}

}else{
u=g[i].value;
if(u==""){
u=0;
}	
}

}


base=parseInt(b);
sub_unit=parseInt(u)/100;

total=base+sub_unit

if(total<limit){
this.error_check++;
this.warning=this.warning.concat(warningTxt);
}

}



function valueCheck(groupName,warningTxt,tagType,valueTxt){

g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if(g[i].value==valueTxt){
this.error_check++;
warningCheck++;
}
}


if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);

}

}






function fileType(groupName,warningTxt,fileList){
fileListArray=fileList.split(",");
g=document.getElementById(groupName).getElementsByTagName("input");
warningCheck=0;
typeCheck=0;


for(var i=0;i<g.length;i++){

var fileCheck= g[i].value;
var ignore= g[i].id;

if(ignore!="ignore"){
fileCheck = fileCheck.substring(fileCheck.length-3,fileCheck.length);
fileCheck = fileCheck.toLowerCase();

typeCheck=0;
for (x in fileListArray){
if(fileCheck==fileListArray[x]||g[i].value==""){
typeCheck++;
}
}
if(typeCheck<1){
warningCheck++;	
}

}


}

if(warningCheck>0){
this.error_check++;
this.warning=this.warning.concat(warningTxt);
}

}





function expiryDate(groupName,warningTxt,tagType){
g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if(!g[i].value.match(/^((0[1-9])|(1[0-2]))\/(\d{2})$/)){
this.error_check++;
warningCheck++;
}
}

if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}
}


function CVS(groupName,warningTxt,tagType){
g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if(!g[i].value.match(/^(\d{3})$/)){
this.error_check++;
warningCheck++;
}
}

if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}
}


function cardNo(groupName,warningTxt,tagType){

g=document.getElementById(groupName).getElementsByTagName(tagType);
warningCheck=0;

for(var i=0;i<g.length;i++){
if((!g[i].value.match(/[0-9]{4} {0,1}[0-9]{4} {0,1}[0-9]{4} {0,1}[0-9]{4}/))&&(g[i].value!="")){
this.error_check++;
warningCheck++;
}
}

if(warningCheck>0){
this.warning=this.warning.concat(warningTxt);
}

}


function noMatch(original,comparison,warningTxt){

original=document.getElementById(original).value;
comparison=document.getElementById(comparison).value;

if(original==comparison){
this.error_check++;
this.warning=this.warning.concat(warningTxt);
}


}



function atLeastOneValue(groupName,warningTxt){
g=document.getElementById(groupName).getElementsByTagName('input');
warningCheck=0;

for(var i=0;i<g.length;i++){
if(g[i].value){
warningCheck++;
}
}


if(warningCheck==0){
this.error_check++;
this.warning=this.warning.concat(warningTxt);
}

}


